|
|
@ -1,5 +1,22 @@ |
|
|
|
# -*- bash -*- |
|
|
|
# -*- bash -*- |
|
|
|
# |
|
|
|
# |
|
|
|
|
|
|
|
# BASH support scriplet for environment modules. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Simply "source" this script with "init" argument, |
|
|
|
|
|
|
|
# then you can use "module" command from the batch script. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Example (from within your batch script): |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# source ~/local/bash-module-env.sh init |
|
|
|
|
|
|
|
# module load gcc |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Optional: if you want to restore the modules listed in $LOADEDMODULES |
|
|
|
|
|
|
|
# (which will need to be passed on to the script via "-v LOADEDMODULES" argument |
|
|
|
|
|
|
|
# when qsub-ing, then use "restore" argment instead: |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Example (from within your batch script): |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# source ~/local/bash-module-env.sh restore |
|
|
|
# |
|
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
# Some cluster defaults (may change over time) |
|
|
|
# Some cluster defaults (may change over time) |
|
|
@ -17,7 +34,7 @@ MODULEPATH_DEFAULT=/cm/local/modulefiles:/cm/shared/modulefiles:/cm/shared/compi |
|
|
|
RestoreModuleEnv () { |
|
|
|
RestoreModuleEnv () { |
|
|
|
local LOADEDMODULES_SAVE |
|
|
|
local LOADEDMODULES_SAVE |
|
|
|
: ${MODULESHOME:=$MODULESHOME_DEFAULT} |
|
|
|
: ${MODULESHOME:=$MODULESHOME_DEFAULT} |
|
|
|
: ${MODULEPATH:=$MODULEPATH_DEFAULT} |
|
|
|
_AppendPaths MODULEPATH "$MODULEPATH_DEFAULT" |
|
|
|
export MODULESHOME |
|
|
|
export MODULESHOME |
|
|
|
export MODULEPATH |
|
|
|
export MODULEPATH |
|
|
|
|
|
|
|
|
|
|
@ -39,15 +56,44 @@ RestoreModuleEnv () { |
|
|
|
InitModuleEnv () { |
|
|
|
InitModuleEnv () { |
|
|
|
# Only do the initialization part of the module so "module" command |
|
|
|
# Only do the initialization part of the module so "module" command |
|
|
|
# is available for the script |
|
|
|
# is available for the script |
|
|
|
local LOADEDMODULES_SAVE |
|
|
|
|
|
|
|
: ${MODULESHOME:=$MODULESHOME_DEFAULT} |
|
|
|
: ${MODULESHOME:=$MODULESHOME_DEFAULT} |
|
|
|
: ${MODULEPATH:=$MODULEPATH_DEFAULT} |
|
|
|
_AppendPaths MODULEPATH "$MODULEPATH_DEFAULT" |
|
|
|
|
|
|
|
#: ${MODULEPATH:=$MODULEPATH_DEFAULT} |
|
|
|
export MODULESHOME |
|
|
|
export MODULESHOME |
|
|
|
export MODULEPATH |
|
|
|
export MODULEPATH |
|
|
|
|
|
|
|
|
|
|
|
source "$MODULESHOME/init/bash" |
|
|
|
source "$MODULESHOME/init/bash" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_AppendPath () { |
|
|
|
|
|
|
|
# Usage: AppendPath VARNAME A_PATH |
|
|
|
|
|
|
|
# Appends a path element if it doesnt exist in current path |
|
|
|
|
|
|
|
local VAR VAL P |
|
|
|
|
|
|
|
VAR=$1 |
|
|
|
|
|
|
|
P=$2 |
|
|
|
|
|
|
|
VAL=$(eval "echo \"\$$VAR\"") # gets the current value of variable ${!VAR} |
|
|
|
|
|
|
|
case ":${VAL}:" in |
|
|
|
|
|
|
|
*:"${P}":*) |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
*) |
|
|
|
|
|
|
|
VAL="${VAL}:${P}" |
|
|
|
|
|
|
|
eval "$VAR=\$VAL" |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
esac |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_AppendPaths () { |
|
|
|
|
|
|
|
# Usage: AppendPath VARNAME PATHLIST |
|
|
|
|
|
|
|
# Appends one or more elements from PATHLIST for the elements that don't |
|
|
|
|
|
|
|
# exist in current path |
|
|
|
|
|
|
|
local VAR PATH1 PATHLIST |
|
|
|
|
|
|
|
VAR=$1 |
|
|
|
|
|
|
|
PATHLIST=$2 |
|
|
|
|
|
|
|
for PATH1 in ${PATHLIST//:/" "}; do |
|
|
|
|
|
|
|
_AppendPath "$VAR" "$PATH1" |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# For convenience: |
|
|
|
# For convenience: |
|
|
|
if [ "$1" = restore ]; then |
|
|
|
if [ "$1" = restore ]; then |
|
|
|
RestoreModuleEnv |
|
|
|
RestoreModuleEnv |
|
|
|