Files
Pmodules/Pmodules/bash
T
gsell f05e9be3c1 cleanup initialisation
- Pmodules/bash: contains now only the 'module()' function, some sanity
  checks and initialization of bash completion plus unsetting some unused
  variables.
- Pmodules/libstd.bash: bug fixed in std::append_path if path includes spaces
- Pmodules/modulecmd.bash.in: (re-)initialize if 'PMODULES_ENV' is empty or
  unset
2019-04-29 17:15:01 +02:00

91 lines
2.0 KiB
Bash

#!/bin/bash
#############################################################################
# bash 3 or newer ...
#
if [ ${BASH_VERSINFO:-0} -lt 3 ]; then
echo "BASH version ${BASH_VERSION} ist not supported! You need at least version 3..."
return 1
fi
############################################################################
# some sanity checks
#
if [[ ! -d ${PMODULES_ROOT} ]]; then
echo "Oops: ${PMODULES_ROOT}: Set as Pmodules root, but this is not a directory." 1>&2
return 1
fi
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
#############################################################################
# initialize bash completion
#
if [[ -r "${PMODULES_HOME}/init/bash_completion" ]]; then
source "${PMODULES_HOME}/init/bash_completion"
fi
#############################################################################
# legacy...
#
unset MODULE_VERSION
unset MODULE_VERSION_STACK
unset MODULESHOME
#############################################################################
# implement module comand as shell function
#
module() {
unset BASH_ENV
local -r modulecmd="${PMODULES_HOME}/bin/modulecmd"
local -a args=()
local -a modulecmd_opts=()
local -a subcmd_opts=()
while (( $# > 0 )); do
case $1 in
-* )
modulecmd_opts+=( $1 )
shift
;;
* )
break
;;
esac
done
while (( $# > 0 )); do
case $1 in
-* )
subcmd_opts+=( $1 )
;;
[/~a-zA-Z]* )
args+=( $1 )
;;
esac
shift
done
[[ ${#args[@]} == 0 ]] && args+=( 'help' )
[[ ${#args[@]} == 1 ]] && args+=( '--' )
# Loop over all modules to load.
# Note: We have to eval here, otherwise we cannot do something like
# $ module load gcc/5.2.0 openmpi/1.8.8 hdf5/1.8.15
local -i i=1
for (( i=1; i < ${#args[@]}; i++ )); do
eval $( "${modulecmd}" bash "${modulecmd_opts[@]}" "${args[0]}" \
"${subcmd_opts[@]}" "${args[i]}" )
done
}
export -f module
# Local Variables:
# mode: sh
# sh-basic-offset: 8
# tab-width: 8
# End: