| 1 |
# shellcheck shell=sh |
| 2 |
|
| 3 |
unset _mlshdbg; |
| 4 |
# disable shell debugging for the run of this init file |
| 5 |
if [ "${MODULES_SILENT_SHELL_DEBUG:-0}" = '1' ]; then |
| 6 |
# immediately disable debugging to echo the less number of line possible |
| 7 |
case "$-" in |
| 8 |
*v*x*) set +vx; _mlshdbg='vx' ;; |
| 9 |
*v*) set +v; _mlshdbg='v' ;; |
| 10 |
*x*) set +x; _mlshdbg='x' ;; |
| 11 |
*) _mlshdbg='' ;; |
| 12 |
esac; |
| 13 |
fi; |
| 14 |
|
| 15 |
# define modules runtime quarantine configuration |
| 16 |
@setquarvars@export MODULES_RUN_QUARANTINE='@RUN_QUARANTINE@' |
| 17 |
@setquarvars@@export RUNENV_VAR='RUNENV_VAL'@ |
| 18 |
@notsetquarvars@#export MODULES_RUN_QUARANTINE='ENVVARNAME' |
| 19 |
@notsetquarvars@ |
| 20 |
# setup quarantine if defined |
| 21 |
unset _mlre _mlIFS; |
| 22 |
if [ -n "${IFS+x}" ]; then |
| 23 |
_mlIFS=$IFS; |
| 24 |
fi; |
| 25 |
IFS=' '; |
| 26 |
for _mlv in ${MODULES_RUN_QUARANTINE:-}; do |
| 27 |
if [ "${_mlv}" = "${_mlv##*[!A-Za-z0-9_]}" ] && [ "${_mlv}" = "${_mlv#[0-9]}" ]; then |
| 28 |
if [ -n "$(eval 'echo ${'"$_mlv"'+x}')" ]; then |
| 29 |
_mlre="${_mlre:-}__MODULES_QUAR_${_mlv}='$(eval 'echo ${'"$_mlv"'}')' "; |
| 30 |
fi; |
| 31 |
_mlrv="MODULES_RUNENV_${_mlv}"; |
| 32 |
_mlre="${_mlre:-}${_mlv}='$(eval 'echo ${'"$_mlrv"':-}')' "; |
| 33 |
fi; |
| 34 |
done; |
| 35 |
if [ -n "${_mlre:-}" ]; then |
| 36 |
_mlre="eval ${_mlre}__MODULES_QUARANTINE_SET=1 "; |
| 37 |
fi; |
| 38 |
|
| 39 |
# define module command and surrounding initial environment (default value |
| 40 |
# for MODULESHOME, MODULEPATH, LOADEDMODULES and parse of init config files) |
| 41 |
# shellcheck disable=2086 # word splitting expected on _mlre |
| 42 |
_mlcode=$(${_mlre:-}@TCLSH@ '@libexecdir@/modulecmd.tcl' sh autoinit) |
| 43 |
_mlret=$? |
| 44 |
|
| 45 |
# clean temp variables used to setup quarantine |
| 46 |
if [ -n "${_mlIFS+x}" ]; then |
| 47 |
IFS=$_mlIFS; |
| 48 |
unset _mlIFS; |
| 49 |
else |
| 50 |
unset IFS; |
| 51 |
fi; |
| 52 |
unset _mlre _mlv _mlrv |
| 53 |
|
| 54 |
# no environment alteration if the above autoinit command failed |
| 55 |
if [ $_mlret -eq 0 ]; then |
| 56 |
eval "$_mlcode" |
| 57 |
|
| 58 |
# if sh is bash, export functions to get them defined in sub-shells |
| 59 |
# shellcheck disable=SC3045 |
| 60 |
if [ "${BASH:-}" != '' ]; then |
| 61 |
export -f _module_raw |
| 62 |
export -f module |
| 63 |
if [ "$(type -t ml)" = 'function' ]; then |
| 64 |
export -f ml |
| 65 |
fi |
| 66 |
fi |
| 67 |
fi |
| 68 |
|
| 69 |
unset _mlcode _mlret |
| 70 |
|
| 71 |
# restore shell debugging options if disabled |
| 72 |
if [ -n "${_mlshdbg:-}" ]; then |
| 73 |
set -"$_mlshdbg"; |
| 74 |
unset _mlshdbg; |
| 75 |
fi; |
| 76 |
|
| 77 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent syntax=sh : |