Commit 70649df1 authored by Sebastian Wahl's avatar Sebastian Wahl

modified according to suggestions made in issue #5

close issue #5
parent ae3db2fb
name: py3_std
channels:
- defaults
- conda-forge
dependencies:
- numpy
- matplotlib
- scipy
- ipykernel
- git
- python=3
- cdo
- netcdf4
- xarray
- libiconv
- cartopy
......@@ -31,6 +31,8 @@ function connect() {
if [[ -f "$chrome" ]]; then
# TODO: disable warning output
"$chrome" --new-window --user-data-dir="/tmp/chromium_user_data_$(date -Ins)" --proxy-server='socks5://localhost:'${socks_5_port} $page &
echo " Cleaning tmp data on /tmp (if any)"
find /tmp/ -maxdepth 1 -mtime +30 -name "chromium_user_data*" -exec rm -rf {} \;
else
echo
echo " ERROR: chrome browser needs to be installed. Go to https://www.google.com/chrome/, install Chrome and try again"
......@@ -40,6 +42,9 @@ function connect() {
if which chromium-browser >/dev/null; then
chromium-browser --new-window --user-data-dir="/tmp/chromium_user_data_$(date -Ins)" \
--proxy-server="socks5://localhost:${socks_5_port}" $page &
# delete user data older than 30 days
echo " Cleaning tmp data on /tmp (if any)"
find /tmp/ -maxdepth 1 -mtime +30 -name "chromium_user_data*" -exec rm -rf {} \;
else
echo
echo " ERROR: chrome browser needs to be installed. On Ubuntu try sudo apt-get install chromium-browser and try again."
......@@ -49,6 +54,19 @@ function connect() {
}
# setup remote installation
function install_conda_environment() {
cd $HOME
test -d miniconda3 && mv -v miniconda3 miniconda_$(date +%Y%m%d_%H%M%S)
curl https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3.sh
bash Miniconda3.sh -b -p \${HOME}/miniconda3
rm -f Miniconda3.sh
source ${HOME}/miniconda3/bin/activate base;
conda install jupyterlab nb_conda_kernels --yes
conda env create -f /dev/stdin;
}
if [[ $# -lt 2 ]]; then
echo
echo " Usage: need two arguments:"
......@@ -76,12 +94,16 @@ fi
# set -vx
hname=$1
task=$2
page=
port=
echo
if [[ "$task" == "start" ]] || [[ "$task" == "connect" ]]; then
if [[ "$task" == "start" ]] || [[ "$task" == "stop" ]]; then
page=$(ssh $hname "\${HOME}/miniconda3/bin/python \${HOME}/miniconda3/bin/jupyter notebook list" | grep http | awk '{print$1}')
port=$(echo $page | awk -F: '{print$3}' | awk -F/ '{print$1}')
fi
echo
if [[ "$task" == "start" ]]; then
if [[ -z "$port" ]] ; then
echo " No Jupyterlab server running on $hname. Will start a server and connect to it "
# TODO: avoid hitting Ctrl+C --> how to I start this in the backgroud adding & does not work
......@@ -96,8 +118,6 @@ if [[ "$task" == "start" ]] || [[ "$task" == "connect" ]]; then
elif [[ "$task" == "stop" ]]; then
page=$(ssh $hname "\${HOME}/miniconda3/bin/python \${HOME}/miniconda3/bin/jupyter notebook list" | grep http | awk '{print$1}')
port=$(echo $page | awk -F: '{print$3}' | awk -F/ '{print$1}')
if [[ ! -z "$port" ]] ; then
echo " Jupyterlab on $hname, port $port, will be stopped"
ssh $hname "\${HOME}/miniconda3/bin/python \${HOME}/miniconda3/bin/jupyter notebook stop $port"
......@@ -105,20 +125,11 @@ elif [[ "$task" == "stop" ]]; then
echo " No Jupyterlab running on $hname"
fi
echo
elif [[ "$task" == "install" ]]; then
ssh $hname bash <<EOF
test -d miniconda3 && mv -v miniconda3 miniconda_$(date +%Y%m%d_%H%M%S)
curl https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3.sh
bash Miniconda3.sh -b -p \${HOME}/miniconda3
rm -f Miniconda3.sh
source \${HOME}/miniconda3/bin/activate base
conda install jupyterlab nb_conda_kernels --yes
conda create -n py3_std python=3 numpy matplotlib scipy ipykernel git --yes
conda activate py3_std
conda install -c conda-forge cdo netcdf4 xarray --yes
conda install libiconv --yes
conda install -c conda-forge cartopy --yes
EOF
# cool trick from https://stackoverflow.com/a/22107893 on how to execute local functions on a remote machine
cat py3_std.yml | ssh $hname "$(typeset -f install_conda_environment); install_conda_environment;"
elif [[ "$task" == "update" ]]; then
echo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment