From 6f0880c5470694047b8f94a8298c0738823a4a6b Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 23 Aug 2016 13:45:21 -0400 Subject: [PATCH] * bash-module-env.sh: an effort to facilitate bash support for batch scripts. Last modified date of this script: 2016-06-23. --- turing/support/bash-module-env.sh | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 turing/support/bash-module-env.sh diff --git a/turing/support/bash-module-env.sh b/turing/support/bash-module-env.sh new file mode 100755 index 0000000..2a6e8ac --- /dev/null +++ b/turing/support/bash-module-env.sh @@ -0,0 +1,57 @@ +# -*- bash -*- +# +# + +# Some cluster defaults (may change over time) +# Reference: /etc/profile.d/modules.sh +MODULESHOME_DEFAULT=/cm/local/apps/environment-modules/3.2.10/Modules/3.2.10 +MODULEPATH_DEFAULT=/cm/local/modulefiles:/cm/shared/modulefiles:/cm/shared/compilers + +# RestoreModuleEnv restores module environment at batch-job runtime to be +# exactly the same as the environment at the time of job submission. +# It requires the following variables to be set: +# - MODULESHOME (optional; default provided above) +# - MODULEPATH +# - LAODEDMODULES + +RestoreModuleEnv () { + local LOADEDMODULES_SAVE + : ${MODULESHOME:=$MODULESHOME_DEFAULT} + : ${MODULEPATH:=$MODULEPATH_DEFAULT} + export MODULESHOME + export MODULEPATH + + LOADEDMODULES_SAVE=$LOADEDMODULES + unset LOADEDMODULES + + source "$MODULESHOME/init/bash" + + if [ -n "$LOADEDMODULES_SAVE" ]; then + module load ${LOADEDMODULES_SAVE//:/" "} + fi + + if [ -n "$Debug" -o -n "$DEBUG_MODULES" ]; then + echo "New loaded modules: $LOADEDMODULES" + module list + fi +} + +InitModuleEnv () { + # Only do the initialization part of the module so "module" command + # is available for the script + local LOADEDMODULES_SAVE + : ${MODULESHOME:=$MODULESHOME_DEFAULT} + : ${MODULEPATH:=$MODULEPATH_DEFAULT} + export MODULESHOME + export MODULEPATH + + source "$MODULESHOME/init/bash" +} + +# For convenience: +if [ "$1" = restore ]; then + RestoreModuleEnv +elif [ "$1" = init ]; then + InitModuleEnv +fi +