diff --git a/turing/support/bash-module-env.sh b/turing/support/bash-module-env.sh index b302de5..a0c0fbd 100755 --- a/turing/support/bash-module-env.sh +++ b/turing/support/bash-module-env.sh @@ -1,3 +1,4 @@ + # -*- bash -*- # # BASH support scriplet for environment modules. @@ -21,6 +22,7 @@ # Some cluster defaults (may change over time) # Reference: /etc/profile.d/modules.sh +# These are the *old* module environment, pre-2016 upgrade 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 @@ -33,7 +35,25 @@ MODULEPATH_DEFAULT=/cm/local/modulefiles:/cm/shared/modulefiles:/cm/shared/compi RestoreModuleEnv () { local LOADEDMODULES_SAVE - : ${MODULESHOME:=$MODULESHOME_DEFAULT} + + # Update 20170314: now Turing has support for old-style module even in + # batch job. We will leverage that if we find that! + # For proper operation, both LOADEDMODULES and _LMFILES_ must be exported + # into the running environment. + if [ -n "${MODULESHOME}" \ + -a -n "${MODULEPATH}" \ + -a "$(type -t module)" = "function" ]; then + return 0 + fi + case "${MODULESHOME}" in + */lmod*) + # FORCE reloading OLD modules for now. + MODULESHOME=$MODULESHOME_DEFAULT + ;; + *) + : ${MODULESHOME:=$MODULESHOME_DEFAULT} + ;; + esac _AppendPaths MODULEPATH "$MODULEPATH_DEFAULT" export MODULESHOME export MODULEPATH @@ -56,7 +76,20 @@ RestoreModuleEnv () { InitModuleEnv () { # Only do the initialization part of the module so "module" command # is available for the script - : ${MODULESHOME:=$MODULESHOME_DEFAULT} + if [ -n "${MODULESHOME}" \ + -a -n "${MODULEPATH}" \ + -a "$(type -t module)" = "function" ]; then + return 0 + fi + case "${MODULESHOME}" in + */lmod*) + # FORCE reloading OLD modules for now. + MODULESHOME=$MODULESHOME_DEFAULT + ;; + *) + : ${MODULESHOME:=$MODULESHOME_DEFAULT} + ;; + esac _AppendPaths MODULEPATH "$MODULEPATH_DEFAULT" #: ${MODULEPATH:=$MODULEPATH_DEFAULT} export MODULESHOME