Commit d81a5d86 authored by Sebastian Wahl's avatar Sebastian Wahl

added update functionality

added auto port selection from run_chromium_through_ssh_tunnel.sh
improved chromium startup
parent 32469640
......@@ -5,7 +5,6 @@
# tested on ursus/taurus, science0[1,2].geomar.de, bdata2.hlrn.de, nesh-fe1.rz.uni-kiel.de
#
# TODO:
# - add update functionality
# - add option to provide an input file with the tasks to do e.g
# $0 hosts.txt
# with hosts.txt in the form of
......@@ -15,12 +14,15 @@
# - add option for matlab kernel?
# - add more documentation to the code
# - make basepath (currently $HOME) flexible
#
function connect() {
hname=$1
proxyport=$2
ssh -f -D localhost:${proxyport} $hname sleep 15
socks_5_port=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
[[ $socks_5_port =~ ^[0-9]+$ ]] || socks_5_port=54321
ssh -f -D localhost:${socks_5_port} $hname sleep 15
page=$(ssh $hname "\${HOME}/miniconda3/bin/python \${HOME}/miniconda3/bin/jupyter notebook list" | grep http | awk '{print$1}')
if [[ "$(uname)" == "Darwin" ]]; then
......@@ -28,15 +30,17 @@ function connect() {
if [[ -f "$chrome" ]]; then
# TODO: disable warning output
"$chrome" --proxy-server='socks5://localhost:'${proxyport} $page &
"$chrome" --new-window --user-data-dir="/tmp/chromium_user_data_$(date -Ins)" --proxy-server='socks5://localhost:'${socks_5_port} $page &
else
echo
echo " ERROR: chrome browser needs to be installed. Go to https://www.google.com/chrome/, install Chrome and try again"
echo
fi
else
set -x
if which chromium-browser >/dev/null; then
chromium-browser --proxy-server="socks5://localhost:${proxyport}" $page
chromium-browser --new-window --user-data-dir="/tmp/chromium_user_data_$(date -Ins)" \
--proxy-server="socks5://localhost:${socks_5_port}" $page &
else
echo
echo " ERROR: chrome browser needs to be installed. On Ubuntu try sudo apt-get install chromium-browser and try again."
......@@ -46,15 +50,13 @@ function connect() {
}
if [[ $# -lt 2 ]] || [[ "$1" == "-h" ]]; then
if [[ $# -lt 2 ]]; then
echo
echo " Usage: need two arguments:"
echo
# TODO: how can I make connections to several remote servers possible at the same time using different tabs"
echo " $0 user@host.example.com start "
echo " to start an existing jupyterlab environment on <user@host.example.com> and connect afterwards"
echo " if jupyterlab is already running on <user@host.example.com> you will be connected with the existing instance."
echo " Close the Chromium Browser before running $0 user@host.example.com start"
echo
echo " $0 user@host.example.com stop "
echo " to stop jupyterlab running on <user@host.example.com>"
......@@ -66,14 +68,15 @@ if [[ $# -lt 2 ]] || [[ "$1" == "-h" ]]; then
echo " Run ssh-copy-id user@host.example.com to setup passwordless ssh login and test with"
echo " ssh user@host.example.com afterwards."
echo
echo " $0 user@host.example.com update "
echo " to update an existing miniconda environment on user@host.example.com"
echo
exit 1
fi
# set -vx
hname=$1
task=$2
proxyport=54321
[[ $# -eq 3 ]] && proxyport=$3
echo
if [[ "$task" == "start" ]] || [[ "$task" == "connect" ]]; then
......@@ -90,7 +93,7 @@ if [[ "$task" == "start" ]] || [[ "$task" == "connect" ]]; then
echo " Jupyterlab on $hname, port $port already running. Connecting to existing server."
fi
echo
connect $hname $proxyport
connect $hname
elif [[ "$task" == "stop" ]]; then
......@@ -120,6 +123,9 @@ EOF
elif [[ "$task" == "update" ]]; then
echo
echo "$0 $hname $task not yet implemented."
echo
echo "Updating all packages on $hname using the conda-forge channel."
ssh $hname bash <<EOF
source \${HOME}/miniconda3/bin/activate py3_std || echo "No conda installation found in \${HOME}/miniconda3/"
conda update -c conda-forge -n py3_std --all --yes
EOF
fi
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