|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +check_env () { |
| 4 | + for module in "geometric_features" "mpas_tools" "jigsawpy" |
| 5 | + do |
| 6 | + if python -c "import ${module}"; then |
| 7 | + echo " ${module} passed" |
| 8 | + else |
| 9 | + echo " ${module} failed" |
| 10 | + exit 1 |
| 11 | + fi |
| 12 | + done |
| 13 | + |
| 14 | + for exec in "gpmetis" "ffmpeg" |
| 15 | + do |
| 16 | + if ${exec} --help; then |
| 17 | + echo " ${exec} passed" |
| 18 | + else |
| 19 | + echo " ${exec} failed" |
| 20 | + exit 1 |
| 21 | + fi |
| 22 | + done |
| 23 | +} |
| 24 | + |
| 25 | + |
| 26 | +# Modify the following to choose which e3sm-unified version(s) the python version(s) are installed and whether to make |
| 27 | +# an environment with x-windows support under cdat (cdatx) and/or without (nox). Typically, both environments should |
| 28 | +# be created. |
| 29 | +versions=(0.1.0) |
| 30 | +pythons=(3.7) |
| 31 | + |
| 32 | +default_python=3.7 |
| 33 | + |
| 34 | +# Any subsequent commands which fail will cause the shell script to exit |
| 35 | +# immediately |
| 36 | +set -e |
| 37 | + |
| 38 | +world_read="True" |
| 39 | + |
| 40 | +# The rest of the script should not need to be modified |
| 41 | +if [[ $HOSTNAME = "cori"* ]] || [[ $HOSTNAME = "dtn"* ]]; then |
| 42 | + base_path="/global/cfs/cdirs/acme/software/anaconda_envs/base" |
| 43 | + activ_path="/global/cfs/cdirs/acme/software/anaconda_envs" |
| 44 | + group="acme" |
| 45 | +elif [[ $HOSTNAME = "acme1"* ]] || [[ $HOSTNAME = "aims4"* ]]; then |
| 46 | + base_path="/usr/local/e3sm_unified/envs/base" |
| 47 | + activ_path="/usr/local/e3sm_unified/envs" |
| 48 | + group="climate" |
| 49 | +elif [[ $HOSTNAME = "blueslogin"* ]]; then |
| 50 | + base_path="/lcrc/soft/climate/e3sm-unified/base" |
| 51 | + activ_path="/lcrc/soft/climate/e3sm-unified" |
| 52 | + group="climate" |
| 53 | +elif [[ $HOSTNAME = "rhea"* ]]; then |
| 54 | + base_path="/ccs/proj/cli900/sw/rhea/e3sm-unified/base" |
| 55 | + activ_path="/ccs/proj/cli900/sw/rhea/e3sm-unified" |
| 56 | + group="cli900" |
| 57 | +elif [[ $HOSTNAME = "cooley"* ]]; then |
| 58 | + base_path="/lus/theta-fs0/projects/ccsm/acme/tools/e3sm-unified/base" |
| 59 | + activ_path="/lus/theta-fs0/projects/ccsm/acme/tools/e3sm-unified" |
| 60 | + group="ccsm" |
| 61 | +elif [[ $HOSTNAME = "compy"* ]]; then |
| 62 | + base_path="/compyfs/software/e3sm-unified/base" |
| 63 | + activ_path="/compyfs/software/e3sm-unified" |
| 64 | + group="users" |
| 65 | +elif [[ $HOSTNAME = "gr-fe"* ]] || [[ $HOSTNAME = "wf-fe"* ]]; then |
| 66 | + base_path="/usr/projects/climate/SHARED_CLIMATE/anaconda_envs/base" |
| 67 | + activ_path="/usr/projects/climate/SHARED_CLIMATE/anaconda_envs" |
| 68 | + group="climate" |
| 69 | +elif [[ $HOSTNAME = "burnham"* ]]; then |
| 70 | + base_path="/home/xylar/Desktop/test_e3sm_unified/base" |
| 71 | + activ_path="/home/xylar/Desktop/test_e3sm_unified" |
| 72 | + group="xylar" |
| 73 | +else |
| 74 | + echo "Unknown host name $HOSTNAME. Add env_path and group for this machine to the script." |
| 75 | + exit 1 |
| 76 | +fi |
| 77 | + |
| 78 | +if [ ! -d $base_path ]; then |
| 79 | + miniconda=Miniconda3-latest-Linux-x86_64.sh |
| 80 | + wget https://repo.continuum.io/miniconda/$miniconda |
| 81 | + /bin/bash $miniconda -b -p $base_path |
| 82 | + rm $miniconda |
| 83 | +fi |
| 84 | + |
| 85 | +# activate the new environment |
| 86 | +source ${base_path}/etc/profile.d/conda.sh |
| 87 | +conda activate |
| 88 | + |
| 89 | +conda config --add channels conda-forge |
| 90 | +conda config --set channel_priority strict |
| 91 | +conda update -y --all |
| 92 | + |
| 93 | +for version in "${versions[@]}" |
| 94 | +do |
| 95 | + for python in "${pythons[@]}" |
| 96 | + do |
| 97 | + channels="--override-channels -c conda-forge -c defaults -c e3sm" |
| 98 | + packages="python=$python compass=${version}" |
| 99 | + |
| 100 | + if [[ "$python" == "$default_python" ]]; then |
| 101 | + suffix="" |
| 102 | + else |
| 103 | + suffix="_py${python}" |
| 104 | + fi |
| 105 | + |
| 106 | + env_name=compass_${version}${suffix} |
| 107 | + if [ ! -d "$base_path/envs/$env_name" ]; then |
| 108 | + echo creating "$env_name" |
| 109 | + conda create -n "$env_name" -y $channels $packages |
| 110 | + conda activate "$env_name" |
| 111 | + conda deactivate |
| 112 | + else |
| 113 | + echo "$env_name" already exists |
| 114 | + fi |
| 115 | + |
| 116 | + conda activate "$env_name" |
| 117 | + check_env |
| 118 | + conda deactivate |
| 119 | + |
| 120 | + mkdir -p "$activ_path" |
| 121 | + |
| 122 | + # make activation scripts |
| 123 | + script="" |
| 124 | + script="${script}"$'\n'"if [ -x \"\$(command -v module)\" ] ; then" |
| 125 | + script="${script}"$'\n'" module unload python" |
| 126 | + script="${script}"$'\n'"fi" |
| 127 | + script="${script}"$'\n'"source ${base_path}/etc/profile.d/conda.sh" |
| 128 | + script="${script}"$'\n'"conda activate $env_name" |
| 129 | + file_name=$activ_path/load_latest_compass${suffix}.sh |
| 130 | + rm -f "$file_name" |
| 131 | + echo "${script}" > "$file_name" |
| 132 | + done |
| 133 | +done |
| 134 | + |
| 135 | +# delete the tarballs and any unused packages |
| 136 | +conda clean -y -p -t |
| 137 | + |
| 138 | +# continue if errors happen from here on |
| 139 | +set +e |
| 140 | + |
| 141 | +echo "changing permissions on activation scripts" |
| 142 | +chown -R "$USER":$group $activ_path/load_latest_compass* |
| 143 | +if [ $world_read == "True" ]; then |
| 144 | + chmod -R go+r $activ_path/load_latest_compass* |
| 145 | + chmod -R go-w $activ_path/load_latest_compass* |
| 146 | +else |
| 147 | + chmod -R g+r $activ_path/load_latest_compass* |
| 148 | + chmod -R g-w $activ_path/load_latest_compass* |
| 149 | + chmod -R o-rwx $activ_path/load_latest_compass* |
| 150 | +fi |
| 151 | + |
| 152 | +echo "changing permissions on environments" |
| 153 | +cd $base_path |
| 154 | +echo " changing owner" |
| 155 | +chown -R "$USER:$group" . |
| 156 | +if [ $world_read == "True" ]; then |
| 157 | + echo " adding group/world read" |
| 158 | + chmod -R go+rX . |
| 159 | + echo " removing group/world write" |
| 160 | + chmod -R go-w . |
| 161 | +else |
| 162 | + echo " adding group read" |
| 163 | + chmod -R g+rX . |
| 164 | + echo " removing group write" |
| 165 | + chmod -R g-w . |
| 166 | + echo " removing world read/write" |
| 167 | + chmod -R o-rwx . |
| 168 | +fi |
| 169 | +echo " done." |
| 170 | + |
0 commit comments