#!/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 fi ############################################################################# # implement module comand as function # module() { local -r modulecmd="${PMODULES_HOME}/bin/modulecmd" local -a args=() local -a switches=() local -a sub_switches=() local subcommand='' while (( $# > 0 )); do case $1 in -u|--userlvl ) switches+=( $1 $2 ) shift 2 ;; -* ) switches+=( $1 ) shift ;; [a-z]* ) subcommand=$1 shift break ;; esac done while (( $# > 0 ));do case $1 in -* ) sub_switches+=( $1 ) ;; [a-zA-Z]* ) args+=( $1 ) ;; esac shift done if [[ ${subcommand} == '' ]]; then subcommand='help' fi if (( ${#args} == 0 )); then args+=( '' ) fi for arg in "${args[@]}"; do eval $( "${modulecmd}" bash ${switches[@]} "${subcommand}" "${sub_switches[@]}" "${arg}" ) done } export -f module ############################################################################# # helper functions # append_path () { local -r P=$1 local -r d=$2 if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then if [[ -z ${!P} ]]; then eval $P=${d} else eval $P="${!P}:${d}" fi fi } prepend_path () { local -r P=$1 local -r d=$2 if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then if [[ -z ${!P} ]]; then eval $P=${d} else eval $P="${d}:${!P}" fi fi } ############################################################################# # setup environment # if [[ -z ${LOADEDMODULES} ]]; then declare -x LOADEDMODULES='' fi if [[ -z ${MODULEPATH} ]]; then declare -x MODULEPATH='' fi if [[ -z ${PSI_LOADEDFAMILIES} ]]; then declare -x PSI_LOADEDFAMILIES='' fi for f in ${PSI_DEFAULT_FAMILIES}; do append_path MODULEPATH "${PSI_PREFIX}/${PSI_MODULES_ROOT}/$f" append_path PSI_LOADEDFAMILIES "${f}" done append_path PATH "${PMODULES_HOME}/bin" append_path MANPATH "${PMODULES_HOME}/share/man" ############################################################################# # initialize bash completion # if [[ -r "${PMODULES_HOME}/init/bash_completion" ]]; then source "${PMODULES_HOME}/init/bash_completion" fi ############################################################################# # legacy... # declare -x MODULE_VERSION=${PMODULES_VERSION} declare -x MODULE_VERSION_STACK="${PMODULE_VERSION}" declare -x MODULESHOME="${PMODULES_HOME}" # Local Variables: # mode: sh # sh-basic-offset: 8 # tab-width: 8 # End: