From 9b106fd458a2e742a46cb8c6056861f6050ab503 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Wed, 30 Sep 2015 17:22:44 +0200 Subject: [PATCH] Bootstrap (building Pmodules itself) removed --- Bootstrap/.gitignore | 3 - Bootstrap/Modules/build | 55 - Bootstrap/Pmodules/bash | 157 --- Bootstrap/Pmodules/bash_completion | 76 -- Bootstrap/Pmodules/csh | 44 - Bootstrap/Pmodules/dialog.bash | 353 ----- Bootstrap/Pmodules/environment.bash.in | 27 - Bootstrap/Pmodules/environment.csh.in | 17 - Bootstrap/Pmodules/libmodules.tcl | 343 ----- Bootstrap/Pmodules/libpbuild.bash | 756 ----------- Bootstrap/Pmodules/libpmodules.bash | 41 - Bootstrap/Pmodules/libstd.bash | 141 -- Bootstrap/Pmodules/modbuild | 350 ----- Bootstrap/Pmodules/modmanage | 6 - Bootstrap/Pmodules/modmanage.bash.in | 785 ----------- Bootstrap/Pmodules/modsync.bash | 236 ---- Bootstrap/Pmodules/modulecmd | 6 - Bootstrap/Pmodules/modulecmd.bash.in | 1678 ------------------------ Bootstrap/Pmodules/profile.bash | 59 - Bootstrap/Pmodules/profile.csh | 69 - Bootstrap/Tcl/build | 24 - Bootstrap/bash/build | 10 - Bootstrap/bootstrap.sh | 7 - Bootstrap/compile_pmodules.sh | 53 - Bootstrap/config/environment.bash.psi | 17 - Bootstrap/config/versions.conf | 8 - Bootstrap/coreutils/build | 10 - Bootstrap/coreutils/build.new | 10 - Bootstrap/dialog/build | 10 - Bootstrap/getopt/build | 40 - Bootstrap/gettext/build | 22 - Bootstrap/install_pmodules.sh | 46 - Bootstrap/mkindex.tcl | 3 - 33 files changed, 5462 deletions(-) delete mode 100644 Bootstrap/.gitignore delete mode 100755 Bootstrap/Modules/build delete mode 100644 Bootstrap/Pmodules/bash delete mode 100644 Bootstrap/Pmodules/bash_completion delete mode 100644 Bootstrap/Pmodules/csh delete mode 100755 Bootstrap/Pmodules/dialog.bash delete mode 100644 Bootstrap/Pmodules/environment.bash.in delete mode 100755 Bootstrap/Pmodules/environment.csh.in delete mode 100644 Bootstrap/Pmodules/libmodules.tcl delete mode 100644 Bootstrap/Pmodules/libpbuild.bash delete mode 100644 Bootstrap/Pmodules/libpmodules.bash delete mode 100644 Bootstrap/Pmodules/libstd.bash delete mode 100755 Bootstrap/Pmodules/modbuild delete mode 100644 Bootstrap/Pmodules/modmanage delete mode 100755 Bootstrap/Pmodules/modmanage.bash.in delete mode 100755 Bootstrap/Pmodules/modsync.bash delete mode 100644 Bootstrap/Pmodules/modulecmd delete mode 100755 Bootstrap/Pmodules/modulecmd.bash.in delete mode 100644 Bootstrap/Pmodules/profile.bash delete mode 100755 Bootstrap/Pmodules/profile.csh delete mode 100755 Bootstrap/Tcl/build delete mode 100755 Bootstrap/bash/build delete mode 100755 Bootstrap/bootstrap.sh delete mode 100755 Bootstrap/compile_pmodules.sh delete mode 100644 Bootstrap/config/environment.bash.psi delete mode 100644 Bootstrap/config/versions.conf delete mode 100755 Bootstrap/coreutils/build delete mode 100755 Bootstrap/coreutils/build.new delete mode 100755 Bootstrap/dialog/build delete mode 100755 Bootstrap/getopt/build delete mode 100755 Bootstrap/gettext/build delete mode 100755 Bootstrap/install_pmodules.sh delete mode 100755 Bootstrap/mkindex.tcl diff --git a/Bootstrap/.gitignore b/Bootstrap/.gitignore deleted file mode 100644 index 6c96710..0000000 --- a/Bootstrap/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -environment.bash -modulecmd.bash -modmanage.bash diff --git a/Bootstrap/Modules/build b/Bootstrap/Modules/build deleted file mode 100755 index 410fc78..0000000 --- a/Bootstrap/Modules/build +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env modbuild - -TCL_DIR="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" - -PATH="${TCL_DIR}/bin:${PATH}" - -pbuild::configure() { - case ${OS} in - Linux ) - declare -x LIBS="-lz -lpthread" - ;; - Darwin ) - declare -x LIBS="-lz -framework CoreFoundation" - ;; - esac - CPPFLAGS="-DUSE_INTERP_ERRORLINE" "${MODULE_SRCDIR}"/configure \ - --prefix="${PREFIX}" \ - --exec-prefix="${PREFIX}" \ - --with-module-path="${PMODULES_ROOT}/Tools/${PMODULES_MODULEFILES_DIR}" \ - --with-tcl="${TCL_DIR}/lib" \ - --without-x \ - --disable-versioning \ - || exit 1 -} - -pbuild::post_install() { - rm -v ${PREFIX}/Modules/bin/add.modules - rm -v ${PREFIX}/Modules/bin/mkroot - rm -rfv ${PREFIX}/Modules/modulefiles - mv -v ${PREFIX}/Modules/share/man/man1/module.1 ${PREFIX}/share/man/man1 - mv -v ${PREFIX}/Modules/share/man/man4/modulefile.4 ${PREFIX}/share/man/man4 - rmdir ${PREFIX}/Modules/bin - rmdir ${PREFIX}/Modules/share/man/man1 - rmdir ${PREFIX}/Modules/share/man/man4 - rmdir ${PREFIX}/Modules/share/man - rmdir ${PREFIX}/Modules/share - rmdir ${PREFIX}/Modules -} - -# fake module command -module() { - : -} - -# use system gcc to compile -declare -rx CC=gcc - -pbuild::add_to_group 'Tools' -pbuild::make_all - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/bash b/Bootstrap/Pmodules/bash deleted file mode 100644 index 32f5ad3..0000000 --- a/Bootstrap/Pmodules/bash +++ /dev/null @@ -1,157 +0,0 @@ -#!/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=() - - while (( $# > 0 ));do - case $1 in - -* ) - switches+=( $1 ) - ;; - [/~a-zA-Z]* ) - args+=( $1 ) - ;; - esac - shift - done - - [[ ${#args[@]} == 0 ]] && args+=( 'help' ) - [[ ${#args[@]} == 1 ]] && args+=( '--' ) - - # 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 "${args[0]}" "${switches[@]}" "${args[i]}" ) - done -} -export -f module - -############################################################################# -# helper functions -# -std::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 -} - -# -# Replace or remove a directory in a path variable. -# -# To remove a dir: -# std::replace_path PATH -# -# To replace a dir: -# std::replace_path PATH /replacement/path -# -# Args: -# $1 name of the shell variable to set (e.g. PATH) -# $2 a grep pattern identifying the element to be removed/replaced -# $3 the replacement string (use "" for removal) -# -# Based on solution published here: -# https://stackoverflow.com/questions/273909/how-do-i-manipulate-path-elements-in-shell-scripts -# -std::replace_path () { - local -r path=$1 - local -r removepat=$2 - local -r replacestr=$3 - - local -r removestr=$(echo "${!path}" | tr ":" "\n" | grep -m 1 "^$removepat\$") - export $path=$(echo "${!path}" | tr ":" "\n" | sed "s:^${removestr}\$:${replacestr}:" | - sed '/^\s*$/d' | tr "\n" ":" | sed -e 's|^:||' -e 's|:$||') -} - -save_env() { - local s='' - while (( $# > 0 )); do - s+="$( typeset -p $1 );" - shift - done - echo export PMODULES_ENV=$( "${PMODULES_HOME}/bin/base64" --wrap=0 <<< "$s" ) -} - -#module purge - -############################################################################# -# setup environment -# -declare -x LOADEDMODULES='' -declare -x _LMFILES_='' -declare -x PMODULES_USED_GROUPS='' -declare -x MODULEPATH='' -for group in ${PMODULES_DEFAULT_GROUPS//:/ }; do - std::append_path MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}" - std::append_path PMODULES_USED_GROUPS "${group}" -done -declare -x UsedReleases='' -for r in ${PMODULES_DEFAULT_RELEASES//:/ }; do - std::append_path UsedReleases "${r}" -done - -eval $(save_env UsedReleases PMODULES_DEFAULT_RELEASES PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES) -unset UsedReleases -unset PMODULES_DEFAULT_RELEASES -unset PMODULES_DEFAULT_GROUPS -unset PMODULES_DEFINED_RELEASES - -std::replace_path PATH "${PMODULES_HOME%/*}/.*" -std::replace_path MANPATH "${PMODULES_HOME%/*}/.*" -std::append_path PATH "${PMODULES_HOME}/bin" - -if [[ -r /etc/man.config ]]; then - declare _manconf='/etc/man.config' -elif [[ -r /etc/man.conf ]]; then - declare _manconf='/etc/man.conf' -fi -if [[ -n ${_manconf} ]]; then - while read name value rest; do - std::append_path MANPATH "${value}" - done < <(grep "^MANPATH\s" "${_manconf}") - unset _manconf -else - std::append_path MANPATH "${PMODULES_HOME}/share/man" - std::append_path MANPATH "/usr/share/man" -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 - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/bash_completion b/Bootstrap/Pmodules/bash_completion deleted file mode 100644 index 76c789a..0000000 --- a/Bootstrap/Pmodules/bash_completion +++ /dev/null @@ -1,76 +0,0 @@ -# -# Bash commandline completion (bash 3.0 and above) for Modules 3.2.10 -# -_module_avail() { - "${PMODULES_HOME}"/bin/modulecmd bash -t avail 2>&1 | sed ' - /:$/d; - /:ERROR:/d; - s#^\(.*\)/\(.\+\)(default)#\1\n\1\/\2#; - s#/(default)##g; - s#/*$##g;' -} - -_module_not_yet_loaded() { - comm -23 <(_module_avail|sort) <(tr : '\n' <<<${LOADEDMODULES}|sort) -} - -_module_long_arg_list() { - local cur="$1" i - - if [[ ${COMP_WORDS[COMP_CWORD-2]} == sw* ]] - then - COMPREPLY=( $(compgen -W "$(_module_not_yet_loaded)" -- "$cur") ) - return - fi - for ((i = COMP_CWORD - 1; i > 0; i--)) - do case ${COMP_WORDS[$i]} in - add|load) - COMPREPLY=( $(compgen -W "$(_module_not_yet_loaded)" -- "$cur") ) - break;; - rm|remove|unload|switch|swap) - COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") ) - break;; - esac - done -} - -_module() { - local cur="$2" prev="$3" cmds opts - - COMPREPLY=() - - cmds="add apropos avail clear dependencies display help\ - initadd initclear initlist initprepend initrm initswitch\ - keyword list load purge refresh rm search show swap switch sync\ - unload unuse update use whatis" - - opts="-c -f -h -i -l -s -t -u -v -H -V\ - --create --force --help --human --icase\ - --long --silent --terse --userlvl --verbose --version" - - case "$prev" in - add|load) COMPREPLY=( $(compgen -W "$(_module_not_yet_loaded)" -- "$cur") );; - rm|remove|unload|switch|swap) - COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") );; - unuse) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );; - use|*-a*) ;; # let readline handle the completion - -u|--userlvl) COMPREPLY=( $(compgen -W "novice expert advanced" -- "$cur") );; - display|help|show|whatis) - COMPREPLY=( $(compgen -W "$(_module_avail)" -- "$cur") );; - *) if test $COMP_CWORD -gt 2 - then - _module_long_arg_list "$cur" - else - case "$cur" in - # The mappings below are optional abbreviations for convenience - ls) COMPREPLY="list";; # map ls -> list - r*) COMPREPLY="rm";; # also covers 'remove' - sw*) COMPREPLY="switch";; - - -*) COMPREPLY=( $(compgen -W "$opts" -- "$cur") );; - *) COMPREPLY=( $(compgen -W "$cmds" -- "$cur") );; - esac - fi;; - esac -} -complete -o default -F _module module diff --git a/Bootstrap/Pmodules/csh b/Bootstrap/Pmodules/csh deleted file mode 100644 index 93c2d64..0000000 --- a/Bootstrap/Pmodules/csh +++ /dev/null @@ -1,44 +0,0 @@ -if ($?tcsh) then - set modules_shell="tcsh" -else - set modules_shell="csh" -endif -set exec_prefix = $PMODULES_HOME/bin' - -set prefix="" -set postfix="" - -if ( $?histchars ) then - set histchar = `echo $histchars | cut -c1` - set _histchars = $histchars - - set prefix = 'unset histchars;' - set postfix = 'set histchars = $_histchars;' -else - set histchar = \! -endif - -if ($?prompt) then - set prefix = "$prefix"'set _prompt="$prompt";set prompt="";' - set postfix = "$postfix"'set prompt="$_prompt";unset _prompt;' -endif - -if ($?noglob) then - set prefix = "$prefix""set noglob;" - set postfix = "$postfix""unset noglob;" -endif -set postfix = "set _exit="'$status'"; $postfix; test 0 = "'$_exit;' - -alias module $prefix'eval `'$exec_prefix'/modulecmd '$modules_shell' '$histchar'*`; '$postfix -unset exec_prefix -unset prefix -unset postfix - - -if (! $?MODULEPATH ) then - setenv MODULEPATH `sed -n 's/[ #].*$//; /./H; $ { x; s/^\n//; s/\n/:/g; p; }' ${MODULESHOME}/init/.modulespath` -endif - -if (! $?LOADEDMODULES ) then - setenv LOADEDMODULES "" -endif diff --git a/Bootstrap/Pmodules/dialog.bash b/Bootstrap/Pmodules/dialog.bash deleted file mode 100755 index 161546f..0000000 --- a/Bootstrap/Pmodules/dialog.bash +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/env bash - -# Hardcoded path to dialog software -DIALOG_CMD=$PMODULES_HOME/bin/dialog - -declare -a modlist # module info -declare -A selected # module info indices selected -declare -a depcnt # dependency reference counter by module info index -declare -A uidmap # unique module id to module info index -declare -A modmap # map module names to module info indices for modlist -declare -A fdmap # module name to family definition mapping -declare -A fmmap # module name to family member mapping -declare -a relmap # module info index to release mapping -declare tempfile # temporary dialog results - -set_difference() { # $1 \ $2 - local -a operand1=($1) - local -a operand2=($2) - local -A members - local -i elem - for elem in "${operand1[@]}"; do - members[$elem]=1 - done - for elem in "${operand2[@]}"; do - unset members[$elem] - done - echo ${!members[@]} -} - -set_merge() { # $1 U $2 (where $1 and $2 are disjoint) - if [[ -z "$1" ]]; then - echo "$2" - elif [[ -z "$2" ]]; then - echo "$1" - else - echo "$1 $2" - fi -} - -set_union() { # $1 U $2 (sorted) - local -a operand1=($1) - local -a operand2=($2) - local -A members - local -i elem - for elem in ${operand1[@]} ${operand2[@]}; do - members[$elem]=1 - done - { IFS=$'\n'; echo "${!members[*]}"; } | sort -n -} - -# unique id for a module -unique_id() { # $1: module info index - local -a minfo=( ${modlist[$1]} ) - if (( ${#minfo[@]} < 4 )); then - echo ${minfo[0]} - else - echo "${minfo[@]:3} ${minfo[0]}" - fi -} - -mod_path() { # $1: module info index - local -i i - local -a m=(${modlist[$1]}) - local res="$PMODULES_ROOT/${fmmap[${m[0]%%/*}]}/${m[0]}" - for (( i=${#m[@]}; i>3; i-- )); do - res+="/${m[i-1]}" - done - echo "$res" -} - -calc_deps() { # $1: module info index - local dpath="$(mod_path $1)/.dependencies" - [[ ! -r "$dpath" ]] && return - local -a d=( $(< "$dpath") ) # dependencies as versioned module names - local -A p # map family to versioned module name - local -A did # map dependency (versioned module name) to unique module id - local -a deps # set of module info indices - local m n f - for m in ${d[@]}; do - n=${m%%/*} - f=${fdmap[$n]} - [[ -n "$f" ]] && { p[$f]=$m; } - f=${fmmap[$n]} - if [[ -z "$f" ]]; then - did[$m]=$m - else - n=${p[$f]} - if [[ -z "$n" ]]; then - did[$m]=$m - else - did[$m]="${did[$n]} $m" - fi - fi - deps+=( ${uidmap["${did[$m]}"]} ) - done - echo "${deps[@]}" -} - -update_deps() { # $1: 1-add dependency, -1-remove dependency $2: set of module info indices - [[ -z "$2" ]] && return - local -a q=($2) # work queue - local deps="" # set of dependencies - local -i m - while (( ${#q[@]} > 0 )); do - m=${q[-1]} - unset q[-1] - d="$(calc_deps $m)" - [[ -z "$d" ]] && continue - d="$(set_difference "$d" "$deps")" - [[ -z "$d" ]] && continue - q+=($d) - deps="$(set_merge "$d" "$deps")" - done - for m in $deps; do - let depcnt[m]+=$1 - done -} - -# "$1": source module environment -find_modules() { - # construct modlist/modmap/uidmap/depcnt/fmmap/relmap arrays from module search output - local -a mc # module info components - local -i i=0 - local current="" - local name m uid - while read m; do - mc=($m) - [[ "${mc[2]}" == "Legacy" ]] && continue # filter out legacy stuff - name=${mc[0]%%/*} - if [[ "$current" != "$name" ]]; then - modmap[$name]="$i" - current=$name - else - modmap[$name]+=" $i" - fi - modlist[i]=$m - uid="$(unique_id $i)" - uidmap["$uid"]=$i - depcnt[i]=0 - [[ -z ${fmmap[$name]} ]] && { fmmap[$name]=${mc[2]}; } - relmap[i]=${mc[1]} - i+=1 - done < <(${PMODULES_HOME}/bin/modulecmd bash search --src="$1" --no-header -a 2>&1) -} - -# "$1": source module environment -find_families() { - # construct fdmap - local -a t # tcl file components - local l s n - while read l; do - s=${l%%:*} - s=${s%/*} - n=${s##*/} - if [[ -z "${fdmap[$n]}" ]]; then - t=( ${l##*:} ) - fdmap[$n]=${t[-1]//\"} - fi - done < <(grep -R set-family "$1/*/${PMODULES_MODULEFILES_DIR}") -} - -select_uid() { # $1: module uid - local -a uidc=($1) # uid components - local name=${uidc[-1]%%/*} # module name - local midx=${uidmap["$1"]} # module info index - [[ -z "$midx" ]] && return - selected[$name]="$(set_union "${selected[$name]}" "$midx")" - update_deps 1 "$midx" -} - -preselect() { # "$1": prefix for preselected modules - # module paths must not contain white space - [[ -z "$1" ]] && return - local -a mpc # module path components - local -i i - local uid n - pushd "$1/$PMODULES_MODULEFILES_DIR" > /dev/null || exit 1; - trap "popd" EXIT - - for m in $(find . -follow -type f); do - n=${m##*/} - [[ "${n:0:1}" == "." ]] && continue - uid="" - mpc=( ${m//\// } ) - for ((i=2; i<${#mpc[@]}-2; i+=2)); do - uid+="${mpc[i]}/${mpc[i+1]} " - done - uid+="${mpc[-2]}/${mpc[-1]}" - PMODULES_ROOT="$1" select_uid "$uid" - done - - popd - trap - EXIT -} - -is_dependency() { # $1: module name - local -a map=(${modmap[$1]}) - local -i m - for ((m=0; m<${#map[@]}; m++)); do - (( ${depcnt[${map[m]}]} > 0 )) && return 0 - done - return 1 -} - -dialog_1() { - local -a input - local marker - local m - for m in $(IFS=$'\n'; echo "${!modmap[*]}" | sort); do - marker="" - [[ -n ${selected[$m]} ]] && { marker+="*"; } - is_dependency $m && { marker+="+"; } - input+=($m "$marker$m") - done - - $DIALOG_CMD --ok-label 'Select' \ - --extra-button --extra-label 'Exit' \ - --no-tags \ - --menu Modules 50 80 50 "${input[@]}" 2>$tempfile - return $? -} - -module_id() { # $@: module info components - echo "$1 ${@:4}" -} - -module_release() { # $@: module info components - echo "$2" -} - -dialog_2() { # $1: module name - local -a map=(${modmap[$1]}) - local -a sel=(${selected[$1]}) - local -i j # mapping index - local -i k=0 # selection index - local -a input - local marker minfo rel m s - for (( j=0; j!=${#map[@]}; j++ )); do - minfo=${modlist[${map[j]}]} - m="$(module_id $minfo)" - rel=" ($(module_release $minfo))" - [[ $rel = " (stable)" ]] && { rel=""; } - [[ "${map[j]}" = "${sel[k]}" ]] && { s="on"; k+=1; } || { s="off"; } - (( ${depcnt[${map[j]}]} > 0 )) && { marker="+"; l+=1; } || { marker=""; } - input+=( ${map[j]} "$marker$m$rel" $s ) - done - - $DIALOG_CMD --extra-button --extra-label 'Clear' --no-tags --checklist Versions 80 90 80 "${input[@]}" 2>$tempfile - return $? -} - -# final dialog output -module_out() { # $1: module info index - local -a args=(${modlist[$1]}) - echo "${args[@]}" -} - -# "$1": prefix for preselected modules (destination module environment) -# "$2": prefix for selectable modules (source module environment) -module_picker() { - find_families "$2" - find_modules "$2" - preselect "$1" - - tempfile=$(mktemp ${TMPDIR:-/tmp}/msyncXXXXXX) || { - echo "Unable to create temporary file!" - exit 1 - } - trap "rm -f $tempfile" EXIT - - local -i level=1 - local -i operation=0 # 0: OK, 1: Cancel - local oldsel - local sel - local m - while (( level != 0 )); do - case $level in - 1) - dialog_1 - res=$? - case $res in - 0) #OK - sel=$(< $tempfile) - level=2 - ;; - 1) #Cancel - operation=1 - level=0 - ;; - 3|255) #ESC/Exit = Commit - for m in ${selected[@]}; do - depcnt[m]=1 - done - for ((m=0; m<${#depcnt[@]}; m++)); do - (( ${depcnt[m]} > 0 )) && module_out $m >&2 - done - level=0 - ;; - *) - echo "Unknown return value from dialog_1: $res" - exit 1 - ;; - esac - ;; - 2) - dialog_2 $sel - res=$? - case $res in - 0) #OK - oldsel=${selected[$sel]} # old selection - selected[$sel]=$(< $tempfile) # new selection - PMODULES_ROOT="$2" update_deps -1 "$(set_difference "$oldsel" "${selected[$sel]}")" # remove dependencies - PMODULES_ROOT="$2" update_deps 1 "$(set_difference "${selected[$sel]}" "$oldsel")" # add dependencies - level=1 - ;; - 1|255) #ESC/Cancel - level=1 - ;; - 3) #Clear - oldsel=${selected[$sel]} # old selection - selected[$sel]="" # new selection - update_deps -1 "$oldsel" # remove dependencies - level=1 - ;; - *) - echo "Unknown return value from dialog_2: $res" - exit 1 - ;; - esac - ;; - *) - echo "Unknown level: $level" - exit 1 - ;; - esac - done - - rm -f $tempfile - trap - EXIT - - return $operation -} - -# if DIALOG_LIB is NOT set, call module picker -[[ ${DIALOG_LIB:+"is_lib"} == "is_lib" ]] || { - if [[ -x ${PMODULES_HOME}/bin/modulecmd ]]; then - module_picker "${1:-$PMODULES_ROOT}" "${2:-/afs/psi.ch/sys/psi.x86_64_slp6}" - exit $? - else - echo "ERROR: module environment configuration: ${PMODULES_HOME}/bin/modulecmd is not an executable!" - exit 1 - fi -} diff --git a/Bootstrap/Pmodules/environment.bash.in b/Bootstrap/Pmodules/environment.bash.in deleted file mode 100644 index 6adb09f..0000000 --- a/Bootstrap/Pmodules/environment.bash.in +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# -# Notes: -# - PMODULES_ROOT is derived from the location of this file. -# - Some for PMODULES_CONFIG_DIR. -# - The Pmodules software must be installed in -# ${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION} -# - -declare -x PMODULES_MODULEFILES_DIR='modulefiles' -declare -x PMODULES_TEMPLATES_DIR='templates' - -declare -x PMODULES_DEFAULT_GROUPS='Tools Programming' -declare -x PMODULES_DEFINED_RELEASES=':unstable:stable:deprecated:' -declare -x PMODULES_DEFAULT_RELEASES='stable' - -if [[ -z ${PMODULES_VERSION} ]]; then - declare -x PMODULES_VERSION="@PMODULES_VERSION@" -fi - -# -# DO NOT CHANGE THE FOLLOWING LINES! - -declare -x PMODULES_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd) -declare -x PMODULES_CONFIG_DIR=$(basename $(cd $(dirname "${BASH_SOURCE}") && pwd)) -declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" -declare -x PMODULES_DIR="${PMODULES_HOME}" diff --git a/Bootstrap/Pmodules/environment.csh.in b/Bootstrap/Pmodules/environment.csh.in deleted file mode 100755 index 937771c..0000000 --- a/Bootstrap/Pmodules/environment.csh.in +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/tcsh - -setenv PMODULES_ROOT "/opt/psi" - -if ( ! $?PMODULES_VERSION ) then - setenv PMODULES_VERSION "@PMODULES_VERSION@" -endif -setenv PMODULES_HOME "$PMODULES_ROOT/Tools/Pmodules/$PMODULES_VERSION" -setenv PMODULES_DIR "${PMODULES_HOME}" - -setenv PMODULES_CONFIG_DIR 'config' -setenv PMODULES_MODULEFILES_DIR 'modulefiles' -setenv PMODULES_TEMPLATES_DIR 'templates' - -setenv PMODULES_DEFAULT_GROUPS 'Tools Programming' -setenv PMODULES_DEFINED_RELEASES ':unstable:stable:deprecated:' -setenv PMODULES_DEFAULT_RELEASES 'stable' diff --git a/Bootstrap/Pmodules/libmodules.tcl b/Bootstrap/Pmodules/libmodules.tcl deleted file mode 100644 index 2c9840c..0000000 --- a/Bootstrap/Pmodules/libmodules.tcl +++ /dev/null @@ -1,343 +0,0 @@ -# -# :TODO: -# switch/swap -# unload modules if parent removed -# - -if {[info exists env(PMODULES_DEBUG)] && $env(PMODULES_DEBUG)} { - proc debug {msg} { - set level [expr [info level] -2] - set r [catch {info level ${level}} e] - if {$r} { - set caller "" - } else { - set caller [lindex [split [info level [expr [info level] - 3]]] 0] - } - puts -nonewline stderr "${caller}: " - puts stderr ${msg} - } -} else { - proc debug {msg} {} -} - -debug "loading libmodules" - -proc module-addgroup { group } { - global env - global name - global version - - debug "called with arg $group" - set Implementation [file join {*}$::implementation] - - set GROUP [string toupper $group] - regsub -- "-" ${GROUP} "_" GROUP - setenv ${GROUP} $name - setenv ${GROUP}_VERSION $version - - set ::${group} $name - set ::${group}_version $version - - if { [module-info mode load] } { - debug "mode is load" - - append-path MODULEPATH $::PmodulesRoot/$group/$::PmodulesModulfilesDir/$Implementation - append-path PMODULES_USED_GROUPS $group - debug "mode=load: new MODULEPATH=$env(MODULEPATH)" - debug "mode=load: new PMODULES_USED_GROUPS=$env(PMODULES_USED_GROUPS)" - } elseif { [module-info mode remove] } { - set GROUP [string toupper $group] - debug "remove hierarchical group '${GROUP}'" - - if { [info exists env(PMODULES_LOADED_${GROUP})] } { - debug "unloading orphan modules" - set modules [split $env(PMODULES_LOADED_${GROUP}) ":"] - foreach m ${modules} { - if { ${m} == "--APPMARKER--" } { - continue - } - if { [is-loaded ${module_name}] } { - debug "unloading: $m" - module unload ${m} - } - } - } else { - debug "no orphan modules to unload" - } - debug "mode=remove: $env(MODULEPATH)" - remove-path MODULEPATH $::PmodulesRoot/$group/$::PmodulesModulfilesDir/$Implementation - debug "mode=remove: $env(PMODULES_USED_GROUPS)" - remove-path PMODULES_USED_GROUPS $group - } - if { [module-info mode switch2] } { - debug "mode=switch2" - append-path MODULEPATH $::PmodulesRoot/$group/$::PmodulesModulfilesDir/[module-info name] - append-path PMODULES_USED_GROUPS ${group} - } -} - -proc set-family { group } { - module-addgroup $group -} - -proc _pmodules_update_loaded_modules { group name version } { - if { ${group} == "--APPMARKER--" } { - return - } - set GROUP [string toupper $group] - debug "${GROUP} $name/$version" - append-path PMODULES_LOADED_${GROUP} "$name/$version" - remove-path PMODULES_LOADED_${GROUP} "--APPMARKER--" -} - -# -# load dependencies, but do *not* unload dependencies -# -proc _pmodules_load_dependencies { fname } { - if { ! [ file exists ${fname} ] } { - return - } - if { ! [module-info mode load] } { - return - } - debug "load dependencies from: ${fname}" - # Slurp up the data file - set fp [open ${fname} r] - set file_data [read ${fp}] - close ${fp} - set data [split ${file_data} "\n"] - foreach line ${data} { - debug "MODULEPATH=$::env(MODULEPATH)" - set module_name [string trim $line] - if { ${module_name} == "#" || ${module_name} == "" } { - continue - } - if { [is-loaded ${module_name}] } { - debug "module already loaded: ${module_name}" - continue - } - debug "module load: ${module_name}" - module load ${module_name} - } -} - -proc lreverse_n { list n } { - set res {} - set i [expr [llength $list] - $n] - while {$i >= 0} { - lappend res {*}[lrange $list $i [expr $i+$n-1]] - incr i -$n - } - set res -} - -# -# set standard environment variables -# -proc _pmodules_setenv { PREFIX name version } { - # - # Hack for supporting legacy modules - if { "${::group}" == "Legacy" } { - debug "this is a legacy module..." - return - } - - set NAME [string toupper $name] - regsub -- "-" ${NAME} "_" NAME - - if { ! [info exist ::dont-setenv] } { - set ::dont-setenv {} - } - - if { ${version} != "" } { - if { [lsearch ${::dont-setenv} "${NAME}_VERSION"] == -1 } { - setenv ${NAME}_VERSION $version - } - } - - if { [file isdirectory "$PREFIX"] } { - if { [lsearch ${::dont-setenv} "${NAME}_PREFIX"] == -1 } { - setenv ${NAME}_PREFIX $PREFIX - } - if { [lsearch ${::dont-setenv} "${NAME}_DIR"] == -1 } { - setenv ${NAME}_DIR $PREFIX - } - if { [lsearch ${::dont-setenv} "${NAME}_HOME"] == -1 } { - setenv ${NAME}_HOME $PREFIX - } - } else { - debug "$PREFIX is not a directory" - } - - if { [file isdirectory "$PREFIX/bin"] } { - if { [lsearch ${::dont-setenv} "PATH"] == -1 } { - prepend-path PATH $PREFIX/bin - } - } - - if { [file isdirectory "$PREFIX/sbin"] } { - if { [lsearch ${::dont-setenv} "PATH"] == -1 } { - prepend-path PATH $PREFIX/sbin - } - } - - if { [file isdirectory "$PREFIX/share/man"] } { - if { [lsearch ${::dont-setenv} "MANPATH"] == -1 } { - prepend-path MANPATH $PREFIX/share/man - } - } - - # set various environment variables - as long as they are not blacklisted - debug "prepend to include paths" - if { [file isdirectory "$PREFIX/include"] } { - if { [lsearch ${::dont-setenv} "C_INCLUDE_PATH"] == -1 } { - prepend-path C_INCLUDE_PATH $PREFIX/include - } - if { [lsearch ${::dont-setenv} "CPLUS_INCLUDE_PATH"] == -1 } { - prepend-path CPLUS_INCLUDE_PATH $PREFIX/include - } - if { [lsearch ${::dont-setenv} "${NAME}_INCLUDE_DIR"] == -1 } { - setenv ${NAME}_INCLUDE_DIR $PREFIX/include - } - } - - debug "prepend to library paths" - if { [file isdirectory "$PREFIX/lib"] } { - if { [lsearch ${::dont-setenv} "LIBRARY_PATH"] == -1 } { - prepend-path LIBRARY_PATH $PREFIX/lib - } - if { [lsearch ${::dont-setenv} "LD_LIBRARY_PATH"] == -1 } { - prepend-path LD_LIBRARY_PATH $PREFIX/lib - } - if { [lsearch ${::dont-setenv} "${NAME}_LIBRARY_DIR"] == -1 } { - setenv ${NAME}_LIBRARY_DIR $PREFIX/lib - } - } - - debug "prepend to library paths (64bit)" - if { [file isdirectory "$PREFIX/lib64"] } { - if { [lsearch ${::dont-setenv} "LIBRARY_PATH"] == -1 } { - prepend-path LIBRARY_PATH $PREFIX/lib64 - } - if { [lsearch ${::dont-setenv} "LD_LIBRARY_PATH"] == -1 } { - prepend-path LD_LIBRARY_PATH $PREFIX/lib64 - } - if { [lsearch ${::dont-setenv} "${NAME}_LIBRARY_DIR"] == -1 } { - setenv ${NAME}_LIBRARY_DIR $PREFIX/lib64 - } - } -} - -proc module-url { _url } { - set ::url ${_url} -} - -proc module-license { _license } { - set ::license ${_license} -} - -proc module-maintainer { _maintainer } { - set ::maintainer ${_maintainer} -} - -proc module-help { _help } { - set ::help ${_help} -} - -proc ModulesHelp { } { - if { [info exists ::whatis] } { - puts stderr "${::whatis}" - } else { - module whatis ModulesCurrentModulefile - } - if { [info exists ::version] } { - puts stderr "Version: ${::version}" - } else { - module whatis - } - if { [info exists ::url] } { - puts stderr "Homepage: ${::url}" - } - if { [info exists ::license] } { - puts stderr "License: ${::license}" - } - if { [info exists ::maintainer] } { - puts stderr "Maintainer: ${::maintainer}" - } - if { [info exists ::help] } { - puts stderr "${::help}\n" - } -} - -# -# intialize global vars -# Modulefile is something like -# -# ${PMODULES_ROOT}/group/${PMODULES_MODULEFILES_DIR}/name/version -# or -# ${PMODULES_ROOT}/group/${PMODULES_MODULEFILES_DIR}/X1/Y1/name/version -# or -# ${PMODULES_ROOT}/group/${PMODULES_MODULEFILES_DIR}/X1/Y1//X2/Y2/name/version -# -proc _pmodules_init_global_vars { } { - global group - global name - global version - global implementation - global PREFIX # prefix of package - - debug "$::ModulesCurrentModulefile" - set ::PmodulesRoot $::env(PMODULES_ROOT) - set ::PmodulesModulfilesDir $::env(PMODULES_MODULEFILES_DIR) - set modulefile [file split $::ModulesCurrentModulefile] - set pmodules_root [file split $::PmodulesRoot] - set pmodules_root_num_dirs [llength $pmodules_root] - - set modulefile_root [file join {*}[lrange $modulefile 0 [expr $pmodules_root_num_dirs - 1]]] - if { $::PmodulesRoot != $modulefile_root } { - debug "stop sourcing: ${::PmodulesRoot} != $modulefile_root" - return - } - debug "modulefile is inside our root" - set rel_modulefile [lrange $modulefile [llength $pmodules_root] end] - set group [lindex $rel_modulefile 0] - set name [lindex $modulefile end-1] - set version [lindex $modulefile end] - set implementation [lrange $rel_modulefile 2 end] - set prefix "$pmodules_root $group [lreverse_n $implementation 2]" - set PREFIX [file join {*}$prefix] - - debug "PREFIX=$PREFIX" - debug "group of module $name: $group" -} - -proc _pmodules_output_message { fname } { - if { [ file exists "${fname}" ] } { - set fp [open "${fname}" r] - set info_text [read $fp] - close $fp - puts stderr ${info_text} - } -} - -if { [info exists ::whatis] } { - module-whatis "$whatis" -} - -_pmodules_init_global_vars - -# -# we cannot load another module with the same name -# -conflict $name - -if { [module-info mode load] } { - debug "${name}/${version}: loading ... " - _pmodules_output_message "${PREFIX}/.info" - _pmodules_load_dependencies "${PREFIX}/.dependencies" -} - -_pmodules_setenv ${PREFIX} ${name} ${version} -_pmodules_update_loaded_modules ${group} ${name} ${version} - -debug "return from lib" diff --git a/Bootstrap/Pmodules/libpbuild.bash b/Bootstrap/Pmodules/libpbuild.bash deleted file mode 100644 index e3a3c81..0000000 --- a/Bootstrap/Pmodules/libpbuild.bash +++ /dev/null @@ -1,756 +0,0 @@ -#!/bin/bash - -# number of parallel make jobs -declare -i JOBS=3 - -declare -x PREFIX='' -declare -x DOCDIR='' -declare -x MODULE_GROUP='' -declare -x MODULE_RELEASE='' -declare cur_module_release='' - -declare DEPEND_RELEASE='' -declare -x MODULE_NAME='' - -# these directories are module dependend -declare -x MODULE_SRCDIR='' -declare -x MODULE_BUILDDIR='' - -declare -x MODULE_BUILD_DEPENDENCIES -declare -x MODULE_DEPENDENCIES - -declare -x C_INCLUDE_PATH -declare -x CPLUS_INCLUDE_PATH -declare -x CPP_INCLUDE_PATH -declare -x LIBRARY_PATH -declare -x LD_LIBRARY_PATH -declare -x DYLD_LIBRARY_PATH - -is_release() { - [[ :${releases}: =~ :$1: ]] && return 0 - std::die 1 "${P}: '$1' is not a valid release name." -} - -pbuild::set_release() { - is_release "$1" && MODULE_RELEASE="$1" -} - -############################################################################## -# -# set supported OS -# -# $1: OS (as printed by 'uname -s') -# -pbuild::supported_os() { - for os in "$@"; do - [[ ${os} == ${OS} ]] && return 0 - done - std::die 1 "${P}: Not available for ${OS}." -} - -############################################################################## -# -# install module in given group -# -# $1: group -# -pbuild::add_to_group() { - if [[ -z ${1} ]]; then - std::die 42 "${FUNCNAME}: Missing group argument." - fi - MODULE_GROUP=$1 -} - -############################################################################## -# -# set build-/runtime dependencies -# -# $@: dependencies -# -pbuild::set_build_dependencies() { - MODULE_BUILD_DEPENDENCIES=("$@") -} - -pbuild::set_runtime_dependencies() { - MODULE_DEPENDENCIES=("$@") -} - -############################################################################## -# -# set documentation file to be installed -# -# $@: documentation files relative to source -# -pbuild::set_docfiles() { - MODULE_DOCFILES=("$@") -} - -############################################################################## -# -# set supported compilers -# -# $@: compilers -# -pbuild::set_supported_compilers() { - MODULE_SUPPORTED_COMPILERS=("$@") -} - -############################################################################## -# -# test availablity of a module -# -# $@: module -# -pbuild::module_is_available() { - [[ -n $("${MODULECMD}" bash avail "$1" 2>&1 1>/dev/null) ]] -} - - -############################################################################## -# -# cleanup environment -# -pbuild::cleanup_env() { - - C_INCLUDE_PATH='' - CPLUS_INCLUDE_PATH='' - CPP_INCLUDE_PATH='' - LIBRARY_PATH='' - LD_LIBRARY_PATH='' - DYLD_LIBRARY_PATH='' - - CFLAGS='' - CPPFLAGS='' - CXXFLAGS='' - LIBS='' - LDFLAGS='' -} - -pbuild::pre_configure() { - : -} - -pbuild::configure() { - ${MODULE_SRCDIR}/configure \ - --prefix="${PREFIX}" -} - -pbuild::build() { - make -j${JOBS} -} - -pbuild::install() { - make install -} - -pbuild::post_install() { - : -} - -pbuild::install_doc() { - std::info "Installing documentation to ${DOCDIR}" - install -m 0755 -d "${DOCDIR}" - install -m0444 "${MODULE_DOCFILES[@]/#/${MODULE_SRCDIR}/}" "${BUILD_BLOCK}" "${DOCDIR}" -} - -pbuild::cleanup_build() { - [[ -n "${MODULE_BUILDDIR}" ]] \ - || std::die 1 "Oops: internal error: MODULE_BUILDDIR is set to empty string..." - [[ "${MODULE_BUILDDIR}" == "/" ]] \ - && std::die 1 "Oops: internal error: MODULE_BUILDDIR is set to '/'..." - [[ -d "/${MODULE_BUILDDIR}" ]] \ - || std::die 1 "Oops: internal error: MODULE_BUILDDIR=${MODULE_BUILDDIR} is not a directory..." - echo "Cleaning up '/${MODULE_BUILDDIR}'..." - rm -rf "/${MODULE_BUILDDIR}" -} - -pbuild::cleanup_src() { - ( - [[ -d /${MODULE_SRCDIR} ]] || return 0 - cd "/${MODULE_SRCDIR}/.."; - if [[ $(pwd) != / ]]; then - echo "Cleaning up $(pwd)" - rm -rf ${MODULE_SRCDIR##*/} - fi - ); - return 0 -} - -# -# The 'do it all' function. -# -pbuild::make_all() { - # - # helper functions - # - - ############################################################################## - # - # load default versions - # - set_default_versions() { - local -r fname="$1" - [[ -r ${fname} ]] || return 0 - - local varname='' - while read _name _version; do - [[ -z ${_name} ]] && continue - [[ -z ${_version} ]] && continue - [[ "${_name:0:1}" == '#' ]] && continue - var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION - # don't set version, if already set - if [[ -z ${!var_name} ]]; then - eval ${var_name}="${_version}" - fi - done < "${fname}" - - } - - ############################################################################## - # - # test whether a module is loaded or not - # - # $1: module name - # - is_loaded() { - [[ :${LOADEDMODULES}: =~ :$1: ]] - } - - ############################################################################## - # - load_build_dependencies() { - for m in "${MODULE_BUILD_DEPENDENCIES[@]}"; do - [[ -z $m ]] && continue - if [[ ! $m =~ "*/*" ]]; then - local _V=$(echo -n $m | tr [:lower:] [:upper:] )_VERSION - if [[ -n ${!_V} ]]; then - m=$m/${!_V} - else - echo "$m: warning: No version set, loading default ..." - fi - fi - is_loaded "$m" && continue - if ! pbuild::module_is_available "$m"; then - std::debug "${m}: module not available" - local rels=( ${releases//:/ } ) - for rel in "${rels[@]}"; do - std::debug "${m}: check release \"${rel}\"" - eval $("${MODULECMD}" bash use ${rel}) - if pbuild::module_is_available "${m}"; then - std::die 1 "${m}: module available with release \"${rel}\", add this release with \"module use ${rel}\" and re-run build script." - fi - done - [[ ${dry_run} == yes ]] && { - std::die 1 "${m}: module does not exist, cannot continue with dry run..." - } - - echo "$m: module does not exist, trying to build it..." - local args=( '' ) - set -- ${ARGS[@]} - while (( $# > 0 )); do - case $1 in - -j ) - args+=( "-j $2" ) - shift - ;; - --jobs=[0-9]* ) - args+=( $1 ) - ;; - -v | --verbose) - args+=( $1 ) - ;; - --release=* ) - args+=( $1 ) - ;; - --with=*/* ) - args+=( $1 ) - ;; - *=* ) - args+=( $1 ) - ;; - esac - shift - done - "${BUILD_SCRIPTSDIR}"/*/"${m/\/*}/build" ${args[@]} - if [[ -z $(module avail "$m" 2>&1) ]]; then - std::die 1 "$m: oops: build failed..." - fi - fi - # :FIXME: this doesn't work any more! - local modulepath_root="${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}" - local tmp=$( module display "${m}" 2>&1 | grep -m1 -- "${modulepath_root}" ) - tmp=${tmp/${modulepath_root}\/} - tmp=${tmp%%/*} - local _family=( ${tmp//./ } ) - if [[ ${_family[1]} == deprecated ]]; then - # set module release to 'deprecated' if a build dependency - # is deprecated - DEPEND_RELEASE='deprecated' - elif [[ ${_family[1]} == unstable ]] && [[ -z ${DEPEND_RELEASE} ]]; then - # set module release to 'unstable' if a build dependency is - # unstable and release not yet set - DEPEND_RELEASE='unstable' - fi - - - echo "Loading module: ${m}" - module load "${m}" - done - } - - - ############################################################################## - # - # find tarball - # $1: download directory - # $2: name without version - # $3: version - # - find_tarball() { - local -r dir=$1 - local -r name=$2 - local -r version=$3 - - TARBALL="" - local ext - for ext in tar tar.gz tgz tar.bz2 tar.xz; do - local fname="${dir}/${name}-${OS}-${version}.${ext}" - if [[ -r "${fname}" ]]; then - TARBALL="${fname}" - break - fi - local fname="${dir}/${name}-${version}.${ext}" - if [[ -r "${fname}" ]]; then - TARBALL="${fname}" - break - fi - done - if [[ -z ${TARBALL} ]]; then - std::error "tar-ball for $P/$V not found." - exit 43 - fi - } - - ############################################################################## - # - # check and setup module specific environment. - # - # The following variables must already be set: - # MODULE_GROUP module group - # P module name - # _P module name in upper case - # MODULEPATH module path - # BUILD_DOWNLOADSDIR directory where all the tar-balls are stored - # - # The following variables might already be set - # V module version, if not set ${_P}_VERSION must - # evaluate to a version - # ${_P}_VERSION module version - # MODULE_RELEASE module release, one of 'unstable', 'stable', - # 'deprecated' - # - # The following variables are set in this function - # MODULE_SRCDIR - # MODULE_BUILDDIR - # MODULE_RPREFIX - # MODULE_NAME - # MODULE_RELEASE - # PREFIX - # DOCDIR - # - check_and_setup_env() { - if [[ -z ${MODULE_GROUP} ]]; then - std::die 1 "$P: group not set." - fi - - # this allows us to specify the version as PKGNAME_VERSION=1.2.3 on - # the cmd-line - if [[ -z $V ]]; then - V=$(eval echo \$${_P}_VERSION) - fi - - # oops, we need a version - if [[ -z $V ]]; then - std::die 1 "$P: Missing version." - fi - MODULE_SRCDIR="${BUILD_TMPDIR}/src/${P/_serial}-$V" - MODULE_BUILDDIR="${BUILD_TMPDIR}/build/$P-$V" - - # build module name - # :FIXME: the MODULE_PREFIX should be derived from MODULE_NAME - # :FIXME: this should be read from a configuration file - case ${MODULE_GROUP} in - Tools ) - MODULE_RPREFIX="${P}/${V}" - MODULE_NAME="${P}/${V}" - ;; - Programming ) - MODULE_RPREFIX="${P}/${V}" - MODULE_NAME="${P}/${V}" - ;; - Libraries ) - MODULE_RPREFIX="${P}/${V}" - MODULE_NAME="${P}/${V}" - ;; - System ) - MODULE_RPREFIX="${P}/${V}" - MODULE_NAME="${P}/${V}" - ;; - Compiler ) - MODULE_RPREFIX="${P}/${V}" - MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}" - - MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/" - MODULE_NAME+="${P}/${V}" - ;; - MPI ) - MODULE_RPREFIX="${P}/${V}/" - MODULE_RPREFIX+="${MPI}/${MPI_VERSION}/" - MODULE_RPREFIX+="${COMPILER}/${COMPILER_VERSION}" - - MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/" - MODULE_NAME+="${MPI}/${MPI_VERSION}/" - MODULE_NAME+="${P}/${V}" - ;; - HDF5 ) - MODULE_RPREFIX="${P}/${V}" - MODULE_RPREFIX+="/${HDF5}/${HDF5_VERSION}" - MODULE_RPREFIX+="/${MPI}/${MPI_VERSION}" - MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}" - - MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/" - MODULE_NAME+="${MPI}/${MPI_VERSION}/" - MODULE_NAME+="${HDF5}/${HDF5_VERSION}/" - MODULE_NAME+="${P}/${V}" - ;; - OPAL ) - MODULE_RPREFIX="${P}/${V}" - MODULE_RPREFIX+="/${OPAL}/${OPAL_VERSION}" - MODULE_RPREFIX+="/${MPI}/${MPI_VERSION}" - MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}" - - MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/" - MODULE_NAME+="${MPI}/${MPI_VERSION}/" - MODULE_NAME+="${OPAL}/${OPAL_VERSION}/" - MODULE_NAME+="${P}/${V}" - ;; - HDF5_serial ) - MODULE_RPREFIX="${P}/${V}" - MODULE_RPREFIX+="/hdf5_serial/${HDF5_SERIAL_VERSION}" - MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}" - - MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/" - MODULE_NAME+="hdf5_serial/${HDF5_SERIAL_VERSION}/" - MODULE_NAME+="${P}/${V}" - ;; - * ) - std::die 1 "$P: oops: unknown group: ${MODULE_GROUP}" - ;; - esac - - # set PREFIX of module - PREFIX="${PMODULES_ROOT}/${MODULE_GROUP}/${MODULE_RPREFIX}" - - # get module release if already installed - local saved_modulepath=${MODULEPATH} - rels=( ${releases//:/ } ) - for rel in "${rels[@]}"; do - eval $("${MODULECMD}" bash unuse ${rel}) - done - for rel in "${rels[@]}"; do - eval $("${MODULECMD}" bash use ${rel}) - if pbuild::module_is_available "${P}/${V}"; then - cur_module_release=${rel} - std::info "${P}/${V}: already available and released as \"${rel}\"" - break - fi - done - MODULEPATH=${saved_modulepath} - - # set release of module - # release is deprecated - # - if a build-dependency is deprecated or - # - the module already exists and is deprecated or - # - is forced to be deprecated by setting this on the command line - if [[ "${depend_release}" == 'deprecated' ]] || \ - [[ "${cur_module_release}" == 'deprecated' ]] \ - || [[ "${MODULE_RELEASE}" == 'deprecated' ]]; then - MODULE_RELEASE='deprecated' - std::info "${P}/${V}: will be released as \"deprecated\"" - # - # release is stable - # - if all build-dependency are stable or - # - the module already exists and is stable - # - an unstable release of the module exists and the release is - # changed to stable on the command line - elif [[ "${depend_release}" == 'stable' ]] \ - || [[ "${cur_module_release}" == 'stable' ]] \ - || [[ "${MODULE_RELEASE}" == 'stable' ]]; then - MODULE_RELEASE='stable' - std::info "${P}/${V}: will be released as \"stable\"" - # - # release is unstable - # - if a build-dependency is unstable or - # - if the module does not exists and no other release-type is - # given on the command line - # - and all the cases I didn't think of - else - MODULE_RELEASE='unstable' - std::info "${P}/${V}: will be released as \"unstable\"" - fi - - # directory for README's, license files etc - DOCDIR="${PREFIX}/share/doc/$P" - - # set tar-ball and flags for tar - find_tarball "${BUILD_DOWNLOADSDIR}" "${P/_serial}" "${V}" - - } - - # redefine function for bootstrapping - check_and_setup_env_bootstrap() { - if [[ -z ${MODULE_GROUP} ]]; then - std::die 1 "$P: group not set." - fi - - if [[ -z $V ]]; then - V=$(eval echo \$${_P}_VERSION) - fi - - # oops, we need a version - if [[ -z $V ]]; then - std::die 1 "$P: Missing version." - fi - MODULE_SRCDIR="${BUILD_TMPDIR}/src/${P/_serial}-$V" - MODULE_BUILDDIR="${BUILD_TMPDIR}/build/$P-$V" - MODULE_GROUP='Tools' - MODULE_NAME="Pmodules/${PMODULES_VERSION}" - # set PREFIX of module - PREFIX="${PMODULES_ROOT}/${MODULE_GROUP}/${MODULE_NAME}" - - MODULE_RELEASE='unstable' - std::info "${MODULE_NAME}: will be released as \"${MODULE_RELEASE}\"" - - # directory for README's, license files etc - DOCDIR="${PREFIX}/share/doc/$P" - - # set tar-ball and flags for tar - find_tarball "${BUILD_DOWNLOADSDIR}" "${P/_serial}" "${V}" - - C_INCLUDE_PATH="${PREFIX}/include" - CPLUS_INCLUDE_PATH="${PREFIX}/include" - CPP_INCLUDE_PATH="${PREFIX}/include" - LIBRARY_PATH="${PREFIX}/lib" - LD_LIBRARY_PATH="${PREFIX}/lib" - DYLD_LIBRARY_PATH="${PREFIX}/lib" - - PATH+=":${PREFIX}/bin" - } - - ############################################################################## - check_compiler() { - test -z ${MODULE_SUPPORTED_COMPILERS} && return 0 - for cc in ${MODULE_SUPPORTED_COMPILERS[@]}; do - if [[ ${COMPILER}/${COMPILER_VERSION} =~ ${cc} ]]; then - return 0 - fi - done - std::die 0 "Package cannot be build with ${COMPILER}/${COMPILER_VERSION}." - } - - ############################################################################## - prep() { - # untar sources - if [[ ! -d ${MODULE_SRCDIR} ]]; then - mkdir -p "${BUILD_TMPDIR}/src" - (cd "${BUILD_TMPDIR}/src" && tar xvf "${TARBALL}") - fi - - # create build directory - mkdir -p "${MODULE_BUILDDIR}" - } - - ############################################################################## - post_install() { - # unfortunatelly sometime we need an OS depended post-install - post_install_linux() { - cd "${PREFIX}" - # solve multilib problem with LIBRARY_PATH on 64bit Linux - [[ -d "lib" ]] && [[ ! -d "lib64" ]] && ln -s lib lib64 - return 0 - } - - std::info "Run post-installation for ${OS} ..." - [[ "${OS}" == "Linux" ]] && post_install_linux - std::info "Post-installation done ..." - return 0 - } - - ############################################################################## - write_runtime_dependencies() { - local -r fname="${PREFIX}/.dependencies" - std::info "Writing run-time dependencies to ${fname}" - local dep - echo -n "" > "${fname}" - for dep in "${MODULE_DEPENDENCIES[@]}"; do - [[ -z $dep ]] && continue - if [[ ! $dep =~ .*/.* ]]; then - local _V=$(echo -n $dep | tr [:lower:] [:upper:] )_VERSION - dep=$dep/${!_V} - fi - echo "${dep}" >> "${fname}" - done - } - - ############################################################################## - write_build_dependencies() { - local -r fname="${PREFIX}/.build_dependencies" - std::info "Writing build dependencies to ${fname}" - local dep - echo -n "" > "${fname}" - for dep in "${MODULE_BUILD_DEPENDENCIES[@]}"; do - [[ -z $dep ]] && continue - if [[ ! $dep =~ "*/*" ]]; then - local _V=$(echo -n $dep | tr [:lower:] [:upper:] )_VERSION - dep=$dep/${!_V} - fi - echo "${dep}" >> "${fname}" - done - } - - ############################################################################## - set_legacy_link() { - local -r link_name="${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}/${MODULE_GROUP}/${MODULE_NAME}" - local -r dir_name=${link_name%/*} - local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}" - if [[ ! -e "${_path}" ]]; then - ( - std::info "Setting new sym-link \"${link_name}\" ..." - mkdir -p "${dir_name}" - cd "${dir_name}" - local x - IFS='/' x=( ${dir_name/${PMODULES_ROOT}\/${PMODULES_MODULEFILES_DIR}\/} ) - local n=${#x[@]} - local -r _target="../"$(eval printf "../%.s" {1..${n}})${PMODULES_TEMPLATES_DIR##*/}/"${MODULE_GROUP}/${P}/modulefile" - ln -fs "${_target}" "${MODULE_NAME##*/}" - ) - fi - std::info "${MODULE_NAME}: set release to '${MODULE_RELEASE}'" - echo "${MODULE_RELEASE}" > "${release_file}" - } - - ############################################################################## - set_link() { - local -r link_name="${PMODULES_ROOT}/${MODULE_GROUP}/${PMODULES_MODULEFILES_DIR}/${MODULE_NAME}" - local -r dir_name=${link_name%/*} - local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}" - if [[ ! -e "${_path}" ]]; then - ( - std::info "Setting new sym-link \"${link_name}\" ..." - mkdir -p "${dir_name}" - cd "${dir_name}" - local x - IFS='/' x=( ${dir_name/${PMODULES_ROOT}\/${MODULE_GROUP}\/} ) - local -i n=${#x[@]} - local _target=$(eval printf "../%.s" {1..${n}}) - _target+="${PMODULES_TEMPLATES_DIR}/${P}/modulefile" - ln -fs "${_target}" "${MODULE_NAME##*/}" - ) - fi - std::info "${MODULE_NAME}: set release to '${MODULE_RELEASE}'" - echo "${MODULE_RELEASE}" > "${release_file}" - } - - ############################################################################## - install_modulefile() { - local -r src="${BUILD_BLOCK_DIR}/modulefile" - local -r dst="${PMODULES_ROOT}/${MODULE_GROUP}/${PMODULES_TEMPLATES_DIR}/${P}" - - std::info "${MODULE_NAME}: installing modulefile in '${dst}'" - install -m 0444 "${src}" "${dst}" - } - - ############################################################################## - # - # here we really start with make_all() - # - local building='no' - echo "${P}:" - set_default_versions "${BUILD_VERSIONSFILE}" - - # setup module specific environment - if [[ ${bootstrap} == no ]]; then - load_build_dependencies - check_and_setup_env - else - check_and_setup_env_bootstrap - fi - - if [[ ! -d "${PREFIX}" ]] || \ - [[ ${force_rebuild} == 'yes' ]] || \ - [[ ${bootstrap} == 'yes' ]]; then - building='yes' - echo "Building $P/$V ..." - [[ ${dry_run} == yes ]] && std::die 0 "" - check_compiler - - if [[ ! -e "${MODULE_BUILDDIR}/.prep" ]] || [[ ${force_rebuild} == 'yes' ]] ; then - prep - touch "${MODULE_BUILDDIR}/.prep" - fi - [[ "${target}" == "prep" ]] && return 0 - - if [[ ! -e "${MODULE_BUILDDIR}/.configure" ]] || [[ ${force_rebuild} == 'yes' ]]; then - cd "${MODULE_SRCDIR}" - pbuild::pre_configure - cd "${MODULE_BUILDDIR}" - pbuild::configure - touch "${MODULE_BUILDDIR}/.configure" - fi - [[ "${target}" == "configure" ]] && return 0 - - if [[ ! -e "${MODULE_BUILDDIR}/.compile" ]] || [[ ${force_rebuild} == 'yes' ]]; then - cd "${MODULE_BUILDDIR}" - pbuild::build - touch "${MODULE_BUILDDIR}/.compile" - fi - [[ "${target}" == "compile" ]] && return 0 - - if [[ ! -e "${MODULE_BUILDDIR}/.install" ]] || [[ ${force_rebuild} == 'yes' ]]; then - cd "${MODULE_BUILDDIR}" - pbuild::install - pbuild::post_install - if typeset -F pbuild::post_install_${OS} 1>/dev/null 2>&1; then - pbuild::post_install_${OS} "$@" - fi - pbuild::install_doc - post_install - if [[ ${bootstrap} == 'no' ]]; then - write_runtime_dependencies - write_build_dependencies - fi - touch "${MODULE_BUILDDIR}/.install" - fi - [[ "${target}" == "install" ]] && return 0 - - [[ ${enable_cleanup_build} == yes ]] && pbuild::cleanup_build - [[ ${enable_cleanup_src} == yes ]] && pbuild::cleanup_src - - else - echo "Not rebuilding $P/$V ..." - fi - if [[ ${bootstrap} == 'no' ]]; then - if [[ -d "${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}" ]]; then - set_legacy_link - fi - set_link - install_modulefile - fi - return 0 -} - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/libpmodules.bash b/Bootstrap/Pmodules/libpmodules.bash deleted file mode 100644 index b1b6f2a..0000000 --- a/Bootstrap/Pmodules/libpmodules.bash +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -if [[ -z ${bindir} ]]; then - local bindir=$(dirname "${BASH_SOURCE}") - bindir=$(cd "${bindir}"/.. && pwd)"/bin" -fi - -pmodules::get_options() { - "${bindir}/getopt" "$@" -} - -pmodules::check_env_vars() { - [[ -n "${PMODULES_ROOT}" ]] && - [[ -n "${PMODULES_CONFIG_DIR}" ]] && - [[ -n "${PMODULES_TEMPLATES_DIR}" ]] && - [[ -n "${PMODULES_HOME}" ]] && - [[ -n "${PMODULES_VERSION}" ]] || std::die 1 " -Error: the module environment you are going to use as source has not been -initialized properly!" -} - -pmodules::check_directories() { - local -r src_prefix="$1" - - [[ -d "${src_prefix}" ]] && - [[ -d "${src_prefix}/${PMODULES_CONFIG_DIR}" ]] && - [[ -d "${src_prefix}/Tools/Pmodules/${PMODULES_VERSION}" ]] || std::die 1 " -Error: the module environment '${src_prefix}' has not been initialized properly!" -} - -pmodules::check_env() { - pmodules::check_env_vars - pmodules::check_directories "${PMODULES_ROOT}" -} - - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/libstd.bash b/Bootstrap/Pmodules/libstd.bash deleted file mode 100644 index 3f142bb..0000000 --- a/Bootstrap/Pmodules/libstd.bash +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/bash - -# -# logging/message functions -# -std::log() { - local -ri fd=$1 - local -r fmt="$2\n" - shift 2 - printf -- "$fmt" "$@" 1>&$fd -} - -std::info() { - std::log 2 "$1" "${@:2}" -} - -std::error() { - std::log 2 "$1" "${@:2}" -} - -std::debug() { - [[ ${PMODULES_DEBUG} ]] || return 0 - std::log 2 "$@" -} - -std::die() { - local -ri ec=$1 - shift - if [[ -n $@ ]]; then - local -r fmt=$1 - shift - std::log 2 "$fmt" "$@" - fi - exit $ec -} - -# -# get answer to yes/no question -# -# $1: prompt -# -std::get_YN_answer() { - local -r prompt="$1" - local ans - read -p "${prompt}" ans - case ${ans} in - y|Y ) - return 0;; - * ) - return 1;; - esac -} - -# -# return normalized abolute pathname -# $1: filename -std::get_abspath() { - local -r fname=$1 - [[ -r "${fname}" ]] || return 1 - if [[ -d ${fname} ]]; then - echo $(cd "${fname}" && pwd) - else - local -r dname=$(dirname "${fname}") - echo $(cd "${dname}" && pwd)/$(basename "${fname}") - fi -} - -std::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 -} - -std::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 -} - -std::remove_path() { - local -r P=$1 - local -r d=$2 - local new_path='' - local -r _P=( ${!P//:/ } ) - # loop over all entries in path - for entry in "${_P[@]}"; do - [[ "${entry}" != "${d}" ]] && new_path+=":${entry}" - done - # remove leading ':' - eval ${P}="${new_path:1}" -} - -# -# split file name -# -std::split_fname() { - local -r savedIFS="${IFS}" - IFS='/' - local std__split_fname_result__=( $(echo "${@: -1}") ) - IFS=${savedIFS} - eval $1=\(\"\${std__split_fname_result__[@]}\"\) - if (( $# >= 3 )); then - eval $2=${#std__split_fname_result__[@]} - fi -} - -std::read_versions() { - local -r fname="$1" - local varname='' - while read _name _version; do - [[ -z ${_name} ]] && continue - [[ -z ${_version} ]] && continue - [[ "${_name:0:1}" == '#' ]] && continue - var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION - # don't set version, if already set - if [[ -z ${!var_name} ]]; then - eval ${var_name}="${_version}" - fi - done < "${fname}" -} - - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/modbuild b/Bootstrap/Pmodules/modbuild deleted file mode 100755 index a8db72d..0000000 --- a/Bootstrap/Pmodules/modbuild +++ /dev/null @@ -1,350 +0,0 @@ -#!/bin/bash - -#set -x - -# The directory where the programm is installed will be added to PATH and -# to the search path of BASH libraries. -declare -r mydir=$(dirname "$0") - - -declare -r libpbuild='libpbuild.bash' -declare -r libstd='libstd.bash' -declare -r pmodule_environment='environment.bash' -declare -ra bash_libpath=("${mydir}" "${mydir}/../lib") - - -############################################################################## -# -# set an error handler. If a function _exit() exists, it will be called -# with the passed exit code. -# -# $1 exit code -# -set -o errexit - -_exit() { - : -} - -error_handler() { - local -i ec=$? - - _exit ${ec} - exit ${ec} -} - -trap "error_handler" ERR - -# disable auto-echo feature of 'cd' -unset CDPATH - -############################################################################## -# -usage() { - std::error " -Usage: $0 [OPTIONS..] [BUILD_BLOCK] [VERSION] - -VERSION - Version of module to compile. - --? | -h | --help - Print usage - --v | --verbose ) - Verbose output - --j N | --jobs=N - Run N parallel make jobs - --f | --force-rebuild - Force rebuild of module. - ---dry-run - Dry run. - ---enable-cleanup-build - Cleanup files in the build directory (default). - ---enable-cleanup-src - Cleanup files in the source directory. - ---disable-cleanup - Keep files in build and source directory - ---disable-cleanup-build - Keep files in build directory. - ---disable-cleanup-src - Keep files in source directory (default). - ---with=P/V - Preload module P with version V. To preload multiple modules, - use this option per module. Nete that order may matter. - ---release=stable|unstable|deprecated - ---prep - Unpack sources only. - ---configure - Unpack sources and configure build. - ---compile - Unpack sources, configure build and compile software - ---install - Unpack sources, configure build, compile software and install. - ---all - Do everything, this step includes cleanup files and setting - the symbolic link to the modulefile. -" - exit 1 -} - -# setup PATH -PATH='/usr/bin:/bin:/usr/sbin:/sbin' - -declare -r OS=$(uname -s) -if [[ "${OS}" == "Darwin" ]]; then - # :FIXME: why do we need this? - [[ -d "/opt/X11/bin" ]] && PATH+=':/opt/X11/bin' -fi - -PATH+="${mydir}" - - -# -# We need GNU versions of the following utilities. This code works -# well on Linux and Mac OS X with MacPorts. -# :FIXME: implement a smarter, portable solution. -# -shopt -s expand_aliases -unalias -a - -__path=$(which gdate 2>/dev/null || : ) -if [[ $__path ]]; then - alias date=$__path -else - alias date=$(which date 2>/dev/null) -fi - -__path=$(which ginstall 2>/dev/null || : ) -if [[ $__path ]]; then - alias install=$__path -else - alias install=$(which install 2>/dev/null) -fi - -__path=$(which greadlink 2>/dev/null || : ) -if [[ $__path ]]; then - alias readlink=$__path -else - alias readlink=$(which readlink 2>/dev/null) -fi - -__path=$(which gsed 2>/dev/null || : ) -if [[ $__path ]]; then - alias sed=$__path -else - alias sed=$(which sed 2>/dev/null) -fi - - -declare ok=1 - -############################################################################## -# source BASH library with standard functions -for dir in "${bash_libpath[@]}"; do - if [[ -r ${dir}/${libstd} ]]; then - source "${dir}/${libstd}" - ok=0 - break - fi -done -if (( ok != 0 )); then - echo "Oops: required BASH library '${libstd}' not found" 1>&2 - exit 1 -fi - -############################################################################## -# -# parse arguments -# -debug_on='no' -force_rebuild='no' -dry_run='no' -enable_cleanup_build='yes' -enable_cleanup_src='no' -target='all' -module_release='' - -# array collecting all modules specified on the command line via '--with=module' -with_modules=() - -# save arguments for building dependencies -declare -rx ARGS="$@" - -# -while (( $# > 0 )); do - case $1 in - -j ) - JOBS=$2 - shift - ;; - --jobs=[0-9]* ) - JOBS=${1/--jobs=} - ;; - -v | --verbose | --debug ) - debug_on='yes' - ;; - -f | --force-rebuild ) - force_rebuild='yes' - ;; - -\? | -h | --help ) - usage - ;; - --disable-cleanup ) - enable_cleanup_build='no' - enable_cleanup_src='no' - ;; - --enable-cleanup-build ) - enable_cleanup_build='yes' - ;; - --disable-cleanup-build ) - enable_cleanup_build='no' - ;; - --enable-cleanup-src ) - enable_cleanup_src='yes' - ;; - --disable-cleanup-src ) - enable_cleanup_src='no' - ;; - --dry-run ) - dry_run='yes' - ;; - --release=* ) - module_release=${1/--release=} - ;; - --with=*/* ) - with_modules+=( ${1/--with=} ) - ;; - --prep | --configure | --compile | --install | --all ) - target=$1 - ;; - [0-9]* ) - V=$1 - ;; - * ) - declare -rx BUILD_BLOCK=$(std::get_abspath "$1") - declare -rx BUILD_BLOCK_DIR=$(dirname "${BUILD_BLOCK}") - ;; - esac - shift -done - -if [[ ${debug_on} == yes ]]; then - trap 'echo "$BASH_COMMAND"' DEBUG -fi - -[[ -n ${BUILD_BLOCK} ]] || std::die 1 "No build-block specified!" -[[ -r ${BUILD_BLOCK} ]] || std::die 1 "${BUILD_BLOCK}: no such file!" - - - -# source Pmodule environment configuration -if [[ -r ${BUILD_BLOCK_DIR}/../config/${pmodule_environment} ]]; then - # we are bootstrapping - source "${BUILD_BLOCK_DIR}/../config/${pmodule_environment}" - declare -rx BUILD_BASEDIR=$(std::get_abspath "${BUILD_BLOCK_DIR}/..") - bootstrap='yes' - -elif [[ -n ${PMODULES_ROOT} ]] && [[ -n ${PMODULES_CONFIG_DIR} ]] && \ - [[ -r ${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/${pmodule_environment} ]]; then - source ${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/${pmodule_environment} - declare -rx BUILD_BASEDIR=$(std::get_abspath "${BUILD_BLOCK_DIR}/../../..") - bootstrap='no' - -else - std::die 3 "Build environment not setup properbly!" -fi - -declare -xr BUILD_CONFIGDIR="${BUILD_BASEDIR}/config" -declare -xr BUILD_SCRIPTSDIR="${BUILD_BASEDIR}/scripts" -declare -xr BUILD_TMPDIR="${BUILD_BASEDIR}/tmp" -declare -xr BUILD_DOWNLOADSDIR="${BUILD_BASEDIR}/Downloads" -declare -xr BUILD_VERSIONSFILE="${BUILD_CONFIGDIR}/versions.conf" - - -# source BASH library with standard functions -((ok=1)) -for dir in "${bash_libpath[@]}"; do - if [[ -r ${dir}/${libpbuild} ]]; then - source "${dir}/${libpbuild}" - ok=0 - break - fi -done -(( ok == 0 )) || std::die 3 "Oops: required BASH library '${libpbuild}' not found" - -# Unset all PATH's and FLAGS's which might be used by a compiler. -# This includes C_INCLUDE_PATH, CFLAGS etc. -pbuild::cleanup_env - -# load all modules passed with the '--with' argument -if [[ ${bootstrap} == no ]]; then - # we aren't bootstraping - if [[ -r "${BUILD_BLOCK_DIR}/with_modules-$V" ]]; then - with_modules+=( $(cat "${BUILD_BLOCK_DIR}/with_modules-$V") ) - elif [[ -r "${BUILD_BLOCK_DIR}/with_modules" ]]; then - with_modules+=( $(cat "${BUILD_BLOCK_DIR}/with_modules") ) - fi - - source "${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/profile.bash" - MODULECMD="${PMODULES_HOME}/bin/modulecmd" - [[ -x ${MODULECMD} ]] || std::die 1 "${MODULECMD}: no such executable" - module purge - module use unstable - # :FIXME: this is a hack!!! - module use Libraries - for m in "${with_modules[@]}"; do - if pbuild::module_is_available "$m"; then - echo "Loading module: ${m}" - module load "${m}" - else - std::die 44 "$m: module not available!" - fi - done -else - # the module command is not yet available... - unset PMODULES_HOME - unset PMODULES_VERSION - std::read_versions "${BUILD_BASEDIR}/config/versions.conf" -fi - -P=$(basename $(dirname "${BUILD_BLOCK}")) -P=${P%.*} -_P=$(echo $P | tr [:lower:] [:upper:]) -_P=${_P//-/_} -_V=${_P}_VERSION - -# :FIXME: do we need this? Can we get rid of 'releases'? -if [[ -n ${PMODULES_DEFINED_RELEASES} ]]; then - declare -r releases="${PMODULES_DEFINED_RELEASES}" -else - # set defaults - declare -r releases=":unstable:stable:deprecated:" -fi - -[[ -n ${module_release} ]] && pbuild::set_release "${module_release}" - -# -# run build -# -source "${BUILD_BLOCK}" - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/modmanage b/Bootstrap/Pmodules/modmanage deleted file mode 100644 index 3f0ed89..0000000 --- a/Bootstrap/Pmodules/modmanage +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh --noprofile - -unset BASH_ENV - -declare -r bindir=$( cd $(dirname $0) && pwd -P ) -"${bindir}/bash" --noprofile --norc "${bindir}/../libexec/modmanage.bash" "$@" diff --git a/Bootstrap/Pmodules/modmanage.bash.in b/Bootstrap/Pmodules/modmanage.bash.in deleted file mode 100755 index aa79385..0000000 --- a/Bootstrap/Pmodules/modmanage.bash.in +++ /dev/null @@ -1,785 +0,0 @@ -#!@PMODULES_HOME@/bin/bash - -# we have to unset CDPATH, otherwise 'cd' prints the directoy! -unset CDPATH - -# used for some output only -declare -r CMD=$(basename "$0") - -declare -r mydir=$(cd $(dirname "$0") && pwd) -declare -r prefix=$(dirname "${mydir}") -declare -r bindir="${prefix}/bin" -declare -r libdir="${prefix}/lib" -declare -r libexecdir="${prefix}/libexec" - -source "${libdir}/libstd.bash" -source "${libdir}/libpmodules.bash" - -PATH="${bindir}:${PATH}" - -_exit () { - std::die 1 "Interrupted..." -} - -_err () { - std::info "Oops: got an error in function '${FUNCNAME[1]}', line ${BASH_LINENO[0]}" - std::die 1 "Aborting ..." -} - -trap '_exit' INT TERM -trap '_err' ERR - - -# make sure that everything is used from this version -declare PMODULES_VERSION='@PMODULES_VERSION@' - -print_version() { - echo " -Pmodules @PMODULES_VERSION@ using Tcl Environment Modules @MODULES_VERSION@ -Copyright GNU GPL v2 -" 1>&2 -} - -usage() { - local -r prog=$(basename $0) - print_version - echo " -Usage: ${prog} [ switches ] [ subcommand ] [subcommand-args ] - -Switches: - --dry-run do nothing - --force force overwrite - -Available SubCommands and Args: - init [--src=] [--user=] - Initialize a new minimal Pmodule environment. - - install [--with=...] - Install matching modules - - sync [--delete] [--dst=] - Synchronize modules. -" -} - -declare force='no' -declare dry_run='no' -declare DRY='' -declare subcommand='' -declare sargs=() - -subcommand_help_init() { - echo " -init [--src=] [--user=] [--version=] - Initialize a new minimal Pmodule environment in directory - . The parameter must only be present if - ${prog} is executed as root. -" 1>&2 -} - -subcommand_help_install() { - echo " -install ... [--with=...] [--release=...] [--src=] - Install matching modules -" 1>&2 -} - -subcommand_help_sync() { - echo " -sync [--delete] [--dst=] - Synchronize environment modules and configuration files - from Pmodule environment to Pmodule environment - (default: currently active Pmodule environment). - Not yet implemented: - If --delete is given, unmarked modules present in - will be deleted. -" 1>&2 -} - -subcommand_help() { - if [[ $# == 0 ]]; then - usage - elif typeset -F subcommand_help_$1 > /dev/null 2>&1 ; then - # help for sub-command - subcommand_help_$1 - else - usage - fi -} - -# -# Derive the relative module installation path -# from the relative modulefile path -# -# $1: relative module file path -# -get_module_prefix() { - local -a comp=( ${1//\// } ) # split rel.path into components - local path="${comp[0]}" # result path - local -i i - for ((i=1; i<${#comp[@]}-1; i+=2)); do - path+="/${comp[$((-i-1))]}/${comp[$((-i))]}" - done - echo "${path}" -} - -# -# Derive the relative module release file path -# from the relative module file path -# -# $1: relative module file path -# -get_releasefile_name() { - echo "$(dirname "$1")/.release-$(basename "$1")" -} - -# -# Sync a module from one Pmodules environment to another: -# - sync module installation -# - sync modulefile -# - sync release file -# -# Note: -# We do not take care of files in $PMODULES_ROOT/$PMODULES_TEMPLATES_DIR. If -# the modulefile is a sym-link it is expected that the target exists. -# -# $1: relative modulefile path (something like: Tools/gnuplot/5.0.0) -# $2: source prefix of Pmodule environment -# $3: target prefix of Pmodule environment -# -sync_module() { - local -r rel_modulefile=$1 - local -r src_prefix=$2 - local -r target_prefix=$3 - - local -r rel_module_prefix=$( get_module_prefix "${rel_modulefile}" ) - local -r rel_releasefile=$( get_releasefile_name "${rel_modulefile}" ) - - # install/update module - if [[ ! -d "${target_prefix}/${rel_module_prefix}" ]] || [[ "${force}" == 'yes' ]]; then - $DRY mkdir -p "${target_prefix}/${rel_module_prefix}" || return $? - $DRY rsync --links --perms --recursive --delete \ - "${src_prefix}/${rel_module_prefix}/" \ - "${target_prefix}/${rel_module_prefix}/" 2>/dev/null || return $? - fi - local -r src_modulefile="${src_prefix}/${rel_modulefile}" - local -r src_releasefile="${src_prefix}/${rel_releasefile}" - local -r target_modulefile="${target_prefix}/${rel_modulefile}" - local -r target_releasefile="${target_prefix}/${rel_releasefile}" - - # create target directory for module- and release-file - if [[ -e "${src_modulefile}" ]] || [[ -e "${src_releasefile}" ]]; then - local dir=$( dirname "${target_modulefile}" ) - $DRY mkdir -p "${dir}" || return $? - fi - - # copy modulefile - if [[ -e "${src_modulefile}" ]]; then - $DRY rsync --links --perms --recursive \ - "${src_modulefile}" "${target_modulefile}" 2>/dev/null || return $? - fi - - # copy release-file - if [[ -e "${src_releasefile}" ]]; then - $DRY rsync --links --perms --recursive \ - "${src_releasefile}" "${target_releasefile}" 2>/dev/null|| return $? - fi - - # copy modulefile template - local -a rel_modulefile_splitted - std::split_fname rel_modulefile_splitted "${rel_modulefile}" - local -r module_group="${rel_modulefile_splitted[0]}" - local -r module_name="${rel_modulefile_splitted[-2]}" - - local -r template="${module_group}/${PMODULES_TEMPLATES_DIR}/${module_name}/" - local -r src_template="${src_prefix}/${template}" - local -r target_template="${target_prefix}/${template}" - if [[ -e "${src_template}" ]]; then - $DRY mkdir -p "${target_template}" - $DRY rsync --links --perms --recursive \ - "${src_template}" "${target_template}" 2>/dev/null|| return $? - fi -} - -# -# Sync the Pmodules configuration and templates -# -# $1: source prefix of Pmodule environment -# $2: target prefix of Pmodule environment -# -sync_config() { - src="$1/${PMODULES_CONFIG_DIR}/" - dst="$2/${PMODULES_CONFIG_DIR}/" - $DRY rsync --recursive --links --perms --delete \ - "${src}" "${dst}" 2>/dev/null || return $? - sed -i.bak "s/PMODULES_VERSION=\(.*\)/PMODULES_VERSION=${PMODULES_VERSION}/" "${dst}/environment.bash" - echo -} - -# -# Delete a module -# -# $1: relative modulefile path -# $2: target prefix of Pmodule environment -# -delete_module() { - echo "Not implemented yet!" -} - -subcommand_init() { - local src='' - local target_prefixes=() - local user='' - local opts='' - opts=$(pmodules::get_options -o h -l src: -l user: -l help -l version: -- "$@") - if [[ $? != 0 ]]; then - subcommand_help_init - exit 1 - fi - eval set -- "${opts}" - while (($# > 0)); do - case $1 in - --src ) - src=$2 - shift - ;; - --user ) - user=$2 - shift - ;; - --version ) - PMODULES_VERSION=$2 - shift - ;; - -- ) - : - ;; - -* | -h | --help ) - echo "$1: illegal option" 1>&2 - subcommand_help_init - exit 1 - ;; - * ) - target_prefixes+=( "$1" ) - ;; - esac - shift - done - (( ${#target_prefixes[@]} != 0 )) || \ - std::die 1 "Error: no target directory specified!" - - # if source directory is not passed as argument, derive it from script name - if [[ -z "${src}" ]]; then - src=$(cd "${bindir}/../../../.." && pwd) - fi - [[ -d "${src}" ]] || \ - std::die 1 "Error: ${src}: source directory does not exist!" - [[ -r "${src}/config/profile.bash" ]] || \ - std::die 1 "Error: ${src}: shell profile does not exist or is not readable!" - source "${src}/config/profile.bash" - - local -i euid=$(id -u) - if (( euid == 0 )); then - [[ -n "${user}" ]] || \ - std::die 1 "Error: --user parameter is required!" - id -u "${user}" > /dev/null 2>&1 || \ - std::die 1 "Error: Unable to retrieve user id of user '${user}'" - else - [[ -z "${user}" ]] || \ - std::die 1 "Error: --user option is only allowed if running as root!" - fi - - pmodules::check_env || \ - std::die 1 "Giving up..." - - echo " -Attempting to create a minimal module environment from the -environment at '${PMODULES_ROOT}' -" - - init_pmodules_environment() { - local -r src_prefix="${PMODULES_ROOT}" - local -r target_prefix=$1 - local src='' - local dst='' - echo "Initializing target directory '${target_prefix}' ..." - echo - if [[ -d "${target_prefix}" ]] && [[ ${force} == no ]]; then - echo "Warning: ${target_prefix} already exists." - std::get_YN_answer "Do you really want to re-run the initialization? (y/N) " || \ - std::die 1 "Abort ..." - fi - force='yes' - echo "Creating target directory '${target_prefix}'..." - $DRY mkdir -p "${target_prefix}" || \ - std::die 1 "Error: make directory failed!" - echo - - echo "Syncing configuration ..." - sync_config "${PMODULES_ROOT}" \ - "${target_prefix}" || \ - std::die 1 "Error: configuration synchronization failed!" - - echo "Syncing Pmodules ${PMODULES_VERSION} from '${src_prefix}' to '${target_prefix}'..." - sync_module "Tools/Pmodules/${PMODULES_VERSION}" \ - "${src_prefix}" \ - "${target_prefix}" || \ - std::die 1 "Error: sync Pmodules failed!" - mkdir -p "${target_prefix}/Tools/${PMODULES_MODULEFILES_DIR}" - echo - - dst="${target_prefix}/${PMODULES_CONFIG_DIR}/environment.bash" - echo "Adding installation source '${src_prefix}' to '${dst}'..." - sed -i.bak '/PMODULES_INSTALL_SOURCE/d' "${dst}" - echo "declare -x PMODULES_INSTALL_SOURCE=\"${src_prefix}\"" >> "${dst}" - echo - - if [[ -n "${user}" ]]; then - echo "Changing user of new module environment to '${user}'..." - $DRY chown -R "${user}" "${target_prefix}" || \ - std::die 1 "Error: changing owner failed!" - echo - fi - echo "New minimal module environment created at '${target_prefix}'." - echo "To use this environment, execute" - echo " sudo ln -fs ${target_prefix} /opt/psi" - echo " source /opt/psi/${PMODULES_CONFIG_DIR}/profile.bash" - } - - umask 022 - for target_prefix in "${target_prefixes[@]}"; do - init_pmodules_environment "${target_prefix}" - done - -} - -declare -a Groups=() -declare -A HierarchyDepths - -get_groups () { - local -r root="$1" - { - cd "${root}" - # for some unknown reason [A-Z]* doesn't work on (some?) SL6 systems - for f in [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*; do - [[ -d ${f}/${PMODULES_MODULEFILES_DIR} ]] || continue - Groups+=( $f ) - done - }; -} - -# -# $1: root of modulefile hierarchy -get_hierarchy_depth () { - local -r root="$1" - local -a modulefiles_dir - std::split_fname modulefiles_dir "${PMODULES_MODULEFILES_DIR}" - local -ir off=$(( ${#modulefiles_dir[@]} + 3 )) - { - cd "${root}" - local group - for group in "${Groups[@]}"; do - local fname=$(find "${group}/${PMODULES_MODULEFILES_DIR}" \ - -depth \( -type f -o -type l \) -print -quit) - [[ -n ${fname} ]] || continue - #local -a tmp2=( ${fname//\// } ) - local -a tmp - std::split_fname tmp "${fname}" - (( HierarchyDepths[$group]=${#tmp[@]}-off )) - done - }; -} - -subcommand_install() { - local opts='' - local -a with=() - local -a releases=() - local -a module_pattern=() - local src_prefix="${PMODULES_INSTALL_SOURCE}" - local -r target_prefix="${PMODULES_ROOT}" - local modulefile='' - local -A modules_to_install - local -A dependencies_to_install - local -A map_to_family - local -a initial_modulepath=() - - # - # Resolve dependencies to given module - # - # $1: modulefile relativ to src prefix. Something like: - # MPI/modulefiles/gcc/4.9.2/openmpi/1.8.4/hdf5/1.8.14 - # - # Notes: - # The variables - # initial_modulepath - # modules_to_install - # map_to_family - # from the calling function are used! - # - resolve_dependencies_of_module () { - local -r modulefile=$1 - local -a modulepath=( "${initial_modulepath[@]}" ) - - # compute filename with dependencies of given module - local -i i=0 n=0 - std::split_fname items n "${modulefile}" - local fname_dependencies="${src_prefix}/${items[0]}" - for (( i = n-2; i >= 2; i-=2 )); do - fname_dependencies+="/${items[$i]}/${items[i+1]}" - done - fname_dependencies+='/.dependencies' - [[ -r ${fname_dependencies} ]] || return 0 - - # loop over all dependecies - local dep - while read dep; do - # skip empty lines - # :FIXME: skip comments?! - [[ -z ${dep} ]] && continue - - # search for module with current modulepath and remember - local modulename=$(find "${modulepath[@]}" -path "*/${dep}" 2>/dev/null | head -n 1 ) - [[ -n ${modulename} ]] || \ - std::die 3 "Oops: required module '${dep}' not found!" - modulename=${modulename/${src_prefix}\/} - dependencies_to_install[${modulename}]='.' - resolve_dependencies_of_module "${modulename}" - # append new node in hierarchy to modulepath - if [[ -n ${map_to_family[${dep}]} ]]; then - local path="${src_prefix}/${map_to_family[${dep}]}/${PMODULES_MODULEFILES_DIR}/" - path+="${modulename/*\/${PMODULES_MODULEFILES_DIR}\/}" - modulepath+=( "${path}" ) - fi - done < "${fname_dependencies}" - } - - print_modules_to_install() { - local modulefile - std::info "The following modules will be installed/updated:" - for modulefile in "${!modules_to_install[@]}"; do - if [[ -e "${target_prefix}/${modulefile}" ]]; then - std::info " Updating: ${modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }" - else - std::info " Installing: ${modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }" - fi - done 2>&1 | sort - if (( ${#dependencies_to_install[@]} > 0 )); then - std::info "\nThe following dependencies will be installed/updated:" - for modulefile in "${!dependencies_to_install[@]}"; do - if [[ -e "${target_prefix}/${modulefile}" ]]; then - std::info " Updating: ${modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }" - else - std::info " Installing: ${modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }" - fi - done 2>&1 | sort - fi - std::info "" - std::get_YN_answer "Do you want to continue? [n] " || \ - std::die 1 "Aborting..." - std::info "" - } - - opts=$(pmodules::get_options -o hf -l dry-run -l force -l with: -l release: -l help -l src: -- "$@") - if [[ $? != 0 ]]; then - subcommand_help_install - exit 1 - fi - eval set -- "${opts}" - while (($# > 0)); do - case $1 in - --dry-run ) - DRY='echo' - ;; - --force | -f ) - force='yes' - ;; - --release ) - releases+=( "$2" ) - shift - ;; - --src ) - src_prefix="$2" - shift - ;; - --with ) - with+=( "$2" ) - shift - ;; - -- ) - : - ;; - -h | --help ) - subcommand_help_install - exit 1 - ;; - -* ) - echo "$1: illegal option" 1>&2 - subcommand_help_init - exit 1 - ;; - * ) - module_pattern+=( "$1" ) - ;; - esac - shift - done - - [[ -n ${src_prefix} ]] \ - || std::die 3 "Oops: no installation source given." - [[ -d ${src_prefix} ]] \ - || std::die 3 "Oops: '${src_prefix}' is not a valid installation source." - - # scan available groups and their depth - get_groups "${src_prefix}" - get_hierarchy_depth "${src_prefix}" - - # set initial modulepath - local group - for group in "${!HierarchyDepths[@]}"; do - if (( ${HierarchyDepths[${group}]} == 0 )); then - initial_modulepath+=( "${src_prefix}/${group}/${PMODULES_MODULEFILES_DIR}" ) - fi - done - - # - # create a mapping from module name to their family. - # Examples: - # gcc/5.2.0 -> Compiler - # openmpi/1.8.4 -> MPI - local _fname='' - while read _fname; do - local _family="${_fname%/${PMODULES_MODULEFILES_DIR}/*}" - local -a items - std::split_fname items "${_fname#*/${PMODULES_MODULEFILES_DIR}/}" - local -i n=${#items[*]} - # We are only interested in families adding something to - # the modulepath. - if (( n >= 4 )); then - local _key=$( IFS='/'; echo "${items[*]:$n-4:2}" ) - map_to_family[$_key]=${_family} - fi - done < <({ cd "${src_prefix}" && \ - find */"${PMODULES_MODULEFILES_DIR}" \ - \( -type l -o -type f \) \! -name ".*"; } 2>/dev/null ) - - # - # search for to be installed modules and their dependencies - # - local -i n=0 - while read modulefile; do - resolve_dependencies_of_module "${modulefile}" - modules_to_install["${modulefile}"]+='.' - let n+=1 - done < <(${PMODULES_HOME}/bin/modulecmd bash search \ - "${module_pattern[@]}" \ - "${with[@]/#/--with=}" \ - "${releases[@]/#/--release=}" \ - --no-header --print-modulefiles \ - --src="${src_prefix}" 2>&1 1>/dev/null) - (( n == 0 )) && \ - std::die 0 "No matching modules found ..." - print_modules_to_install - - # install ... - for modulefile in "${!modules_to_install[@]}" "${!dependencies_to_install[@]}"; do - if [[ -e "${target_prefix}/${modulefile}" ]]; then - std::info " Updating: ${modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }" - else - std::info " Installing: ${modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }" - fi - sync_module "${modulefile}" \ - "${src_prefix}" \ - "${target_prefix}" - done - std::info "\nDone!\n" -} - -# -# delete specified module(s) -# -subcommand_delete() { - : -} - -# -# remove modules which have been removed in our source -# -subcommand_cleanup() { - : -} - -subcommand_sync() { - local delete=false - local opts='' - local dst_prefix='' - local src_prefix='' - - opts=$(pmodules::get_options -o h -l dst: -l delete -l help -- "$@") - if [[ $? != 0 ]]; then - subcommand_help_sync - exit 1 - fi - eval set -- "${opts}" - while (($# > 0)); do - case $1 in - --dst ) - dst_prefix="$2" - shift - ;; - --delete ) - delete=true - ;; - -- ) - : - ;; - -* | -h | --help ) - echo "$1: illegal option" 1>&2 - subcommand_help_init - exit 1 - ;; - * ) - [[ -n "${src_prefix}" ]] && \ - std::die 1 "Error: Only one source is allowed!" - src_prefix="$1" - ;; - esac - shift - done - unset -v opts - - if [[ -z "${dst_prefix}" ]]; then - dst_prefix="${PMODULES_ROOT}" - fi - ( - PMODULES_ROOT="${dst_prefix}" pmodules::check_env || \ - std::die 1 "Error: invalid destination modules environment!" - ) || std::die 1 "Giving up..." - - : ${src_prefix:=${PMODULES_INSTALL_SOURCE}} - if [[ -z "${src_prefix}" ]]; then - std::die 1 "Error: no source module environment was specified!" - fi - ( - PMODULES_ROOT="${src_prefix}" pmodules::check_env || \ - std::die 1 "Error: invalid source modules environment!" - ) || std::die 1 "Giving up..." - [[ "$( cd "$src_prefix"; pwd -P )" == "$( cd "$dst_prefix"; pwd -P )" ]] && \ - std::die 1 "Error: source and destination are equal!" - local modbin=${PMODULES_HOME#"${PMODULES_ROOT}/"}/bin/modulecmd.tcl - local file_type_src=$( file -b "${src_prefix}/${modbin}" 2>&1 || echo err1 ) - local file_type_dst=$( file -b "${dst_prefix}/${modbin}" 2>&1 || echo err2 ) - [[ "${file_type_src}" == "${file_type_dst}" ]] || \ - std::die 1 "Error: The file signatures in the source and destination installation do not match!" - unset -v file_type_src file_type_dst - local dialog_script="${PMODULES_HOME}/bin/dialog.bash" - [[ -r "$dialog_script" ]] || \ - std::die 1 "Error: Unable to find dialog script of installation $dialog_script"; - - DIALOG_LIB=1 # use dialog script as a library - source "$dialog_script" # dialog functions - - # Redefine module_out to append modules to the selected_modules variable - local -a selected_modules - module_out() { - local -a args=(${modlist[$1]}) - local path="" - IFS=/ - [[ -n "${args[3]}" ]] && path="/${args[*]:3}" - unset IFS - selected_modules+=( "${args[2]}${path}/${args[0]}" ) - } - - module_picker "${dst_prefix}" "${src_prefix}" || { - # this calls module_out for each selected module, - #filling up the selected_modules array - echo "Abort!" - exit 1 - } - - local -a destination_modules=( $(cd "${dst_prefix}/${PMODULES_MODULEFILES_DIR}"; find -L . -type f | while read f; do n=${f##*/}; [[ "${n:0:1}" == "." ]] || echo ${f#./}; done) ) - - # redefine set difference, the version in dialog.bash only handles integers - set_difference() { # $1 \ $2 - local -a operand1=($1) - local -a operand2=($2) - local -A members - local elem - for elem in "${operand1[@]}"; do - members[$elem]=1 - done - for elem in "${operand2[@]}"; do - unset members[$elem] - done - echo ${!members[@]} - } - - if [[ "$delete" == "true" ]]; then - local -a modules_delete=( $(set_difference "${destination_modules[*]}" "${selected_modules[*]}") ) - for m in "${modules_delete[@]}"; do - echo "Deleting module $m ..." - delete_module "$m" "$dst_prefix" - done - unset modules_delete - fi - - local -a modules_copy=( $(set_difference "${selected_modules[*]}" "${destination_modules[*]}") ) - if [[ -n $modules_copy ]]; then - echo "Syncing configuration ..." - sync_config "$src_prefix" "$dst_prefix" || \ - std::die 1 "Error: syncing the configuration failed" - fi - for m in "${modules_copy[@]}"; do - echo "Copying module $m ..." - sync_module "$m" "$src_prefix" "$dst_prefix" || \ - std::die 1 "Error: syncing of module $m failed!" - done - unset modules_copy -} - -while (($# > 0)); do - case $1 in - -h | -H | -\? | --help | -help ) - usage - exit 1 - ;; - -V | --version ) - print_version - exit 1 - ;; - -f | --force ) - force='yes' - ;; - --dry-run ) - dry_run='yes' - DRY='echo' - ;; - -* ) - echo "$1: unknown switch.\n" 1>&2 - exit 1 - ;; - init|install|sync|help ) - subcommand="subcommand_$1" - shift - sargs=( $* ) - shift $# - ;; - * ) - echo "$1: unknown sub-command" 1>&2 - exit 1 - esac - shift || : -done - -if [[ -z ${subcommand} ]]; then - usage - exit 1 -fi -[[ -z "${PMODULES_ROOT}" ]] && \ - std::die 1 "Error: No current module environment is configured!" -$subcommand "${sargs[@]}" - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/modsync.bash b/Bootstrap/Pmodules/modsync.bash deleted file mode 100755 index ad9f148..0000000 --- a/Bootstrap/Pmodules/modsync.bash +++ /dev/null @@ -1,236 +0,0 @@ -#!/usr/bin/env bash - -declare -r DEFAULT_SRC="/afs/psi.ch/sys/psi.@sys" -declare -r DEFAULT_DST="/opt/psi.local" - -usage() { - echo " -$0 [--from=] [--to=] [--dryrun] [--delete] - --from source module installation (default: $DEFAULT_SRC) - - --to destination module installation (default: $DEFAULT_DST) - - --dryrun just tell what would be copied and deleted - - --delete as an additional task, delete modules that are present - at the destination but not at the source installation - (destination cleanup)" >&2 -} - -die() { - echo "$1" >&2 - exit 1 -} - -# check if directory $1 is a valid prefix -is_module_prefix() { - if [[ -d "$1" ]] && - [[ -d "$1/$PMODULES_CONFIG_DIR" ]] && - [[ -d "$1/$PMODULES_MODULEFILES_DIR" ]] - then - return 0 - fi - return 1 -} - -# set the source and destination module installations -get_options() { - local src_dir="$DEFAULT_SRC" - local dst_dir="$DEFAULT_DST" - local dryrun=false - local delete=false - local option - - while (($# > 0)); do - if [[ "${1#--from}" != "$1" ]]; then - option="${1#--from}" - option="${option#=}" - [[ -z "$option" ]] && { shift; option="$1"; } - src_dir="$option" - elif [[ "${1#--to}" != "$1" ]]; then - option="${1#--to}" - option="${option#=}" - [[ -z "$option" ]] && { shift; option="$1"; } - dst_dir="$option" - elif [[ -z "${1#--dryrun}" ]]; then - dryrun=true - elif [[ -z "${1#--delete}" ]]; then - delete=true - else - usage > /dev/fd/2 - std::die "Unknown option: $1" - fi - shift - done - - is_module_prefix "$src_dir" || { std::die "<$src_dir> is not a Pmodules installation"; } - is_module_prefix "$dst_dir" || { std::die "<$dst_dir> is not a Pmodules installation"; } - src_dir=$( cd "$src_dir"; pwd -P ) - dst_dir=$( cd "$dst_dir"; pwd -P ) - [[ "$src_dir" == "$dst_dir" ]] && { std::die "same source and destination installations"; } - local modbin=$( cd "$PMODULES_HOME"; pwd -P ) - local prefix=$( cd "$PMODULES_PREFIX"; pwd -P ) - modbin=${modbin#"$prefix/"}/bin/modulecmd - local -r file_type_src=$( file -b "$src_dir/$modbin" 2>&1 || echo err1 ) - local -r file_type_dst=$( file -b "$dst_dir/$modbin" 2>&1 || echo err2 ) - [[ ! "${file_type_src}" == "${file_type_dst}" ]] || { - std::die "The file signatures in the source and destination installation do not match!" - } - echo "$src_dir" "$dst_dir" "$dryrun" "$delete" -} - -# Derive the relative module installation path -# from the relative module file path -# $1 relative module file path -get_modpath() { - local -a comp=( ${1//\// } ) # split rel.path into components - local -a path # result path - local -i i - for ((i=0; i<${#comp[@]}; i++)); do - case $i in - 0) path=( ${comp[0]%.*} );; - *) path+=( "${comp[$((-i-1))]}/${comp[$((-i))]}" ); i+=1;; - esac - done - echo "${path[*]}" -} - -# Derive the relative module release file path -# from the relative module file path -# $1 relative module file path -get_release_path() { - echo "$(dirname "$1")/.release-$(basename "$1")" -} - -# $1 dryrun=(true|false) -# $2 relative module file path of destination module to be deleted -# $3 destination prefix -delete_module() { - if [[ "$1" != "false" ]]; then - echo "(dryrun) delete: $2 at $3" 1>&2 - return 0 - fi - local modpath=$( get_modpath "$2" ) - [[ -z "$modpath" ]] && { - std::die "Unable to retrieve module file and installation paths"; - } - echo "rm -v \"$3/$PMODULES_MODULEFILES_DIR/$2\"" - echo "rm -v \"$3/$PMODULES_MODULEFILES_DIR/$( get_release_path $2 )\"" - echo "rmdir -vp \"$( dirname "$3/$PMODULES_MODULEFILES_DIR/$2" )\"" - echo "rm -vrf \"$3/$modpath\"" - echo "rmdir -vp \"$( dirname "$3/$modpath" )\"" - echo "deleted: $2" 1>&2 -} - -# $1 dryrun=(true|false) -# $2 relative module file path of source module to be copied to the destination -# $3 source prefix -# $4 destination prefix -copy_module() { - if [[ "$1" != "false" ]]; then - echo "(dryrun) copy: $2 from $3 to $4" 1>&2 - return 0 - fi - local modpath=$( get_modpath "$2" ) - [[ -z "$modpath" ]] && { std::die "Unable to retrieve module file and installation paths"; } - install -d $( dirname "$3/$PMODULES_MODULEFILES_DIR/$2" ) - ( - cd $3 - rsync --links --perms --relative --verbose "$PMODULES_MODULEFILES_DIR/$2" "$4" - rsync --links --perms --relative --verbose "$PMODULES_MODULEFILES_DIR/$( get_release_path "$2" )" "$4" - rsync --recursive --links --perms --relative --verbose "$modpath" "$4" - ) - echo "copied: $2" 1>&2 -} - -# syncronize modules from source to -# destination module installations -# --from= default: /afs/psi.ch/sys/psi.@sys -# --to= default: /opt/psi.local -sync_modules() { - local -a options=( $(get_options "$@") ) - [[ -z "$options" ]] && exit 1 - local src_dir="${options[0]}" - local dst_dir="${options[1]}" - local dryrun="${options[2]}" - local delete="${options[3]}" - unset options - - local profile_script="$src_dir/$PMODULES_CONFIG_DIR/profile.bash" - [[ -r "$profile_script" ]] || { - std::die "Unable to find profile script of installation $profile_script"; - } - local search_script="$src_dir/Tools/Pmodules/${PMODULES_VERSION}/bin/modulecmd" - [[ -x "$search_script" ]] || { - std::die "Unable to find search script of installation $search_script"; - } - local dialog_script="$src_dir/Tools/Pmodules/${PMODULES_VERSION}/bin/dialog.bash" - [[ -r "$dialog_script" ]] || { - std::die "Unable to find dialog script of installation $dialog_script"; - } - - . "$profile_script" # set variables for the source installation - - DIALOG_LIB=1 # use dialog script as a library - . "$dialog_script" # dialog functions - - local -a selected_modules - - # Redefine module_out to append modules to the selected_modules variable - module_out() { - local -a args=(${modlist[$1]}) - local path="" - IFS=/ - [[ -n "${args[3]}" ]] && path="/${args[*]:3}" - unset IFS - selected_modules+=( "${args[2]}$path/${args[0]}" ) - } - - module_picker "$dst_dir" < <("$search_script" bash search --no-header -a 2>&1) - - local -a destination_modules=( $(cd "$dst_dir/$PMODULES_MODULEFILES_DIR"; find -L . -type f | while read f; do echo ${f#./}; done) ) - - # redefine set difference, the version in dialog.bash only handles integers - set_difference() { # $1 \ $2 - local -a operand1=($1) - local -a operand2=($2) - local -A members - local elem - for elem in "${operand1[@]}"; do - members[$elem]=1 - done - for elem in "${operand2[@]}"; do - unset members[$elem] - done - echo ${!members[@]} - } - - [[ "$delete" == "true" ]] && { - local -a modules_delete=( $(set_difference "${destination_modules[*]}" "${selected_modules[*]}") ) - for m in "${modules_delete[@]}"; do - delete_module "$dryrun" "$m" "$dst_dir" - done - unset modules_delete - } - - - local -a modules_copy=( $(set_difference "${selected_modules[*]}" "${destination_modules[*]}") ) - [[ -z $modules_copy ]] || { - if [[ "$dryrun" != "false" ]]; then - echo "(dryrun) update: $dst_dir/$PMODULES_CONFIG_DIR from $src_dir/$PMODULES_CONFIG_DIR" 1>&2 - else - ( - local -a extraoption="$( [[ "$delete" == "true" ]] && echo --delete )" - cd "$src_dir" - rsync --recursive --links --perms --relative $extraoption --verbose --exclude .git "$PMODULES_CONFIG_DIR" "$dst_dir" - echo "updated: $PMODULES_CONFIG_DIR from $src_dir" 1>&2 - ) - fi - for m in "${modules_copy[@]}"; do - copy_module "$dryrun" "$m" "$src_dir" "$dst_dir" - done - } - unset modules_copy -} - -sync_modules "$@" diff --git a/Bootstrap/Pmodules/modulecmd b/Bootstrap/Pmodules/modulecmd deleted file mode 100644 index 89ca1ab..0000000 --- a/Bootstrap/Pmodules/modulecmd +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh --noprofile - -unset BASH_ENV - -declare -r bindir=$( cd $(dirname $0) && pwd -P ) -"${bindir}/bash" --noprofile --norc "${bindir}/../libexec/modulecmd.bash" "$@" diff --git a/Bootstrap/Pmodules/modulecmd.bash.in b/Bootstrap/Pmodules/modulecmd.bash.in deleted file mode 100755 index 9672145..0000000 --- a/Bootstrap/Pmodules/modulecmd.bash.in +++ /dev/null @@ -1,1678 +0,0 @@ -#!@PMODULES_HOME@/bin/bash --noprofile -# - -#set -o nounset -# we have to unset CDPATH, otherwise 'cd' prints the directoy! -unset CDPATH - -# used for some output only -declare -r CMD='module' - -declare -r mydir=$(cd $(dirname "$0") && pwd) -declare -r prefix=$(dirname "${mydir}") -declare -r bindir="${prefix}/bin" -declare -r libdir="${prefix}/lib" -declare -r libexecdir="${prefix}/libexec" - -source "${libdir}/libstd.bash" -source "${libdir}/libpmodules.bash" - -PATH="${bindir}:${PATH}" - -declare -r version='@PMODULES_VERSION@' -declare -r modulecmd="${libexecdir}/modulecmd.tcl" - -declare -rx TCL_LIBRARY="${libdir}/tcl8.6" - -# required for pre 0.99.3 modulefiles -declare -rx PSI_LIBMODULES="${TCL_LIBRARY}/libmodules.tcl" - -declare verbosity_lvl=${PMODULES_VERBOSITY:-'verbose'} - -shopt -s nullglob -declare -a Groups='()' -declare -A HierarchyDepths='()' - -export_env() { - local s='' - if [[ "${shell}" == "bash" ]]; then - while (( $# > 0 )); do - echo -n "export $1=\"${!1}\";" - shift - done - return - elif [[ "${shell}" == "tcsh" ]]; then - while (( $# > 0 )); do - echo "setenv $1 ${!1}" - shift - done - return - fi -} - -save_env() { - local s='' - local tmp - while (( $# > 0 )); do - tmp="$( typeset -p $1 2> /dev/null)" - [[ -n "${tmp}" ]] && s+="${tmp};" - shift - done - declare -g PMODULES_ENV=$( "${PMODULES_HOME}/bin/base64" --wrap=0 <<< "$s" ) - export_env PMODULES_ENV -} - -trap 'save_env Groups HierarchyDepths UsedReleases PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES PMODULES_DEFAULT_RELEASES' EXIT - -print_version() { - echo " -Pmodules ${version} using Tcl Environment Modules @MODULES_VERSION@ -Copyright GNU GPL v2 -" 1>&2 -} - -usage() { - print_version - echo " -USAGE: - module [ switches ] [ subcommand ] [subcommand-args ] - -SWITCHES: - -h|-H|-?|--help this usage info - -V|--version modules version & configuration options - -SUBCOMMANDS: - + add|load [switches] modulefile [modulefile ...] - + rm|unload modulefile [modulefile ...] - + switch|swap [modulefile1] modulefile2 - + display|show modulefile [modulefile ...] - + avail [switches] [modulefile [modulefile ...]] - + search [switches] [args] - + use [switches] [dir|group|release ...] - + unuse dir|group|release [dir|group|release ...] - + refresh - + purge - + list [switches] - + clear - + help [modulefile|subcommand] - + whatis [modulefile [modulefile ...]] - + apropos|keyword string - + initadd modulefile [modulefile ...] - + initprepend modulefile [modulefile ...] - + initrm modulefile [modulefile ...] - + initswitch modulefile1 modulefile2 - + initlist - + initclear -" 1>&2 - std::die 1 -} - -subcommand_help_add() { - echo " -USAGE: - module add modulefile... - module load modulefile... - Load modulefile(s) into the shell environment. Loading a - 'group-head' will extend the MODULEPATH. E.g.: loading a - compiler makes additional modules like openmpi and libraries - compiled with this compiler available. -" 1>&2 - std::die 1 -} - -subcommand_help_load() { - subcommand_help_add -} - -subcommand_help_rm() { - echo " -USAGE: - module rm modulefile... - moudle unload modulefile... - Remove modulefile(s) from the shell environment. Removing - a 'group-head' will also unload all modules belonging to - this group. -" 1>&2 - std::die 1 -} - -subcommand_help_unload() { - subcommand_help_rm -} - -subcommand_help_switch() { - echo " -USAGE: - module switch [modulefile1] modulefile2 - module swap [modulefile1] modulefile2 - Switch loaded modulefile1 with modulefile2. If modulefile1 - is not specified, then it is assumed to be the currently - loaded module with the same root name as modulefile2. -" 1>&2 - std::die 1 -} - -subcommand_help_swap() { - subcommand_help_switch -} - -subcommand_help_display() { - echo " -USAGE: - module display modulefile... - module show modulefile... - Display information about one or more modulefiles. The - display sub-command will list the full path of the - modulefile(s) and all (or most) of the environment changes - the modulefile(s) will make if loaded. It will not display - any environment changes found within conditional statements. -" 1>&2 - std::die 1 -} - -subcommand_help_show() { - subcommand_help_display -} - -subcommand_help_apropos() { - echo " -USAGE: - module apropos string - module keyword string Seeks through the 'whatis' informations of all modulefiles for - the specified string. All module-whatis informations matching - the string will be displayed. - -" 1>&2 - std::die 1 -} - -subcommand_help_keyword() { - subcommand_help_apropos -} - - -subcommand_help_avail() { - echo " -USAGE: - module avail string - List all available modulefiles in the current MODULEPATH. If - an argument is given, then each directory in the MODULEPATH - is searched for modulefiles whose pathname match the argument. - - This command does *not* display all installed modules on the - system. Only *loadable* modules are listed. The list of - available modules may change either by loading other modules, - e.g. a compiler, or with the sub-command 'use'. -" 1>&2 - std::die 1 -} - -subcommand_help_search() { - echo " -USAGE: - module search [switches] string... - Search installed modules. If an argument is given, search - for modules whose name match the argument. - -SWITCHES: - --no-header - Suppress output of a header. - - --release=RELEASE - Search for modules within this release. You can specify this - switch multiple times. Without this switch, the used releases - will be searched. - - -a|--all-releases - Search within all releases. - - --with=STRING - Search for modules compiled with modules matching string. The - command - - module search --with=gcc/4.8.3 - - lists all modules in the hierarchy compiled with gcc 4.8.3. -" 1>&2 - std::die 1 -} - -subcommand_help_use() { - echo " -USAGE: - module use [-a|--append|-p|--prepend] [directory|group|release...] - Without arguments this sub-command displays information about - the module search path, used families and releases. You can - use this sub-command to get a list of available families and - releases. - - With a directory as argument, this directory will either be - prepended or appended to the module search path. The default - is to prepend the directory. - - With a group as argument, the modules in this group will - be made available. - - With a release as argument, this modules with this release - will be made available. - -SWITCHES: - -a | --append -p | --prepend ) - Append/prepend agrument to module search path or list of to be - searched releases. -" 1>&2 - std::die 1 -} - -subcommand_help_unuse() { - echo " -unuse directory|group|release... - Remove the given directory, group or release from the search - path. -" 1>&2 - std::die 1 -} -subcommand_help_update() { - echo " -USAGE: - module update - Attempt to reload all loaded modulefiles. -" 1>&2 - std::die 1 -} - -subcommand_help_refresh() { - echo " -USAGE: - module refresh - Force a refresh of all non-persistent components of currently - loaded modules. This should be used on derived shells where - aliases need to be reinitialized but the environment variables - have already been set by the currently loaded modules. -" 1>&2 - std::die 1 -} - -subcommand_help_purge() { - echo " -USAGE: - module purge - Unload all loaded modulefiles. -" 1>&2 - std::die 1 -} - -subcommand_help_list() { - echo " -USAGE: - module list - List loaded modules. -" 1>&2 - std::die 1 -} - -subcommand_help_clear() { - echo " -USAGE: - module clear - Force the Modules package to believe that no modules are - currently loaded. -" 1>&2 - std::die 1 -} - -subcommand_help_whatis() { - echo " -USAGE: - module whatis [modulefile...] - Display the information set up by the module-whatis commands - inside the specified modulefile(s). If no modulefile is - specified, all 'whatis' lines will be shown. -" 1>&2 - std::die 1 -} - -subcommand_help_initadd() { - echo " -USAGE: - module initadd modulefile... - Add modulefile(s) to the shell's initialization file in the - user's home directory. The startup files checked (in order) - are: - - csh - .modules, .cshrc(.ext), .csh_variables, and - .login(.ext) - tcsh - .modules, .tcshrc, .cshrc(.ext), .csh_variables, - and .login(.ext) - (k)sh - .modules, .profile(.ext), and .kshenv(.ext) - bash - .modules, .bash_profile, .bash_login, - .profile(.ext) and .bashrc(.ext) - zsh - .modules, .zcshrc(.ext), .zshenv(.ext), and - .zlogin(.ext) - - If a 'module load' line is found in any of these files, the - modulefile(s) is(are) appended to any existing list of - modulefiles. The 'module load' line must be located in at - least one of the files listed above for any of the 'init' - sub-commands to work properly. If the 'module load' line - line is found in multiple shell initialization files, all - of the lines are changed. -" 1>&2 - std::die 1 -} - -subcommand_help_initprepend() { - echo " -USAGE: - module initprepend modulefile... - Does the same as initadd but prepends the given modules to - the beginning of the list. -" 1>&2 - std::die 1 -} - -subcommand_help_initrm() { - echo " -USAGE: - module initrm modulefile... - Remove modulefile(s) from the shell's initialization files. -" 1>&2 - std::die 1 -} - -subcommand_help_initswitch() { - echo " -USAGE: - module initswitch modulefile1 modulefile2 - Switch modulefile1 with modulefile2 in the shell's initialization files. -" 1>&2 - std::die 1 -} - -subcommand_help_initlist() { - echo " -USAGE: - module initlist - List all of the modulefiles loaded from the shell's initialization file. -" 1>&2 - std::die 1 -} - -subcommand_help_initclear() { - echo " -USAGE: - module initclear - Clear all of the modulefiles from the shell's initialization files. -" 1>&2 - std::die 1 -} - -# -# get release of module -# Note: -# - the release of a modulefile outside ${PMODULES_ROOT} is 'stable' -# - the release of a modulefile inside ${PMODULES_ROOT} without a -# coresponding release file is 'unstable' -# -# Args: -# $1: absolute modulefile name -# -get_release() { - local -r modulefile=$1 - - # is modulefile outside ${PMODULES_ROOT}? - if [[ ! ${modulefile} =~ ${PMODULES_ROOT} ]]; then - echo 'stable' - return 0 - fi - - # we are inside ${PMODULES_ROOT} - local -r releasefile="${modulefile%/*}/.release-${modulefile##*/}" - if [[ -r ${releasefile} ]]; then - # read releasefile, remove empty lines, spaces etc - local -r data=$( < "${releasefile}" ) - echo ${data} - else - echo 'unstable' - fi - return 0 -} - -: ${PMODULES_DEFINED_RELEASES:=':unstable:stable:deprecated:'} - -is_release() { - [[ ${PMODULES_DEFINED_RELEASES} =~ :$1: ]] -} - -is_used_release() { - [[ ":${UsedReleases}:" =~ :$1: ]] -} - -declare used_groups=":${PMODULES_USED_GROUPS}:" - -is_group () { - [[ -n ${group} ]] && [[ -n ${HierarchyDepths[${group}]} ]] -} - -is_used_group() { - [[ ${used_groups} =~ :$1: ]] -} - -module_is_loaded() { - [[ :${LOADEDMODULES}: =~ :$1: ]] -} - -# -# check shebang -# $1: file name to test -is_modulefile() { - local -r fname=$1 - local shebang - [[ -r ${fname} ]] || return 1 - read -n 11 shebang < "${fname}" - [[ "${shebang}" == "#%Module1.0" ]] -} - -subcommand_generic0() { - local -r subcommand=$1 - shift - local opts='' - opts=$(pmodules::get_options -- '' "$@") || subcommand_help_${subcommand} - eval set -- "${opts}" - while (( $# > 0 )); do - case $1 in - -- ) - shift - ;; - * ) - std::die 3 "${CMD} ${subcommand}: illegal argument -- $1" - ;; - esac - done - "${modulecmd}" "${shell}" "${subcommand}" -} - -subcommand_generic1() { - local -r subcommand=$1 - shift - local opts='' - opts=$(pmodules::get_options -- '' "$@") || subcommand_help_${subcommand} - eval set -- "${opts}" - local args=() - while (( $# > 0 )); do - case $1 in - -- ) - ;; - * ) - if (( ${#args[@]} == 0 )); then - args+=( "$1" ) - else - std::die 3 "${CMD} ${subcommand}: only one argument allowed" - fi - ;; - esac - shift - done - if (( ${#args[@]} == 0 )); then - std::die 3 "${CMD} ${subcommand}: missing argument" - fi - "${modulecmd}" "${shell}" "${subcommand}" "${args[@]}" -} - -subcommand_generic1plus() { - local -r subcommand=$1 - shift - local opts='' - opts=$(pmodules::get_options -- '' "$@") || subcommand_help_${subcommand} - eval set -- "${opts}" - local args=() - while (( $# > 0 )); do - case $1 in - -- ) - ;; - * ) - args+=( "$1" ) - ;; - esac - shift - done - if (( ${#args[@]} == 0 )); then - std::die 3 "${CMD} ${subcommand}: missing argument" - fi - "${modulecmd}" "${shell}" "${subcommand}" "${args[@]}" -} - -subcommand_generic1or2() { - local -r subcommand=$1 - shift - local opts='' - opts=$(pmodules::get_options -- '' "$@") || subcommand_help_${subcommand} - eval set -- "${opts}" - local args=() - while (( $# > 0 )); do - case $1 in - -- ) - ;; - * ) - if (( ${#args[@]} > 2 )); then - std::die 3 "${CMD} ${subcommand}: only one or two arguments are allowed" - fi - args+=( "$1" ) - ;; - esac - shift - done - if (( ${#args[@]} == 0 )); then - std::die 3 "${CMD} ${subcommand}: missing argument" - fi - "${modulecmd}" "${shell}" "${subcommand}" "${args[@]}" -} - -# -# load [-fsvw] -# -# $1: module to load -# -subcommand_load() { - local release='undef' - local moduledir='' - local m='' - - local saved_IFS=${IFS}; - IFS=':' - local -a modulepath=(${MODULEPATH}) - IFS=${saved_IFS} - local -r saved_MODULEPATH=${MODULEPATH} - local -a saved_modulepath=${modulepath} - local -r saved_UsedReleases=${UsedReleases} - - # - # Test whether a given module can be loaded according to the - # accepted releases. - # - # Notes: - # The variable 'release' in function 'subcommand_load()' will be set. - # The release of a modulefile outsite our hierarchy is 'stable'. - # - # $1: absolute name of modulefile - # - is_loadable() { - release=$( get_release "$1" ) - [[ :${UsedReleases}: =~ ${release} ]] && return 0 - return 1 - } - - # - # Test whether a given module is available. - # Possible cases: - # - absolute file- or link-name in- or outside our hierarchy - # - relative file- or link-name in- or outside out hierarchy - # - full module name in- or outside our hierarchy - # - module name without version in- or outside our hierarchy - # - directory in- or outsite our hierarchy (not supported by modulecmd.tcl!) - # - # arguments: - # $1: module name or file - # - # possible return values: - # 0: is a loadable module - # 1: nothing found - # 2: wrong shebang - # 3: has unused release - # 4: inside our hierarchy but not loadable - # - # Notes: - # The variable 'release' in function 'subcommand_load()' will be set. - # The variable 'm' in function 'subcommand_load()' may be set. - # - is_available() { - local m=$1 - - # handle the case of an absolute or relative file- or link-name - if [[ -f ${m} ]]; then - if [[ "${m:0:1}" != "/" ]]; then - # convert to absolte path if relative - m=$(std::get_abspath "${m}") - fi - is_modulefile "${m}" || return 2 - is_loadable "${m}" || return 3 - if [[ "${m}" =~ "${PMODULES_ROOT}" ]]; then - for dir in "${modulepath[@]}"; do - [[ "${m}" =~ "${dir}" ]] && return 0 - done - return 4 - fi - return 0 - fi - - # check whether $m is in our modulepath - for dir in "${modulepath[@]}"; do - if [[ -d ${dir}/$1 ]]; then - # module specified without version, like 'hdf5' - while read fname; do - is_modulefile "${fname}" || return 2 - if is_loadable "${fname}"; then - moduledir="${dir}" - return 0 - fi - done < <(find "${dir}/$1" -mindepth 1 -maxdepth 1 -type l -o -type f \! -name ".*") - else - # module specified with name/version, like 'hdf5/1.8.14' - [[ -f ${dir}/$1 ]] || continue - [[ -r ${dir}/$1 ]] || continue - is_modulefile "${dir}/$1" || return 2 - if is_loadable "${dir}/$1"; then - moduledir="${dir}" - return 0 - fi - fi - done - return 1 - } - - # - # output load 'hints' - # - # Note: - # The variable 'm' from the parent function will be used - # but not changed. - # - # Args: - # none - output_load_hints() { - local -ra rels=( ${PMODULES_DEFINED_RELEASES//:/ } ) - for rel in "${rels[@]}"; do - eval $( subcommand_use "${rel}" ) - if is_available "${m}"; then - std::info "${m}: is ${rel}! If you want to load this module, run" - std::info "\tmodule use ${rel}" - std::info "before running" - std::info "\tmodule load ${m}" - exit 42 - fi - done - local something_found='no' - local -a output=() - local -a release=() - local -a loadable=() - local -i i=0 - local -i n=0 - while read -a line; do - output[n]="module load ${line[@]:3} ${line[0]}" - release[n]=${line[1]} - if [[ ":${UsedReleases}:" =~ "${release[n]}" ]]; then - loadable[n]='yes' - else - loadable[n]='no' - fi - n+=1 - done < <(subcommand_search "${m}" -a --no-header 2>&1) - std::info "${CMD} load: module unavailable -- ${m}" - if (( n > 0 )); then - # :FIXME: output group - std::info "\nBut the following modules chain(s) are available in the hierarchy:" - for ((i=n-1; i >=0; i--)); do - if [[ "${loadable[i]}" == "no" ]]; then - std::info "${output[i]}\t# ${release[i]}" - else - std::info "${output[i]}" - fi - done - fi - } - - local opts - opts=$(pmodules::get_options -o fsvw -l force -l silent -l verbose -l warn -- "$@") || \ - subcommand_help_load - eval set -- "${opts}" - local args=() - opts='' - while (($# > 0)); do - case $1 in - -f | --force ) - opts+=' -f' - ;; - -s | --silent ) - verbosity_lvl='silent' - ;; - -v | --verbose ) - verbosity_lvl='verbose' - ;; - -w | --warn ) - verbosity_lvl='warn' - ;; - -- ) - ;; - * ) - args+=( $1 ) - ;; - esac - shift - done - if (( ${#args[@]} == 0 )); then - std::die 2 "${CMD} load: No module specified." - fi - for m in "${args[@]}"; do - # restore original MODULEPATH; it might have been overwritten - MODULEPATH=${saved_MODULEPATH} - modulepath=${saved_modulepath} - UsedReleases=${saved_UsedReleases} - if [[ "$m" =~ ":" ]]; then - - # extendet module name is either - # - group:name or - # - group:name:release or - # - release:name or - # - release:group:name or - # - name:release - - local save_ifs=${IFS} - IFS=':' - local -a toks=($m) - IFS=${save_ifs} - local group='' - local release='' - if is_group "${toks[0]}"; then - group=${toks[0]} - m=${toks[1]} - release=${toks[2]} - elif is_release "${toks[0]}"; then - release=${toks[0]} - if is_group "${toks[1]}"; then - group=${toks[1]} - m=${toks[2]} - else - m=${toks[1]} - group=${toks[2]} - fi - else - m=${toks[0]} - if is_group "${toks[1]}"; then - group=${toks[1]} - release=${toks[2]} - else - release=${toks[1]} - group=${toks[2]} - fi - fi - if [[ -n ${group} ]]; then - is_group "${group}" || std::die 3 "${CMD} load: illegal group name." - local -i depth=${HierarchyDepths[${group}]} - (( depth != 0 )) && std::die 3 "${CMD} load: illegal group name." - MODULEPATH="${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}" - modulepath=( ${MODULEPATH} ) - fi - if [[ -n ${release} ]]; then - is_release "${release}" || std::die 3 "${CMD} load: illegal release name." - std::append_path UsedReleases "${release}" - fi - fi - if is_available "${m}"; then - if [[ ${verbosity_lvl} != silent ]] && [[ ${release} != stable ]]; then - std::info "Warning: the ${release} module '${m}' has been loaded." - fi - "${modulecmd}" "${shell}" ${opts} load "${m}" - else - if [[ ${verbosity_lvl} == 'verbose' ]]; then - output_load_hints - else - std::die 3 "${CMD} load: module unavailable -- ${m}" - fi - fi - done - # restore original MODULEPATH; it might have been overwritten - MODULEPATH=${saved_MODULEPATH} - UsedReleases=${saved_UsedReleases} -} - -# -# unload -# -subcommand_unload() { - # :FIXME: add dependency tests: don't unload if module is required be - # another module - while (( $# > 0 )); do - subcommand_generic1 unload "$1" - shift - done -} - -# -# swap [] -# -subcommand_swap() { - subcommand_generic1or2 swap "$@" -} - -# -# show -# -subcommand_show() { - while (( $# > 0 )); do - subcommand_generic1 show "$1" - shift - done -} - -# -# get all available modules in given directory. -# return list like -# modulename1 release1 modulename2 release2 ... -# -get_available_modules() { - local -r dir=$1 - local -r module=$2 - local -r use_releases=${3:-${UsedReleases}} - local -a mods=() - while read mod; do - local release=$( get_release "${dir}/${mod}" ) - - if [[ :${use_releases}: =~ :${release}: ]]; then - mods+=( "${mod}" ${release} ) - fi - done < <(MODULEPATH="${dir}" "${modulecmd}" bash -t avail "${module}" 2>&1 | tail -n +2) - echo "${mods[@]}" -} - -# -# avail [-hlt] [...] -# -subcommand_avail() { - # use this variable in the output functions - local -a mods=() - local dir='' - - # get number of columns of terminal - cols=$(tput cols) - - output_header() { - local caption=${dir/${PMODULES_ROOT}\/} - local caption=${caption/\/${PMODULES_MODULEFILES_DIR}/: } - local caption=${caption/: \//: } - let i=($cols-${#caption})/2-2 - printf -- "%0.s-" $(seq 1 $i) 1>&2 - printf -- " %s " "${caption}" 1>&2 - printf -- "%0.s-" $(seq 1 $i) 1>&2 - printf -- "\n" 1>&2 - } - - terse_output() { - output_header - for (( i=0; i<${#mods[@]}; i+=2 )); do - local mod=${mods[i]} - local release=${mods[i+1]} - case $release in - stable ) - out='' - ;; - * ) - out="${release}" - ;; - esac - printf "%-20s\t%s\n" "${mod}" "${out}" 1>&2 - done - std::info "" - } - - # - # :FIXME: for the time being, this is the same as terse_output! - long_output() { - output_header - for (( i=0; i<${#mods[@]}; i+=2 )); do - local mod=${mods[i]} - local release=${mods[i+1]} - case $release in - stable ) - out='' - ;; - * ) - out=${release} - ;; - esac - printf "%-20s\t%s\n" "${mod}" "${out}" 1>&2 - done - std::info "" - } - - human_readable_output() { - output_header - - local -i column=$cols - local -i colsize=16 - for ((i=0; i<${#mods[@]}; i+=2)); do - if [[ ${verbosity_lvl} == 'verbose' ]]; then - local release=${mods[i+1]} - case ${mods[i+1]} in - stable ) - mod=${mods[i]} - ;; - * ) - mod="${mods[i]}(${release:0:1})" - ;; - esac - else - mod=${mods[i]} - fi - local -i len=${#mod} - local -i span=$(( len / 16 + 1 )) - local -i colsize=$(( span * 16 )) - if (( column+len >= cols )); then - printf -- "\n" 1>&2 - column=0 - fi - if (( column+colsize < cols )); then - fmt="%-${colsize}s" - else - fmt="%-s" - fi - printf "${fmt}" "${mod}" 1>&2 - column+=colsize - done - printf -- "\n\n" 1>&2 - } - local opts='' - opts=$(pmodules::get_options -o hlt -l human -l long -l terse -- "$@") || subcommand_help_avail - eval set -- "${opts}" - local pattern=() - local output_function='' - local opts='' - while (($# > 0)); do - case $1 in - -h | --human ) - [[ -z ${opts} ]] || \ - std::die 1 "${CMD} list: you cannot set both options: '$1' and '${opts}'." - opts=$1 - output_function='human_readable_output' - ;; - -l | --long ) - [[ -z ${opts} ]] || \ - std::die 1 "${CMD} list: you cannot set both options: '$1' and '${opts}'." - opts=$1 - output_function='long_output' - ;; - -t | --terse ) - [[ -z ${opts} ]] || \ - std::die 1 "${CMD} list: you cannot set both options: '$1' and '${opts}'." - opts=$1 - output_function='terse_output' - ;; - -- ) - ;; - * ) - pattern+=( "$1" ) - ;; - esac - shift - done - output_function=${output_function:-human_readable_output} - if (( ${#pattern[@]} == 0 )); then - pattern+=( '' ) - fi - local saved_IFS=${IFS}; - IFS=':' - local -a modulepath=(${MODULEPATH}) - IFS=${saved_IFS} - for string in "${pattern[@]}"; do - for dir in "${modulepath[@]}"; do - mods=( $( get_available_modules "${dir}" "${string}" ) ) - [[ ${#mods[@]} == 0 ]] && continue - - ${output_function} - done - done -} - -# get available groups -# $1: root of modulefile hierarchy -# -get_groups () { - local -r root="$1" - { - cd "${root}" - # for some unknown reason [A-Z]* doesn't work on (some?) SL6 systems - for f in [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*; do - Groups+=( $f ) - done - }; -} - -# -# $1: root of modulefile hierarchy -get_hierarchy_depth () { - local -r root="$1" - { - cd "${root}" - local _group - for _group in "${Groups[@]}"; do - local tmp=$(find "${_group}/${PMODULES_MODULEFILES_DIR}" -depth -type f -o -type l | head -1) - local -a tmp2=( ${tmp//\// } ) - local depth=${#tmp2[@]} - let depth-=4 - HierarchyDepths[$_group]=${depth} - done - }; -} - -# -# use [-a|--append|-p|--prepend] [directory|group|release...] -# -subcommand_use() { - if (( ${#Groups[@]} == 0 )); then - get_groups "${PMODULES_ROOT}" - get_hierarchy_depth "${PMODULES_ROOT}" - fi - local saved_IFS=${IFS}; - IFS=':' - local -a modulepath=(${MODULEPATH}) - IFS=${saved_IFS} - - print_info() { - local f - local r - std::info "Used groups:" - for f in ${used_groups//:/ }; do - std::info "\t${f}" - done - std::info "\nUnused groups:" - local _group - for _group in "${Groups[@]}"; do - local -i depth=${HierarchyDepths[${_group}]} - if ! is_used_group "${_group}" && (( depth == 0 )); then - std::info "\t${_group}" - fi - done - - std::info "\nUsed releases:" - for r in ${UsedReleases//:/ }; do - std::info "\t${r}" - done - std::info "\nUnused releases:" - for r in ${PMODULES_DEFINED_RELEASES//:/ }; do - if ! is_used_release $r; then - std::info "\t${r}" - fi - done - - std::info "\nAdditonal directories in MODULEPATH:" - let n=0 - for (( i=0; i<${#modulepath[@]}; i++)); do - if [[ ! ${modulepath[i]} =~ ${PMODULES_ROOT} ]]; then - std::info "\t${modulepath[i]}" - let n+=1 - fi - done - if (( n == 0 )); then - std::info "\tnone" - fi - std::info "\n" - } - - use () { - - local dirs_to_add=() - local subcommand_switches='' - while (( $# > 0)); do - if [[ "$1" == "--" ]]; then - shift - continue - fi - arg=$1 - # if is release - # ... - # elif is group - # ... - # elif matches modulepath root - # ... - # elif is directory - # ... - local modulefiles_dir="${PMODULES_ROOT}/${arg}/${PMODULES_MODULEFILES_DIR}" - if [[ ${arg} == -a ]] || [[ ${arg} == --append ]]; then - subcommand_switches='--append' - elif [[ ${arg} == -p ]] || [[ ${arg} == --prepend ]]; then - subcommand_switches='' - elif is_release "${arg}"; then - # releases are always *appended* - std::append_path UsedReleases "${arg}" - elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulefiles_dir} ]]; then - if (( ${HierarchyDepths[$arg]} != 0 )); then - std::die 3 "${CMD} ${FUNCNAME[0]##*_}: cannot add group ${arg} to module path" - fi - std::append_path PMODULES_USED_GROUPS "${arg}" - dirs_to_add+=( ${modulefiles_dir} ) - elif [[ ${arg} =~ ^${PMODULES_ROOT} ]]; then - std::die 3 "${CMD} ${FUNCNAME[0]##*_}: illegal directory: ${arg}" - elif [[ -d ${arg} ]]; then - local normalized_dir=$(cd "${arg}" && pwd) - dirs_to_add+=( ${normalized_dir} ) - else - std::die 3 "${CMD} ${FUNCNAME[0]##*_}: neither a directory, release or group: ${arg}" - fi - shift - done - - declare -g PMODULES_USED_GROUPS="${PMODULES_USED_GROUPS}" - export_env PMODULES_USED_GROUPS - [[ ${#dirs_to_add[@]} == 0 ]] && return - - for dir in "${dirs_to_add[@]}"; do - subcommand_generic1 use ${subcommand_switches} "${dir}" - done - } - - local opts='' - opts=$(pmodules::get_options -o 'ap' -l 'append' -l 'prepend' -- "$@") || subcommand_help_use - eval set -- "${opts}" - - if [[ $# == 1 ]]; then - print_info - else - use "$@" - fi -} - -# -# unuse directory|group|release... -# -subcommand_unuse() { - local opts='' - opts=$(pmodules::get_options -o '' -- "$@") || subcommand_help_unuse - eval set -- "${opts}" - local dirs_to_remove=() - while (( $# > 0)); do - if [[ "$1" == "--" ]]; then - shift - continue - fi - arg=$1 - # if is release - # ... - # elif is group - # ... - # elif matches modulepath root - # ... - # elif is directory - # ... - local modulefiles_dir="${PMODULES_ROOT}/${arg}/${PMODULES_MODULEFILES_DIR}" - if is_release "${arg}"; then - std::remove_path UsedReleases "${arg}" - elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulefiles_dir} ]]; then - if (( ${HierarchyDepths[$arg]} != 0 )); then - std::die 3 "${CMD} ${FUNCNAME[0]##*_}: cannot remove group ${arg} from module path" - fi - std::remove_path PMODULES_USED_GROUPS "${arg}" - dirs_to_remove+=( ${modulefiles_dir} ) - elif [[ -d ${arg} ]]; then - local normalized_dir=$(cd "${arg}" && pwd) - dirs_to_remove+=( ${normalized_dir} ) - elif [[ ${arg} =~ ^${PMODULES_ROOT} ]]; then - std::die 3 "${CMD} ${FUNCNAME[0]##*_}: illegal directory: ${arg}" - else - std::die 3 "${CMD} ${FUNCNAME[0]##*_}: not a directory: ${arg}" - fi - shift - done - #echo "export PMODULES_USED_GROUPS=${PMODULES_USED_GROUPS}" - declare -g PMODULES_USED_GROUPS="${PMODULES_USED_GROUPS}" - export_env PMODULES_USED_GROUPS - [[ ${#dirs_to_remove[@]} == 0 ]] && return - for dir in "${dirs_to_remove[@]}"; do - subcommand_generic1 unuse "${dir}" - done -} - -# -# update -# -# :FIXME: either compile Modules with --enable-beginenv or remove the sub-command -# -subcommand_update() { - subcommand_generic0 update "$@" -} - -# -# refresh -# -subcommand_refresh() { - subcommand_generic0 refresh "$@" -} - -# -# purge -# -subcommand_purge() { - subcommand_generic0 purge "$@" -} - -# -# list [-hlt] -# -subcommand_list() { - local opts='' - opts=$(pmodules::get_options -o hlt -l human -l long -l terse -- "$@") || subcommand_help_list - eval set -- "${opts}" - local opts='' - while (( $# > 0 )); do - case $1 in - -h | --human ) - [[ -z ${opts} ]] || \ - std::die 1 "${CMD} list: you cannot set both options: '$1' and '${opts}'." - opts='-h' - ;; - -l | --long ) - [[ -z ${opts} ]] || \ - std::die 1 "${CMD} list: you cannot set both options: '$1' and '${opts}'." - opts='-l' - ;; - -t | --terse ) - [[ -z ${opts} ]] || \ - std::die 1 "${CMD} list: you cannot set both options: '$1' and '${opts}'." - opts='-t' - ;; - -- ) - ;; - * ) - std::die 1 "${CMD} list: invalid argument -- $1" - ;; - esac - shift - done - "${modulecmd}" "${shell}" list "${opts}" -} - -pmodules_init() { - declare -g PMODULES_DEFAULT_GROUPS='' - declare -g PMODULES_DEFAULT_RELEASES='' - - source "${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/environment.bash" - - declare -g LOADEDMODULES='' - declare -g PMODULES_USED_GROUPS='' - declare -g MODULEPATH='' - declare -g _LMFILES_='' - - for group in ${PMODULES_DEFAULT_GROUPS}; do - std::append_path MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}" - std::append_path PMODULES_USED_GROUPS "${group}" - done - declare -ag Groups='()' - declare -Ag HierarchyDepths='()' - declare -g UsedReleases='' - for r in ${PMODULES_DEFAULT_RELEASES//:/ }; do - std::append_path UsedReleases "${r}" - done - -} - -# -# clear -# -subcommand_clear() { - local opts='' - opts=$(pmodules::get_options -- '' "$@") || subcommand_help_${subcommand} - eval set -- "${opts}" - while (( $# > 0 )); do - case $1 in - -- ) - shift - ;; - * ) - std::die 3 "${CMD} ${subcommand}: illegal argument -- $1" - ;; - esac - done - pmodules_init - export_env LOADEDMODULES PMODULES_USED_GROUPS MODULEPATH _LMFILES_ -} - -# -# search [switches] [STRING...] -# -subcommand_search() { - local modules=() - local with_modules='//' - local src_prefix='' - local _print_header='yes' - local _print_modulefiles='no' - local use_releases=':' - local -r fmt="%-20s %-10s %-12s %-s\n" - - # no args - print_header() { - printf '\n' 1>&1 - printf "${fmt}" "Module" "Release" "Group" "Requires" 1>&2 - printf -- '-%.0s' {1..60} 1>&2 - printf '\n' 1>&2 - } - - # args: - # $1: module name pattern - search () { - local -r module=$1 - # we must write temporary results to a file for sorting - local -r tmpfile=$( mktemp /tmp/$(basename $0).XXXXXX ) \ - || std::die 1 "Oops: unable to create tmp file!" - local _group - # loop over all groups - for _group in "${Groups[@]}"; do - local depth=${HierarchyDepths[${_group}]} - # get all potential directories of group with module-files - local mpaths=( $(find \ - "${src_prefix}/${_group}/modulefiles" \ - -type d \ - -mindepth ${depth} -maxdepth ${depth} \ - 2>/dev/null)) - local mpath - for mpath in "${mpaths[@]}"; do - # get dependencies encoded in directory name - local p="${mpath/${src_prefix}}" - p=( ${p//\// } ) - local deps=() - local -i i - for ((i=2; i < ${#p[@]}; i+=2)); do - deps+=( ${p[i]}/${p[i+1]} ) - done - local requires=${deps[@]} - - # get and print all available modules in $mpath - # with respect to the requested releases - local mods=( $( get_available_modules \ - "${mpath}" \ - "${module}" \ - "${use_releases}" ) ) - [[ ${#mods[@]} == 0 ]] && continue - for (( i=0; i<${#mods[@]}; i+=2 )); do - printf "${fmt}" ${mods[i]} "${mods[i+1]}" \ - ${_group} "${requires}" >> "${tmpfile}" - done - done - done - if [[ "${_print_modulefiles}" == "no" ]]; then - sort -k 1,1 -k 4,4 -k 5,5 "${tmpfile}" | awk "${with_modules}" 1>&2 - else - while read -a line; do - # group first - local out="${line[2]}/" - # add directory of modulefiles - out+="${PMODULES_MODULEFILES_DIR}/" - for d in "${line[@]:3}"; do - out+="$d/" - done - out+="${line[0]}" - std::info "${out}" - done < <(sort -k 1,1 -k 4,4 -k 5,5 "${tmpfile}" | awk "${with_modules}") - fi - rm -f "${tmpfile}" - } - - opts=$(pmodules::get_options -o 'ahH?' \ - -l help \ - -l no-header \ - -l print-modulefiles \ - -l release: \ - -l with: \ - -l all-releases \ - -l src: \ - -- "$@") || subcommand_help_${0##*_} - eval set -- "${opts}" - - while (( $# > 0 )); do - case $1 in - --no-header ) - _print_header='no' - ;; - --print-modulefiles ) - _print_modulefiles='yes' - _print_header='no' - ;; - --release ) - is_release "$2" || \ - std::die 1 "${CMD} search: illegal release name -- $2" - use_releases+="$2:" - shift - ;; - --with ) - if [[ -z $2 ]] || [[ "$2" =~ "-*" ]]; then - std::die 1 "${CMD} search: with what?" - fi - with_modules+=" && / ${2//\//\\/}/" - shift - ;; - -a | --all-releases ) - use_releases="${PMODULES_DEFINED_RELEASES}" - ;; - --src ) - src_prefix=$2 - pmodules::check_directories "${src_prefix}" - - shift - ;; - -\? | -h | -H | --help ) - usage - ;; - -- ) - ;; - * ) - modules+=( "$1" ) - ;; - esac - shift - done - if [[ -z "${src_prefix}" ]]; then - src_prefix="${PMODULES_ROOT}" - fi - - if [[ "${use_releases}" == ":" ]]; then - use_releases=":${UsedReleases}:" - fi - - [[ "${_print_header}" == "yes" ]] && print_header - if [[ ${#modules[@]} == 0 ]]; then - modules+=( '' ) - fi - - if (( ${#Groups[@]} == 0 )) || [[ ${src_prefix} != ${PMODULES_ROOT} ]]; then - get_groups "${src_prefix}" - get_hierarchy_depth "${src_prefix}" - fi - - for module in "${modules[@]}"; do - search "${module}" - done -} - -# -# help [module|sub-command] -# -subcommand_help() { - local opts='' - opts=$(pmodules::get_options -o HV\? -l version -l help -- "$@") || usage - eval set -- "${opts}" - local arg='' - - while (( $# > 0 )); do - case $1 in - -[hH] | -\? | --help ) - usage - ;; - -V | --version ) - print_version - std::die 1 - ;; - -- ) - : - ;; - * ) - [[ -z ${arg} ]] || \ - std::die 1 "${CMD} help: only one argument allowed." - arg="$1" - ;; - esac - shift - done - if [[ -z ${arg} ]]; then - usage - elif typeset -F subcommand_help_${arg} > /dev/null 2>&1 ; then - # help for sub-command - subcommand_help_${arg} - else - # :FIXME: print help of newest *available* module - # (respecting UsedReleases) - subcommand_generic1plus help "${arg}" - fi -} - -# -# whatis [module] -# -subcommand_whatis() { - if (( $# == 0 )); then - subcommand_generic0 whatis - else - subcommand_generic1plus whatis "$@" - fi -} - -# -# apropos string -# -subcommand_apropos() { - subcommand_generic1 apropos "$@" -} - -# -# initadd module... -# -subcommand_initadd() { - subcommand_generic1plus initadd "$@" -} - -# -# initprepend module... -# -subcommand_initprepend() { - subcommand_generic1plus initprepend "$@" -} - -# -# initrm module... -# -subcommand_initrm() { - subcommand_generic1plus initrm "$@" -} - -# -# initswitch module1 module2 -# -subcommand_initswitch() { - subcommand_generic1or2 initswitch "$@" -} - -# -# initlist -# -subcommand_initlist() { - subcommand_generic0 initlist "$@" -} - -# -# initclear -# -subcommand_initclear() { - subcommand_generic0 initclear "$@" -} - -if [[ -n ${PMODULES_ENV} ]]; then - eval "$("${PMODULES_HOME}/bin/base64" -d <<< "${PMODULES_ENV}" 2>/dev/null)" -else - pmodules_init -fi - -case $1 in - bash ) - declare shell="$1" - ;; - tcsh ) - declare shell="$1" - ;; - * ) - std::die 1 "${CMD}: unsupported shell -- $1" - ;; -esac -shift - -declare -a opts=() -while (( $# > 0 )); do - case $1 in - -H | -\? | --help | -help ) - usage - ;; - -V | --version ) - print_version - std::die 1 - ;; - -* ) - opts+=( "$1" ) - ;; - add|load ) - subcommand='subcommand_load' - shift - opts+=( "$@" ) - shift $# - ;; - rm|unload ) - subcommand='subcommand_unload' - shift - opts+=( "$@" ) - shift $# - ;; - switch|swap ) - subcommand='subcommand_swap' - shift - opts+=( "$@" ) - shift $# - ;; - display|show ) - subcommand='subcommand_show' - shift - opts+=( "$@" ) - shift $# - ;; - apropos|keyword ) - subcommand='subcommand_apropos' - shift - opts+=( "$@" ) - shift $# - ;; - avail|search|use|unuse|update|refresh|purge|list|clear|whatis|help ) - subcommand=subcommand_$1 - shift - if (( $# > 0 )); then - opts+=( "$@" ) - shift $# - fi - ;; - initadd|initprepend|initrm|initswitch|initlist|initclear ) - subcommand=subcommand_$1 - shift - opts=( "$@" ) - shift $# - ;; - * ) - std::die 1 "${CMD}: unknown sub-command -- $1" - ;; - esac - shift -done - -if (( ${#Groups[@]} == 0 )); then - get_groups "${PMODULES_ROOT}" - get_hierarchy_depth "${PMODULES_ROOT}" -fi - -$subcommand "${opts[@]}" - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/profile.bash b/Bootstrap/Pmodules/profile.bash deleted file mode 100644 index 77e4b6e..0000000 --- a/Bootstrap/Pmodules/profile.bash +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -# -############################################################################# -# D O N O T C H A N G E T H I S F I L E ! # -############################################################################# - -############################################################################# -# read Pmodules configuration -# -_init_env_file="$(dirname ${BASH_SOURCE})/environment.bash" -if [[ ! -r "${_init_env_file}" ]]; then - echo "Oops: cannot initialize Modules!" - echo "${_init_env_file}: file does not exist or is not readable." - return 1 -fi -source "${_init_env_file}" -unset _init_env_file - -############################################################################ -# check configuration -# -if [[ -z ${PMODULES_ROOT} ]]; then - echo "Oops: Pmodules root not set." 1>&2 - return 1 -fi -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 [[ -z ${PMODULES_VERSION} ]]; then - echo "Oops: ${PMODULES_VERSION}: Pmodules version not set." 1>&2 - return 1 -fi -if [[ -z ${PMODULES_HOME} ]]; then - echo "Oops: Pmodules home not set." 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 - -############################################################################ -# inititialize Pmodules for bash -# -_init_bash="${PMODULES_HOME}/init/bash" -if [[ ! -r "${_init_bash}" ]]; then - echo "Oops: cannot initialize Modules!" - echo "${_init_bash}: File does not exist or is not readable." - return 1 -fi -source "${_init_bash}" -unset _init_bash - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Pmodules/profile.csh b/Bootstrap/Pmodules/profile.csh deleted file mode 100755 index 0aee6f5..0000000 --- a/Bootstrap/Pmodules/profile.csh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/tcsh - -############################################################################# -# read Pmodules configuration -# -set _init_env_file="/opt/psi/config/environment.bash" -if ( ! -r "$_init_env_file" ); then - echo "Oops: cannot initialize Modules!" - echo "$_init_env_file: file does not exist or is not readable." - return 1 -fi -source "$_init_env_file" -unset _init_env_file - -############################################################################ -# check configuration -# -if ( ! $?PMODULES_PREFIX ) then - echo "Oops: Pmodules prefix not set." - return 1 -endif - -if ( "$PMODULES_PREFIX" == "" ) then - echo "Oops: Pmodules prefix set to empty string!" -endif -if ( ! -d ${PMODULES_PREFIX} ) then - echo "Oops: ${PMODULES_PREFIX}: Set as Pmodules prefix, but this is not a directory!" - return 1 -endif - -if ( ! $?PMODULES_VERSION ) then - echo "Oops: Pmodules version not set!" - return 1 -endif -if ( "$PMODULES_VERSION" == "" ) then - echo "Oops: Pmodules version set to empty string!" - return 1 -endif - -if ( $?PMODULES_HOME ) then - echo "Oops: Pmodules home not set!" - return 1 -endif -if ( "$PMODULES_HOME" == "" ) then - echo "Oops: Pmodules home set to empty string!" - return 1 -fi -if ( ! -d "$PMODULES_HOME" ) then - echo "Oops: $PMODULES_HOME: Set as Pmodules home, but this is not a directory!" - return 1 -endif - -############################################################################ -# inititialize Pmodules for bash -# -set _init_csh="$PMODULES_HOME/init/csh" -if ( ! -r "$_init_csh" ) then - echo "Oops: cannot initialize Modules!" - echo "$_init_csh: File does not exist or is not readable." - return 1 -fi -source "$_init_csh" -unset _init_csh - -# Local Variables: -# mode: csh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/Tcl/build b/Bootstrap/Tcl/build deleted file mode 100755 index 2f7bab6..0000000 --- a/Bootstrap/Tcl/build +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env modbuild - -pbuild::configure() { - case ${OS} in - Linux ) - srcdir="${MODULE_SRCDIR}/unix" - ;; - Darwin ) - srcdir="${MODULE_SRCDIR}/macosx" - ;; - esac - "${srcdir}"/configure \ - --prefix="${PREFIX}" \ - --enable-shared=no \ - || exit 1 -} - -pbuild::post_install() { - { cd "${PREFIX}"/bin && rm -f tclsh && ln -fs tclsh${V%.*} tclsh; }; -} - -pbuild::add_to_group 'Tools' -pbuild::set_docfiles 'license.terms' 'README' -pbuild::make_all diff --git a/Bootstrap/bash/build b/Bootstrap/bash/build deleted file mode 100755 index 27e258a..0000000 --- a/Bootstrap/bash/build +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env modbuild - -pbuild::configure() { - "${MODULE_SRCDIR}"/configure \ - --prefix="${PREFIX}" \ - || exit 1 -} - -pbuild::add_to_group 'Tools' -pbuild::make_all diff --git a/Bootstrap/bootstrap.sh b/Bootstrap/bootstrap.sh deleted file mode 100755 index e63c140..0000000 --- a/Bootstrap/bootstrap.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -declare -r BASE_DIR=$(cd "$(dirname $0)/../.." && pwd) -declare -r BOOTSTRAP_DIR="${BASE_DIR}/Bootstrap" - -${BOOTSTRAP_DIR}/compile_pmodules.sh -${BOOTSTRAP_DIR}/install_pmodules.sh - diff --git a/Bootstrap/compile_pmodules.sh b/Bootstrap/compile_pmodules.sh deleted file mode 100755 index 25283f5..0000000 --- a/Bootstrap/compile_pmodules.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -declare -r BOOTSTRAP_DIR=$(dirname "$0") - -unset PMODULES_HOME -unset PMODULES_VERSION - -source "${BOOTSTRAP_DIR}/Pmodules/libstd.bash" -source "${BOOTSTRAP_DIR}/config/environment.bash" - -std::read_versions "${BOOTSTRAP_DIR}/config/versions.conf" - -#if [[ -n ${PMODULES_DIR} ]] && [[ "${PMODULES_DIR}" != "/" ]] && [[ -d "${PMODULES_DIR}" ]]; then -# rm -rf "${PMODULES_DIR}" -#fi - -build () { - local -r name="$1" - local -r version="$2" - - "${BOOTSTRAP_DIR}/Pmodules/modbuild" "${BOOTSTRAP_DIR}/${name}/build" --disable-cleanup "${version}" || \ - std::die 3 "Compiling '${name}' failed!" -} - -if [[ ! -f "${PMODULES_HOME}/bin/base64" ]]; then - build coreutils "${COREUTILS_VERSION}" -fi - -if [[ ! -f "${PMODULES_HOME}/bin/xgettext" ]]; then - build gettext "${GETTEXT_VERSION}" -fi - -if [[ ! -f "${PMODULES_HOME}/bin/getopt" ]]; then - build getopt "${GETOPT_VERSION}" -fi - -if [[ ! -f "${PMODULES_HOME}/bin/dialog" ]]; then - build dialog "${DIALOG_VERSION}" -fi - -if [[ ! -f "${PMODULES_HOME}/bin/bash" ]]; then - build bash "4.3.30" -fi - -if [[ ! -e "${PMODULES_HOME}/bin/tclsh" ]]; then - build Tcl "${TCL_VERSION}" -fi - -if [[ ! -e "${PMODULES_HOME}/libexec/modulecmd.tcl" ]]; then - build Modules "${MODULES_VERSION}" && \ - mv -v "${PMODULES_HOME}/bin/modulecmd" "${PMODULES_HOME}/libexec/modulecmd.tcl" -fi -echo "Done..." diff --git a/Bootstrap/config/environment.bash.psi b/Bootstrap/config/environment.bash.psi deleted file mode 100644 index cd8914b..0000000 --- a/Bootstrap/config/environment.bash.psi +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# - -declare -x PMODULES_ROOT='/opt/psi' -declare -x PMODULES_CONFIG_DIR='config' -declare -x PMODULES_MODULEFILES_DIR='modulefiles' -declare -x PMODULES_TEMPLATES_DIR='templates' - -declare -x PMODULES_VERSION="0.99.5" - -declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" - -declare -x PMODULES_DEFAULT_GROUPS='Tools Programming' -declare -x PMODULES_DEFINED_RELEASES=':unstable:stable:deprecated:' -declare -x PMODULES_DEFAULT_RELEASES='stable' - - diff --git a/Bootstrap/config/versions.conf b/Bootstrap/config/versions.conf deleted file mode 100644 index 779ebf9..0000000 --- a/Bootstrap/config/versions.conf +++ /dev/null @@ -1,8 +0,0 @@ -bash 4.3.30 -coreutils 8.23 -dialog 1.2.1 -getopt 1.1.6 -gettext 0.19.4 -Modules 3.2.10 -Pmodules 0.99.5 -Tcl 8.6.3 diff --git a/Bootstrap/coreutils/build b/Bootstrap/coreutils/build deleted file mode 100755 index ed5e87a..0000000 --- a/Bootstrap/coreutils/build +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env modbuild - -pbuild::configure() { - "${MODULE_SRCDIR}"/configure \ - --prefix="${PREFIX}" \ - || exit 1 -} - -pbuild::add_to_group 'Tools' -pbuild::make_all diff --git a/Bootstrap/coreutils/build.new b/Bootstrap/coreutils/build.new deleted file mode 100755 index 63030c7..0000000 --- a/Bootstrap/coreutils/build.new +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env pbuild - -pmodules.configure() { - "${MODULE_SRCDIR}"/configure \ - --prefix="${PREFIX}" \ - || exit 1 -} - -pmodules.add_to_group 'Tools' -pmodules.make_all diff --git a/Bootstrap/dialog/build b/Bootstrap/dialog/build deleted file mode 100755 index 27e258a..0000000 --- a/Bootstrap/dialog/build +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env modbuild - -pbuild::configure() { - "${MODULE_SRCDIR}"/configure \ - --prefix="${PREFIX}" \ - || exit 1 -} - -pbuild::add_to_group 'Tools' -pbuild::make_all diff --git a/Bootstrap/getopt/build b/Bootstrap/getopt/build deleted file mode 100755 index d486ed3..0000000 --- a/Bootstrap/getopt/build +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env modbuild - -pbuild::configure() { - : -} - -pbuild::build() { - case ${OS} in - Linux ) - declare -x LDFLAGS="-lintl" - ;; - Darwin ) - declare -x LDFLAGS="-lintl -liconv -framework CoreFoundation" - ;; - esac - - cd "${MODULE_SRCDIR}" - make -e -} - -pbuild::install() { - cd "${MODULE_SRCDIR}" - declare -x DESTDIR="${PREFIX}" - declare -x prefix='' - make -e install -} - -pbuild::cleanup_build() { - cd "${MODULE_SRCDIR}" - make -e realclean -} - -pbuild::add_to_group 'Tools' -pbuild::make_all - -# Local Variables: -# mode: sh -# sh-basic-offset: 8 -# tab-width: 8 -# End: diff --git a/Bootstrap/gettext/build b/Bootstrap/gettext/build deleted file mode 100755 index c859d43..0000000 --- a/Bootstrap/gettext/build +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env modbuild - -pbuild::configure() { - "${MODULE_SRCDIR}"/configure \ - --prefix="${PREFIX}" \ - --disable-java \ - --disable-threads \ - --disable-shared \ - --enable-relocatable \ - --disable-openmp \ - --disable-acl \ - --disable-curses \ - --with-included-gettext \ - --without-libiconv-prefix \ - --without-libintl-prefix \ - --with-included-libxml \ - --with-pic=yes \ - || exit 1 -} - -pbuild::add_to_group 'Tools' -pbuild::make_all diff --git a/Bootstrap/install_pmodules.sh b/Bootstrap/install_pmodules.sh deleted file mode 100755 index 489625a..0000000 --- a/Bootstrap/install_pmodules.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -declare BOOTSTRAP_DIR=$(dirname "$0") -source "${BOOTSTRAP_DIR}/Pmodules/libstd.bash" -source "${BOOTSTRAP_DIR}/config/environment.bash" - -declare -r BOOTSTRAP_DIR=$(std::get_abspath "${BOOTSTRAP_DIR}") -declare -r SRC_DIR="${BOOTSTRAP_DIR}/Pmodules" - -std::read_versions "${BOOTSTRAP_DIR}/config/versions.conf" - - -echo "Installing to ${PMODULES_HOME} ..." -sed_cmd="s:@PMODULES_HOME@:${PMODULES_HOME}:g;" -sed_cmd+="s:@PMODULES_VERSION@:${PMODULES_VERSION}:g;" -sed_cmd+="s:@MODULES_VERSION@:${MODULES_VERSION}:g" -sed "${sed_cmd}" "${SRC_DIR}/modulecmd.bash.in" > "${SRC_DIR}/modulecmd.bash" -sed "${sed_cmd}" "${SRC_DIR}/modmanage.bash.in" > "${SRC_DIR}/modmanage.bash" -sed "${sed_cmd}" "${SRC_DIR}/environment.bash.in" > "${SRC_DIR}/environment.bash" - -install -d -m 0755 "${PMODULES_HOME}/bin" -install -d -m 0755 "${PMODULES_HOME}/config" -install -d -m 0755 "${PMODULES_HOME}/init" -install -d -m 0755 "${PMODULES_HOME}/lib" - -install -m 0755 "${SRC_DIR}/modulecmd" "${PMODULES_HOME}/bin" -install -m 0755 "${SRC_DIR}/modulecmd.bash" "${PMODULES_HOME}/libexec" -install -m 0755 "${SRC_DIR}/modmanage" "${PMODULES_HOME}/bin" -install -m 0755 "${SRC_DIR}/modmanage.bash" "${PMODULES_HOME}/libexec" -install -m 0755 "${SRC_DIR}/dialog.bash" "${PMODULES_HOME}/bin" -install -m 0755 "${SRC_DIR}/modbuild" "${PMODULES_HOME}/bin" - -install -m 0755 "${SRC_DIR}/environment.bash" "${PMODULES_HOME}/config/environment.bash.in" -install -m 0755 "${SRC_DIR}/profile.bash" "${PMODULES_HOME}/config/profile.bash.in" - -install -m 0644 "${SRC_DIR}/bash" "${PMODULES_HOME}/init" -install -m 0644 "${SRC_DIR}/bash_completion" "${PMODULES_HOME}/init" - -install -m 0644 "${SRC_DIR}/libpmodules.bash" "${PMODULES_HOME}/lib" -install -m 0644 "${SRC_DIR}/libpbuild.bash" "${PMODULES_HOME}/lib" -install -m 0644 "${SRC_DIR}/libstd.bash" "${PMODULES_HOME}/lib" -install -m 0644 "${SRC_DIR}/libmodules.tcl" "${PMODULES_HOME}/lib/tcl8.6" - -{ - cd "${PMODULES_HOME}/lib/tcl8.6" - "${BOOTSTRAP_DIR}/mkindex.tcl" -} diff --git a/Bootstrap/mkindex.tcl b/Bootstrap/mkindex.tcl deleted file mode 100755 index 297872f..0000000 --- a/Bootstrap/mkindex.tcl +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env tclsh - -auto_mkindex . *.tcl