|
| 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 | +# install wget |
| 25 | +sudo dnf install wget -y |
| 26 | +echo -e "${red_start}Installed wget${nocolor_start}" |
| 27 | + |
| 28 | +# install tmux |
| 29 | +sudo dnf install tmux -y |
| 30 | +echo -e "${red_start}Installed tmux${nocolor_start}" |
| 31 | + |
| 32 | +# retrieve and install miniforge in /tmp/ |
| 33 | +# assuming EBS volume is already attached to instance |
| 34 | +echo -e "${red_start}Starting Miniforge3 installation${nocolor_start}" |
| 35 | +mkdir -p /tmp |
| 36 | +wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh" -O /tmp/Miniforge3.sh |
| 37 | +bash /tmp/Miniforge3.sh -b -p /tmp/conda |
| 38 | +rm -f /tmp/Miniforge.sh |
| 39 | +source "/tmp/conda/etc/profile.d/conda.sh" |
| 40 | +source "/tmp/conda/etc/profile.d/mamba.sh" |
| 41 | + |
| 42 | +echo -e "${red_start}Completed Miniforge3 installation${nocolor_start}" |
| 43 | + |
| 44 | +# add conda and mamba to path |
| 45 | +mamba init |
| 46 | + |
| 47 | +# set paths to environment and package directories |
| 48 | +printf '\n# set conda environment and package directories' >> ~/.bashrc |
| 49 | +printf '\nexport CONDA_ENVS_PATH=/tmp/conda/envs' >> ~/.bashrc |
| 50 | +printf '\nexport CONDA_PKGS_DIRS=/tmp/conda/pkgs' >> ~/.bashrc |
| 51 | +source ~/.bashrc |
| 52 | + |
| 53 | +# create jupyter environment under /tmp/conda/envs/ |
| 54 | +# (in EBS storage to save space in home directory) |
| 55 | +mamba create --name jupyter python=3.11 -y |
| 56 | +echo -e "${red_start}Created jupyter environment${nocolor_start}" |
| 57 | + |
| 58 | +# install python packages (using mamba) in jupyter environment |
| 59 | +mamba activate jupyter |
| 60 | +echo -e "${red_start}Installing Python packages in jupyter environment${nocolor_start}" |
| 61 | +mamba install requests tqdm numpy pandas -y |
| 62 | +mamba install xorg-libice libexpat libevent -y |
| 63 | +mamba install nspr alsa-lib libogg libpq -y |
| 64 | +mamba install xorg-renderproto xorg-xf86vidmodeproto graphite2 expat -y |
| 65 | +mamba install libgpg-error dbus -y |
| 66 | +mamba install libflac gettext -y |
| 67 | +mamba install xcb-util-wm xorg-libx11 xcb-util-image -y |
| 68 | +mamba install xkeyboard-config -y |
| 69 | +mamba install libxkbcommon fonts-conda-forge font-ttf-ubuntu gstreamer zlib -y |
| 70 | +mamba install xorg-xextproto libpng attr mpg123 -y |
| 71 | +mamba install pixman libvorbis glib-tools -y |
| 72 | +mamba install libsystemd0 xcb-util-keysyms xorg-libxrender libllvm15 -y |
| 73 | +mamba install font-ttf-dejavu-sans-mono pcre2 font-ttf-inconsolata font-ttf-source-code-pro -y |
| 74 | +mamba install lame nss xorg-xproto pthread-stubs xorg-libxdmcp -y |
| 75 | +mamba install libgcrypt xorg-libsm xorg-libxext fonts-conda-ecosystem xorg-kbproto mysql-libs -y |
| 76 | +mamba install fontconfig libjpeg-turbo xcb-util-renderutil -y |
| 77 | +mamba install glib -y |
| 78 | +mamba install freetype libcap libcups libopus -y |
| 79 | +mamba install gst-plugins-base mysql-common xcb-util -y |
| 80 | +mamba install cairo -y |
| 81 | +mamba install libsndfile harfbuzz xorg-libxau -y |
| 82 | +mamba install libglib libxcb -y |
| 83 | +mamba install qt-main -y |
| 84 | +mamba install pyqt -y |
| 85 | +mamba install matplotlib -y |
| 86 | +mamba install netcdf4 -y |
| 87 | +mamba install h5netcdf -y |
| 88 | +mamba install boto3 lxml -y |
| 89 | +mamba install scipy -y |
| 90 | +mamba install geos -y |
| 91 | +mamba install proj pyproj -y |
| 92 | +mamba install cartopy -y |
| 93 | +mamba install notebook -y |
| 94 | +mamba install progressbar -y |
| 95 | +mamba install gsw -y |
| 96 | +mamba install nco -y |
| 97 | + |
| 98 | +# install remaining packages using pip |
| 99 | +# (mamba installs tend to get killed on t2.micro) |
| 100 | +pip install dask |
| 101 | +pip install "xarray[complete]" |
| 102 | +pip install jupyterlab |
| 103 | +pip install dask_labextension |
| 104 | +pip install s3fs |
| 105 | +pip install ecco_v4_py |
| 106 | + |
| 107 | +echo -e "${red_start}Completed Python package installations${nocolor_start}" |
| 108 | + |
| 109 | +echo -e "${red_start}Setting up NASA Earthdata authentication${nocolor_start}" |
| 110 | +# NASA Earthdata authentication |
| 111 | +# check if credentials are already archived in ~/.netrc, and if not then prompt the user for them |
| 112 | +earthdata_cred_stored=0 |
| 113 | +if [ -f ~/.netrc ]; then |
| 114 | + if grep -q "machine urs.earthdata.nasa.gov" ~/.netrc; then |
| 115 | + earthdata_cred_stored=1 |
| 116 | + echo -e "${red_start}Earthdata credentials already archived" |
| 117 | + fi |
| 118 | +fi |
| 119 | +if [ $earthdata_cred_stored -eq 0 ]; then |
| 120 | + if [ -f ~/.netrc ]; then sudo chmod 600 ~/.netrc; fi |
| 121 | + read -p 'NASA Earthdata username: ' uservar |
| 122 | + read -sp 'NASA Earthdata password: ' passvar |
| 123 | + echo -e "machine urs.earthdata.nasa.gov\n login ${uservar}\n password ${passvar}\n" >> ~/.netrc |
| 124 | + |
| 125 | + echo -e "\n${red_start}NASA Earthdata authentication info archived in ~/.netrc${nocolor_start}" |
| 126 | +fi |
| 127 | +sudo chmod 400 ~/.netrc |
| 128 | + |
| 129 | +# create symlink to jupyter_lab_start.sh from the user's home directory |
| 130 | +ln -s ~/ECCO-v4-Python-Tutorial/Cloud_Setup/jupyter_lab_start.sh ~/jupyter_lab_start.sh |
0 commit comments