mirror of
https://github.com/envmodules/modules.git
synced 2026-06-07 00:25:05 +08:00
Introduce MODULES_SILENT_SHELL_DEBUG environment variable to silent the xtrace and verbose output on sh-kind shells. When set (means MODULES_SILENT_SHELL_DEBUG=1), current xtrace and verbose flags are saved then these shell properties are disabled. Once execution is finished, saved setup is restored. This mechanism is defined on initialization scripts, at the beginning to silent, at the end to restore defined behavior. It is also defined within the module function following exact same principle. By default, xtrace and verbose shell properties are applied to module function and initialization script if enabled in calling shell script or interactive session. These properties are disabled in module context only if MODULES_SILENT_SHELL_DEBUG is set to '1'. Notice that if xtrace/verbose properties are set, shell code that leads to disable them when MODULES_SILENT_SHELL_DEBUG is set will be outputed as debugging is set during these operations. The mechanism only applies to the SH-shell family. Closes #121
117 lines
4.0 KiB
Plaintext
117 lines
4.0 KiB
Plaintext
# disable shell debugging for the run of this init file
|
|
if [ "$MODULES_SILENT_SHELL_DEBUG" = '1' ]; then
|
|
# immediately disable debugging to echo the less number of line possible
|
|
case "$-" in
|
|
*v*x*) set +vx; _mlshdbg='vx' ;;
|
|
*v*) set +v; _mlshdbg='v' ;;
|
|
*x*) set +x; _mlshdbg='x' ;;
|
|
*) _mlshdbg='' ;;
|
|
esac;
|
|
fi;
|
|
|
|
# define modules runtine quarantine configuration
|
|
@setquarvars@export MODULES_RUN_QUARANTINE='@RUN_QUARANTINE@'
|
|
@setquarvars@@export RUNENV_VAR='RUNENV_VAL'@
|
|
@notsetquarvars@#export MODULES_RUN_QUARANTINE='ENVVARNAME'
|
|
@notsetquarvars@
|
|
# setup quarantine if defined
|
|
_mlre='';
|
|
if [ -n "${IFS+x}" ]; then
|
|
_mlIFS=$IFS;
|
|
fi;
|
|
IFS=' ';
|
|
for _mlv in ${MODULES_RUN_QUARANTINE}; do
|
|
if [ "${_mlv}" = "${_mlv##*[!A-Za-z0-9_]}" -a "${_mlv}" = "${_mlv#[0-9]}" ]; then
|
|
if [ -n "`eval 'echo ${'$_mlv'+x}'`" ]; then
|
|
_mlre="${_mlre}${_mlv}_modquar='`eval 'echo ${'$_mlv'}'`' ";
|
|
fi;
|
|
_mlrv="MODULES_RUNENV_${_mlv}";
|
|
_mlre="${_mlre}${_mlv}='`eval 'echo ${'$_mlrv'}'`' ";
|
|
fi;
|
|
done;
|
|
if [ -n "$_mlre" ]; then
|
|
_mlre="eval ${_mlre}";
|
|
fi;
|
|
|
|
# define module command and surrounding initial environment (default value
|
|
# for MODULESHOME, MODULEPATH, LOADEDMODULES and parse of init/.modulespath)
|
|
eval `${_mlre}@TCLSH@ @libexecdir@/modulecmd.tcl bash autoinit`
|
|
|
|
# clean temp variables used to setup quarantine
|
|
if [ -n "${_mlIFS+x}" ]; then
|
|
IFS=$_mlIFS; unset _mlIFS;
|
|
else
|
|
unset IFS;
|
|
fi;
|
|
unset _mlre _mlv _mlrv
|
|
|
|
@compatversion@# redefine module command if compat version has been activated
|
|
@compatversion@if [ "$MODULES_USE_COMPAT_VERSION" = '1' ]; then
|
|
@compatversion@ if [ -t 1 ]; then
|
|
@compatversion@ _moduleraw() { eval `@libexecdir@/modulecmd-compat bash $*`; }
|
|
@compatversion@ else
|
|
@compatversion@ module() { eval `@libexecdir@/modulecmd-compat bash $*`; }
|
|
@compatversion@ fi
|
|
@compatversion@fi
|
|
@compatversion@
|
|
# export functions to get them defined in sub-shells
|
|
if [ -t 1 ]; then
|
|
export -f _moduleraw
|
|
fi
|
|
export -f module
|
|
|
|
@compatversion@# define function to switch between C and Tcl versions of Modules
|
|
@compatversion@switchml() {
|
|
@compatversion@ typeset swfound=1
|
|
@compatversion@ if [ "$MODULES_USE_COMPAT_VERSION" = '1' ]; then
|
|
@compatversion@ typeset swname='main'
|
|
@compatversion@ if [ -e @libexecdir@/modulecmd.tcl ]; then
|
|
@compatversion@ typeset swfound=0
|
|
@compatversion@ unset MODULES_USE_COMPAT_VERSION
|
|
@compatversion@ fi
|
|
@compatversion@ else
|
|
@compatversion@ typeset swname='compatibility'
|
|
@compatversion@ if [ -e @libexecdir@/modulecmd-compat ]; then
|
|
@compatversion@ typeset swfound=0
|
|
@compatversion@ MODULES_USE_COMPAT_VERSION=1; export MODULES_USE_COMPAT_VERSION
|
|
@compatversion@ fi
|
|
@compatversion@ fi
|
|
@compatversion@
|
|
@compatversion@ # switch version only if command found
|
|
@compatversion@ if [ $swfound -eq 0 ]; then
|
|
@compatversion@ echo "Switching to Modules $swname version"
|
|
@compatversion@ source @initdir@/bash
|
|
@compatversion@ else
|
|
@compatversion@ echo "Cannot switch to Modules $swname version, command not found"
|
|
@compatversion@ return 1
|
|
@compatversion@ fi
|
|
@compatversion@}
|
|
@compatversion@export -f switchml
|
|
@compatversion@
|
|
# setup ENV variables to get module defined in sub-shells (works for 'sh'
|
|
# and 'ksh' in interactive mode and 'sh' (zsh-compat), 'bash' and 'ksh'
|
|
# (zsh-compat) in non-interactive mode.
|
|
ENV=@initdir@/profile.sh; export ENV
|
|
BASH_ENV=@initdir@/bash; export BASH_ENV
|
|
|
|
# enable completion only in interactive mode
|
|
if [ ${BASH_VERSINFO:-0} -ge 3 ] && [[ $- =~ i ]] &&
|
|
[ -r @initdir@/bash_completion ]; then
|
|
source @initdir@/bash_completion
|
|
fi
|
|
|
|
@setbinpath@if [[ ! ":$PATH:" =~ ':@bindir@:' ]]; then
|
|
@setbinpath@ PATH=@bindir@${PATH:+:}$PATH; export PATH
|
|
@setbinpath@fi
|
|
@setbinpath@
|
|
@setmanpath@manpath=`manpath 2>/dev/null`
|
|
@setmanpath@if [[ ! ":$manpath:" =~ ':@mandir@:' ]]; then
|
|
@setmanpath@ MANPATH=@mandir@${manpath:+:}$manpath; export MANPATH
|
|
@setmanpath@fi
|
|
@setmanpath@
|
|
# restore shell debugging options if disabled
|
|
if [ -n "$_mlshdbg" ]; then
|
|
set -$_mlshdbg;
|
|
unset _mlshdbg;
|
|
fi;
|