* bash-module-env.sh: an effort to facilitate bash support for batch

scripts.

  Last modified date of this script: 2016-06-23.
master
Wirawan Purwanto 8 years ago
parent bf43a3b0b5
commit 6f0880c547
  1. 57
      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
Loading…
Cancel
Save