|
| 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 | +# |
| 6 | +# $ sudo dnf update -y |
| 7 | +# $ sudo dnf install git -y |
| 8 | +# $ cd ~ |
| 9 | +# $ git clone https://github.com/ECCO-GROUP/ECCO-v4-Python-Tutorial.git |
| 10 | + |
| 11 | +# Then run this script: |
| 12 | +# |
| 13 | +# $ sudo chmod 755 ~/ECCO-v4-Python-Tutorial/Cloud_Setup/jupyter_env_setup.sh |
| 14 | +# $ ~/ECCO-v4-Python-Tutorial/Cloud_Setup/jupyter_env_setup.sh |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +# # Start body of script |
| 19 | + |
| 20 | +red_start='\033[0;31m' |
| 21 | +blue_start='\033[0;34m' |
| 22 | +nocolor_start='\033[0m' |
| 23 | + |
| 24 | +# # set paths to environment and package directories |
| 25 | + |
| 26 | +# create jupyter environment |
| 27 | +mamba create --name jupyter python=3.11 -y |
| 28 | +echo -e "${red_start}Created jupyter environment${nocolor_start}" |
| 29 | + |
| 30 | +# install python packages (using mamba) in jupyter environment |
| 31 | +mamba activate jupyter |
| 32 | +echo -e "${red_start}Installing Python packages in jupyter environment${nocolor_start}" |
| 33 | +mamba install requests tqdm numpy pandas -y |
| 34 | +mamba install xorg-libice libexpat libevent -y |
| 35 | +mamba install nspr alsa-lib libogg libpq -y |
| 36 | +mamba install xorg-renderproto xorg-xf86vidmodeproto graphite2 expat -y |
| 37 | +mamba install libgpg-error dbus -y |
| 38 | +mamba install libflac gettext -y |
| 39 | +mamba install xcb-util-wm xorg-libx11 xcb-util-image -y |
| 40 | +mamba install xkeyboard-config -y |
| 41 | +mamba install libxkbcommon fonts-conda-forge font-ttf-ubuntu gstreamer zlib -y |
| 42 | +mamba install xorg-xextproto libpng attr mpg123 -y |
| 43 | +mamba install pixman libvorbis glib-tools -y |
| 44 | +mamba install libsystemd0 xcb-util-keysyms xorg-libxrender libllvm15 -y |
| 45 | +mamba install font-ttf-dejavu-sans-mono pcre2 font-ttf-inconsolata font-ttf-source-code-pro -y |
| 46 | +mamba install lame nss xorg-xproto pthread-stubs xorg-libxdmcp -y |
| 47 | +mamba install libgcrypt xorg-libsm xorg-libxext fonts-conda-ecosystem xorg-kbproto mysql-libs -y |
| 48 | +mamba install fontconfig libjpeg-turbo xcb-util-renderutil -y |
| 49 | +mamba install glib -y |
| 50 | +mamba install freetype libcap libcups libopus -y |
| 51 | +mamba install gst-plugins-base mysql-common xcb-util -y |
| 52 | +mamba install cairo -y |
| 53 | +mamba install libsndfile harfbuzz xorg-libxau -y |
| 54 | +mamba install libglib libxcb -y |
| 55 | +mamba install qt-main -y |
| 56 | +mamba install pyqt -y |
| 57 | +mamba install matplotlib -y |
| 58 | +mamba install netcdf4 -y |
| 59 | +mamba install h5netcdf -y |
| 60 | +mamba install boto3 lxml -y |
| 61 | +mamba install scipy -y |
| 62 | +mamba install geos -y |
| 63 | +mamba install proj pyproj -y |
| 64 | +mamba install cartopy -y |
| 65 | +mamba install notebook -y |
| 66 | +mamba install progressbar -y |
| 67 | +mamba install gsw -y |
| 68 | +mamba install nco -y |
| 69 | +mamba install pympler -y |
| 70 | + |
| 71 | +# install remaining packages using pip |
| 72 | +# (mamba installs tend to get killed on t2.micro) |
| 73 | +pip install dask |
| 74 | +pip install "xarray[complete]" |
| 75 | +pip install jupyterlab |
| 76 | +pip install dask_labextension |
| 77 | +pip install s3fs |
| 78 | +pip install ecco_v4_py |
| 79 | + |
| 80 | +echo -e "${red_start}Completed Python package installations${nocolor_start}" |
| 81 | + |
| 82 | + |
| 83 | +echo -e "${red_start}Setting up NASA Earthdata authentication${nocolor_start}" |
| 84 | +# NASA Earthdata authentication |
| 85 | +# check if credentials are already archived in ~/.netrc, and if not then prompt the user for them |
| 86 | +earthdata_cred_stored=0 |
| 87 | +if [ -f ~/.netrc ]; then |
| 88 | + if grep -q "machine urs.earthdata.nasa.gov" ~/.netrc; then |
| 89 | + earthdata_cred_stored=1 |
| 90 | + echo -e "${red_start}Earthdata credentials already archived ${nocolor_start}" |
| 91 | + fi |
| 92 | +fi |
| 93 | +if [ $earthdata_cred_stored -eq 0 ]; then |
| 94 | + if [ -f ~/.netrc ]; then sudo chmod 600 ~/.netrc; fi |
| 95 | + read -p 'NASA Earthdata username: ' uservar |
| 96 | + read -sp 'NASA Earthdata password: ' passvar |
| 97 | + echo -e "machine urs.earthdata.nasa.gov\n login ${uservar}\n password ${passvar}\n" >> ~/.netrc |
| 98 | + |
| 99 | + echo -e "\n${red_start}NASA Earthdata authentication info archived in ~/.netrc${nocolor_start}" |
| 100 | +fi |
| 101 | +sudo chmod 400 ~/.netrc |
| 102 | + |
| 103 | +# create symlink to jupyter_lab_start.sh from the user's home directory |
| 104 | +ln -s ~/ECCO-v4-Python-Tutorial/Cloud_Setup/jupyter_lab_start.sh ~/jupyter_lab_start.sh |
| 105 | + |
| 106 | +echo "goodbye!" |
0 commit comments