59 lines
1.8 KiB
Bash
59 lines
1.8 KiB
Bash
#!/bin/bash
|
|
|
|
### Small script to create an SSH tunnel from outside of PSI network to access RA.
|
|
### Change to your PSI account username and run. Once running, going to https://localhost:5000 leads to jupyera.psi.ch without needing VPN.
|
|
|
|
def_user=$USER
|
|
def_addr="jupytera"
|
|
def_port="5000"
|
|
def_debug=false
|
|
def_node=false
|
|
|
|
function show_usage {
|
|
echo "usage: $0 [-u USER] [-p PORT] [-s]"
|
|
echo " -u, --user USER set user (default: ${def_user})"
|
|
echo " -p, --port PORT set local port (default: ${def_port})"
|
|
echo " -s, --staging tunnel to jupytera staging (default: jupytera production)"
|
|
echo " -n, --node node at which jupyter is running"
|
|
echo " -d, --debug turn on debug mode (default: off)"
|
|
echo " -h, --help, -? show this help"
|
|
}
|
|
|
|
user=${def_user}
|
|
addr=${def_addr}
|
|
port=${def_port}
|
|
debug=${def_debug}
|
|
node=${def_node}
|
|
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case $1 in
|
|
-u|--user) user="$2" ; shift ;;
|
|
-p|--port) port="$2" ; shift ;;
|
|
-n|--node) node="$2" ; shift ;;
|
|
-s|--staging) addr="jupytera-staging" ;;
|
|
-d|--debug) debug=true ;;
|
|
-h|--help|-\?) show_usage ; exit ;;
|
|
*) echo "unknown argument: $1" ; show_usage ; exit 1 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
|
|
echo "Creating tunnel to ${addr}.psi.ch on https://localhost:${port}/ ..."
|
|
echo
|
|
echo "Username: ${user}"
|
|
|
|
# If node not given, link to a generic jupyter from spawner. If node given and a notebook already started there, link there.
|
|
if [ "${node}" = false ]; then
|
|
cmd="ssh -J ${user}@hop.psi.ch ${user}@ra.psi.ch -L ${port}:${addr}.psi.ch:443"
|
|
else
|
|
echo "Establishing tunnel to ${node}"
|
|
cmd="ssh -J ${user}@hop.psi.ch ${user}@ra.psi.ch -L ${port}:${node}.psi.ch:8888"
|
|
fi
|
|
|
|
if ${debug} ; then
|
|
echo "DEBUG:" $cmd
|
|
else
|
|
$cmd
|
|
fi
|