|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Shell script to start a Jupyter lab session |
| 4 | +# in a tmux window (so it persists even if ssh tunnel is disconnected) |
| 5 | + |
| 6 | +red_start='\033[0;31m' |
| 7 | +blue_start='\033[0;34m' |
| 8 | +nocolor_start='\033[0m' |
| 9 | + |
| 10 | + |
| 11 | +# Add Earthdata credentials to ~/.netrc if they are not already present |
| 12 | +sh ~/ECCO-v4-Python-Tutorial/Docker/earthdata_auth_docker.sh |
| 13 | + |
| 14 | +echo "Starting Jupyter lab session!" |
| 15 | +echo "" |
| 16 | + |
| 17 | +read -p 'Which container port do you want to use [default 8888]: ' user_port |
| 18 | +user_port=${user_port:-8888} |
| 19 | +echo "using port ${user_port}" |
| 20 | +echo "" |
| 21 | + |
| 22 | +# Start configuration for Jupyter lab |
| 23 | +echo "Enter password to access Jupyter lab from browser," |
| 24 | +echo "or leave blank to not require a password." |
| 25 | + |
| 26 | +PW="$(python3 -c 'from jupyter_server.auth import passwd; import getpass; print(passwd(getpass.getpass(), algorithm="sha256"))')" |
| 27 | + |
| 28 | + |
| 29 | +# Start Jupyter lab |
| 30 | +source /srv/conda/bin/activate |
| 31 | +conda activate notebook |
| 32 | +jupyter lab --no-browser --autoreload --port=${user_port} --ip='0.0.0.0' --NotebookApp.token='' --NotebookApp.password=\"$PW\" --notebook-dir=\"./ECCO-v4-Python-Tutorial\" |
| 33 | + |
| 34 | +# Print info about session |
| 35 | +echo -e "${red_start}Started Jupyter lab in Docker container" |
| 36 | +echo -e "${red_start}Access from your local machine in a browser window" |
| 37 | +echo -e "${red_start}by tunneling to host machine at the port" |
| 38 | +echo -e "${red_start}you are using to connect to the Docker container, e.g., " |
| 39 | +echo -e "${blue_start}ssh -i ~/.ssh/ec2_auth.pem -L 8888:localhost:8888 ec2-user@100.104.70.127" |
| 40 | +echo -e "${red_start}and opening the URL in your browser" |
| 41 | +echo -e "${blue_start}http://127.0.0.1:8888/ ${red_start}or ${blue_start}http://localhost:8888/" |
| 42 | +echo -e "${red_start}If you are already running Jupyter on your local machine" |
| 43 | +echo -e "${red_start}on port 8888, you need to use a different local port, e.g.," |
| 44 | +echo -e "${blue_start}ssh -i ~/.ssh/ec2_auth.pem -L 9889:localhost:8888 ec2-user@100.104.70.127${nocolor_start}" |
0 commit comments