Skip to content

Commit 1d7c256

Browse files
author
JPL User
committed
jupyter_env_setup.sh to set up working environment on cloud
1 parent a79d365 commit 1d7c256

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
3+
# # Shell script for setting up conda, jupyter, essential Python packages on an AWS EC2 instance.
4+
# # Assumes that the ECCO-v4-Python-Tutorial Github repository has already been downloaded using:
5+
# sudo dnf update -y
6+
# sudo dnf install git -y
7+
# cd ~
8+
# git clone https://github.com/ECCO-GROUP/ECCO-v4-Python-Tutorial.git
9+
10+
# # Then run this script:
11+
# sudo chmod 755 ~/ECCO-v4-Python-Tutorial/ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh
12+
# ~/ECCO-v4-Python-Tutorial/ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh
13+
14+
15+
# # Start body of script
16+
17+
# install wget
18+
sudo dnf install wget -y
19+
20+
# retrieve and install miniforge in /opt/
21+
# assuming EBS volume is already attached to instance
22+
mkdir -p /tmp
23+
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh" -O /tmp/Miniforge3.sh
24+
sudo bash /tmp/Miniforge3.sh -b -p /opt/conda
25+
sudo chmod -R a+w /opt/conda
26+
source "/opt/conda/etc/profile.d/conda.sh"
27+
source "/opt/conda/etc/profile.d/mamba.sh"
28+
29+
red_start='\033[0;31m'
30+
nocolor_start='\033[0m+'
31+
echo -e "${red_start}Completed Miniforge3 installation${nocolor_start}"
32+
33+
# add conda and mamba to path
34+
mamba init
35+
36+
# set paths to environment and package directories
37+
printf '\n# set conda environment and package directories' >> ~/.bashrc
38+
printf '\nexport CONDA_ENVS_PATH=/opt/conda/envs' >> ~/.bashrc
39+
printf '\nexport CONDA_PKGS_DIRS=/opt/conda/pkgs' >> ~/.bashrc
40+
source ~/.bashrc
41+
42+
# create jupyter environment under /opt/conda/envs/
43+
# (in EBS storage to save space in home directory)
44+
mamba create --name jupyter python=3.8 -y
45+
echo -e "${red_start}Created jupyter environment${nocolor_start}"
46+
47+
# install python packages (using mamba) in jupyter environment
48+
mamba activate jupyter
49+
mamba install requests tqdm numpy pandas -y
50+
mamba install xorg-libice libexpat libevent -y
51+
mamba install nspr alsa-lib libogg libpq -y
52+
mamba install xorg-renderproto xorg-xf86vidmodeproto graphite2 expat -y
53+
mamba install libgpg-error dbus -y
54+
mamba install libflac gettext -y
55+
mamba install xcb-util-wm xorg-libx11 xcb-util-image -y
56+
mamba install xkeyboard-config -y
57+
mamba install libxkbcommon fonts-conda-forge font-ttf-ubuntu gstreamer zlib -y
58+
mamba install xorg-xextproto libpng attr mpg123 -y
59+
mamba install pixman libvorbis glib-tools -y
60+
mamba install libsystemd0 xcb-util-keysyms xorg-libxrender libllvm15 -y
61+
mamba install font-ttf-dejavu-sans-mono pcre2 font-ttf-inconsolata font-ttf-source-code-pro -y
62+
mamba install lame nss xorg-xproto pthread-stubs xorg-libxdmcp -y
63+
mamba install libgcrypt xorg-libsm xorg-libxext fonts-conda-ecosystem xorg-kbproto mysql-libs -y
64+
mamba install fontconfig libjpeg-turbo xcb-util-renderutil -y
65+
mamba install glib -y
66+
mamba install freetype libcap libcups libopus -y
67+
mamba install gst-plugins-base mysql-common xcb-util -y
68+
mamba install cairo -y
69+
mamba install libsndfile harfbuzz xorg-libxau -y
70+
mamba install libglib libxcb -y
71+
mamba install qt-main -y
72+
mamba install pyqt -y
73+
mamba install matplotlib -y
74+
mamba install netcdf4 -y
75+
mamba install scipy -y
76+
mamba install geos -y
77+
mamba install proj pyproj -y
78+
mamba install cartopy -y
79+
mamba install notebook -y
80+
mamba install progressbar -y
81+
mamba install gsw -y
82+
83+
# install remaining packages using pip
84+
# (mamba installs tend to get killed on t2.micro)
85+
pip install dask
86+
pip install xarray
87+
pip install jupyterlab
88+
pip install s3fs
89+
pip install ecco_v4_py
90+
91+
echo -e "${red_start}Completed Python package installations${nocolor_start}"
92+
93+
# NASA Earthdata authentication
94+
# check if credentials are already archived in ~/.netrc, and if not then prompt the user for them
95+
earthdata_cred_stored=0
96+
if [ -f ~/.netrc ]; then
97+
if grep -q "machine urs.earthdata.nasa.gov" ~/.netrc; then
98+
earthdata_cred_stored=1
99+
fi
100+
fi
101+
if [ $earthdata_cred_stored -eq 0 ]; then
102+
if [ -f ~/.netrc ]; then sudo chmod 600 ~/.netrc; fi
103+
read -p 'NASA Earthdata username: ' uservar
104+
read -sp 'NASA Earthdata password: ' passvar
105+
echo -e "machine urs.earthdata.nasa.gov\n login ${uservar}\n password ${passvar}\n" >> ~/.netrc
106+
fi
107+
sudo chmod 400 ~/.netrc
108+
109+
echo -e "${red_start}Set up NASA Earthdata authentication${nocolor_start}"
110+
111+
# set up Jupyter lab, to be opened in a tmux session using password
112+
PW="$(python3 -c 'from notebook.auth import passwd; import getpass; print(passwd(getpass.getpass(), algorithm="sha256"))')"
113+
jlab_start="\'jupyter lab --no-browser --autoreload --port=9889 --ip=\'127.0.0.1\' --NotebookApp.token=\'\' --NotebookApp.password=\"$PW\" --notebook-dir=\"~/ECCO-v4-Python-Tutorial/Tutorials_as_Jupyter_Notebooks\" \'"
114+
tmux new-session -d -s jupyterlab ${jlab_start}
115+
116+
blue_start='\033[0;34m'
117+
echo -e "${red_start}Started Jupyter lab in tmux session jupyterlab"
118+
echo -e "${red_start}Access from your local machine in a browser window at"
119+
echo -e "${blue_start}http://127.0.0.1:9889/"
120+
echo -e "${red_start}tmux session can be accessed with"
121+
echo -e "${blue_start}tmux -a -t jupyterlab"
122+
echo -e "${red_start}and terminated with"
123+
echo -e "${blue_start}tmux kill-ses -t jupyterlab"

0 commit comments

Comments
 (0)