diff --git a/scripts/Bootstrap/Modules/build b/scripts/Bootstrap/Modules/build index a22a7e1..b8795df 100755 --- a/scripts/Bootstrap/Modules/build +++ b/scripts/Bootstrap/Modules/build @@ -2,7 +2,7 @@ #set -o functrace source "$(dirname $0)/../../../lib/libem.bash" -TCL_DIR="${PSI_PREFIX}/Tools/Pmodules/${PMODULES_VERSION}" +TCL_DIR="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" PATH="${TCL_DIR}/bin:${PATH}" @@ -18,7 +18,7 @@ function em.configure() { CPPFLAGS="-DUSE_INTERP_ERRORLINE" "${MODULE_SRCDIR}"/configure \ --prefix="${PREFIX}" \ --exec-prefix="${PREFIX}" \ - --with-module-path="${PSI_PREFIX}/${PSI_MODULES_ROOT}" \ + --with-module-path="${PMODULES_ROOT}/Tools/${PMODULES_MODULEFILES_DIR}" \ --with-tcl="${TCL_DIR}/lib" \ --without-x \ --disable-versioning \ diff --git a/scripts/Bootstrap/Pmodules/bash b/scripts/Bootstrap/Pmodules/bash index 7621913..3a8293a 100644 --- a/scripts/Bootstrap/Pmodules/bash +++ b/scripts/Bootstrap/Pmodules/bash @@ -136,17 +136,17 @@ declare -x LOADEDMODULES='' declare -x _LMFILES_='' declare -x PMODULES_USED_GROUPS='' declare -x MODULEPATH='' -for f in ${PMODULES_DEFAULT_GROUPS//:/ }; do - append_path MODULEPATH "${PSI_PREFIX}/${PSI_MODULES_ROOT}/$f" - append_path PMODULES_USED_GROUPS "${f}" +for group in ${PMODULES_DEFAULT_GROUPS//:/ }; do + append_path MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}" + append_path PMODULES_USED_GROUPS "${group}" done -declare -x USED_RELEASES='' +declare -x UsedReleases='' for r in ${PMODULES_DEFAULT_RELEASES//:/ }; do - append_path USED_RELEASES "${r}" + append_path UsedReleases "${r}" done -eval $(save_env USED_RELEASES PMODULES_DEFAULT_RELEASES PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES) -unset USED_RELEASES +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 diff --git a/scripts/Bootstrap/Pmodules/dialog.bash b/scripts/Bootstrap/Pmodules/dialog.bash index 1235b24..fe2df76 100755 --- a/scripts/Bootstrap/Pmodules/dialog.bash +++ b/scripts/Bootstrap/Pmodules/dialog.bash @@ -61,7 +61,7 @@ function unique_id() { # $1: module info index function mod_path() { # $1: module info index local -i i local -a m=(${modlist[$1]}) - local res="$PSI_PREFIX/${fmmap[${m[0]%%/*}]}/${m[0]}" + local res="$PMODULES_ROOT/${fmmap[${m[0]%%/*}]}/${m[0]}" for (( i=${#m[@]}; i>3; i-- )); do res+="/${m[i-1]}" done @@ -156,7 +156,7 @@ function find_families() { t=( ${l##*:} ) fdmap[$n]=${t[-1]//\"} fi - done < <(grep -R set-family "$1/${PSI_MODULES_ROOT}") + done < <(grep -R set-family "$1/*/${PMODULES_MODULEFILES_DIR}") } function select_uid() { # $1: module uid @@ -174,7 +174,7 @@ function preselect() { # "$1": prefix for preselected modules local -a mpc # module path components local -i i local uid n - pushd "$1/$PSI_MODULES_ROOT" > /dev/null || exit 1; + pushd "$1/$PMODULES_MODULEFILES_DIR" > /dev/null || exit 1; trap "popd" EXIT for m in $(find . -follow -type f); do @@ -186,7 +186,7 @@ function preselect() { # "$1": prefix for preselected modules uid+="${mpc[i]}/${mpc[i+1]} " done uid+="${mpc[-2]}/${mpc[-1]}" - PSI_PREFIX="$1" select_uid "$uid" + PMODULES_ROOT="$1" select_uid "$uid" done popd @@ -309,8 +309,8 @@ function module_picker() { 0) #OK oldsel=${selected[$sel]} # old selection selected[$sel]=$(< $tempfile) # new selection - PSI_PREFIX="$2" update_deps -1 "$(set_difference "$oldsel" "${selected[$sel]}")" # remove dependencies - PSI_PREFIX="$2" update_deps 1 "$(set_difference "${selected[$sel]}" "$oldsel")" # add dependencies + 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 @@ -344,7 +344,7 @@ function module_picker() { # 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:-$PSI_PREFIX}" "${2:-/afs/psi.ch/sys/psi.x86_64_slp6}" + 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!" diff --git a/scripts/Bootstrap/Pmodules/environment.bash.in b/scripts/Bootstrap/Pmodules/environment.bash.in index 240d3c5..a11599f 100644 --- a/scripts/Bootstrap/Pmodules/environment.bash.in +++ b/scripts/Bootstrap/Pmodules/environment.bash.in @@ -1,16 +1,27 @@ #!/bin/bash -declare -x PSI_PREFIX=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd) +declare -x PMODULES_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd) if [[ -z ${PMODULES_VERSION} ]]; then declare -x PMODULES_VERSION="@PMODULES_VERSION@" fi -declare -x PMODULES_HOME="${PSI_PREFIX}/Tools/Pmodules/${PMODULES_VERSION}" +declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" +declare -x PMODULES_DIR="${PMODULES_HOME}" -declare -x PSI_CONFIG_DIR=$(basename $(cd $(dirname "${BASH_SOURCE}") && pwd)) -declare -x PSI_MODULES_ROOT='modulefiles' -declare -x PSI_TEMPLATES_DIR='templates' +declare -x PMODULES_CONFIG_DIR=$(basename $(cd $(dirname "${BASH_SOURCE}") && pwd)) +declare -x PMODULES_MODULEFILES_DIR='modulefiles' +declare -x PMODULES_TEMPLATES_DIR='templates' declare -x PMODULES_DEFAULT_GROUPS='Tools Programming' -declare -x PMODULES_DEFAULT_RELEASES='stable' declare -x PMODULES_DEFINED_RELEASES=':unstable:stable:deprecated:' +declare -x PMODULES_DEFAULT_RELEASES='stable' + +# legacy vars +declare -x PSI_PREFIX="${PMODULES_ROOT}" +declare -x PSI_CONFIG_DIR="${PMODULES_CONFIG_DIR}" +declare -x PSI_MODULES_ROOT="${PMODULES_MODULES_ROOT}" +declare -x PSI_TEMPLATES_DIR="${PMODULES_TEMPLATES_DIR}" +declare -x PSI_DEFAULT_FAMILIES="${PMODULES_DEFAULT_GROUPS}" +declare -x PSI_DEFAULT_RELEASES="${PMODULES_DEFAULT_RELEASES}" +declare -x PSI_DEFINED_RELEASES="${PMODULES_DEFINED_RELEASES}" + diff --git a/scripts/Bootstrap/Pmodules/libmodules.tcl b/scripts/Bootstrap/Pmodules/libmodules.tcl index 284ad9a..fbc7aa2 100644 --- a/scripts/Bootstrap/Pmodules/libmodules.tcl +++ b/scripts/Bootstrap/Pmodules/libmodules.tcl @@ -4,7 +4,7 @@ # unload modules if parent removed # -if {[info exists env(PSI_DEBUG)] && $env(PSI_DEBUG)} { +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] @@ -20,87 +20,77 @@ if {[info exists env(PSI_DEBUG)] && $env(PSI_DEBUG)} { proc debug {msg} {} } -proc set-family { family } { +debug "loading libmodules" + +proc module-addgroup { group } { global env global name global version - global implementation - debug $family - set Implementation [file join {*}${implementation}] + debug $group + set Implementation [file join {*}$::implementation] - set FAMILY [string toupper $family] - regsub -- "-" ${FAMILY} "_" FAMILY - setenv ${FAMILY} $name - setenv ${FAMILY}_VERSION $version + set GROUP [string toupper $group] + regsub -- "-" ${GROUP} "_" GROUP + setenv ${GROUP} $name + setenv ${GROUP}_VERSION $version - set ::${family} ${name} - set ::${family}_version ${version} - - lassign [split ${::family} .] caller_family caller_release - if { "${caller_release}" != "" } { - set caller_release ".${caller_release}" - } - debug "caller family: ${caller_family}, release: ${caller_release}" + set ::${group} $name + set ::${group}_version $version if { [module-info mode load] } { debug "mode is load" - append-path MODULEPATH ${::MODULE_ROOT_PATH}/${family}/${Implementation} - append-path PMODULES_USED_GROUPS ${family} + + 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] } { # remove orphan modules debug "remove orphan modules" - set FAMILY [string toupper $family] - if { [info exists env(PSI_ACTIVE_MODULES_${FAMILY})] } { - set modules [split $env(PSI_ACTIVE_MODULES_${FAMILY}) ":"] + set GROUP [string toupper $group] + if { [info exists env(PMODULES_LOADED_${GROUP})] } { + set modules [split $env(PMODULES_LOADED_${GROUP}) ":"] foreach m ${modules} { if { ${m} == "--APPMARKER--" } { continue } - debug "unloading module: $m" - module unload ${m} + if { [is-loaded ${module_name}] } { + debug "unloading module: $m" + module unload ${m} + } } } - remove-path MODULEPATH ${::MODULE_ROOT_PATH}/${family}/${Implementation} - remove-path PMODULES_USED_GROUPS ${family} + remove-path MODULEPATH $::PmodulesRoot/$group/$::PmodulesModulfilesDir/$Implementation + remove-path PMODULES_USED_GROUPS $group debug "mode=remove: $env(MODULEPATH)" debug "mode=remove: $env(PMODULES_USED_GROUPS)" } if { [module-info mode switch2] } { debug "mode=switch2" - append-path MODULEPATH ${::MODULE_ROOT_PATH}/${family}/[module-info name] - append-path PMODULES_USED_GROUPS ${family} + append-path MODULEPATH $::PmodulesRoot/$group/$::PmodulesModulfilesDir/[module-info name] + append-path PMODULES_USED_GROUPS ${group} } } +proc set-family { group } { + module-addgroup $group +} - -proc update_active_modules { family name version } { - if { ${family} == "--APPMARKER--" } { +proc _pmodules_update_loaded_modules { group name version } { + if { ${group} == "--APPMARKER--" } { return } - set FAMILY [string toupper $family] - append-path PSI_ACTIVE_MODULES_${FAMILY} "$name/$version" - remove-path PSI_ACTIVE_MODULES_${FAMILY} "--APPMARKER--" + set GROUP [string toupper $group] + debug "${GROUP} $name/$version" + append-path PMODULES_LOADED_${GROUP} "$name/$version" + remove-path PMODULES_LOADED_${GROUP} "--APPMARKER--" } -proc is-avail { m } { - debug "${m}" - set output [catch { exec "$::env(MODULESHOME)/bin/modulecmd" bash avail "${m}" } msg] - if { ${output} != "" } { - return yes - } else { - return no - } -} - - # # load dependencies, but do *not* unload dependencies # -proc load_dependencies { fname } { +proc _pmodules_load_dependencies { fname } { if { ! [ file exists ${fname} ] } { return } @@ -123,12 +113,6 @@ proc load_dependencies { fname } { debug "module already loaded: ${module_name}" continue } - debug "module avail: ${module_name}" - if { ! [is-avail "${module_name}"] } { - debug "module not in current MODULEPATH: ${module_name}" - set search_output [exec $::env(PSI_PREFIX)/config/init/extensions/search.bash "${module_name}"] - module use $::env(PSI_PREFIX)/modulefiles/[lindex ${search_output} 2] - } debug "module load: ${module_name}" module load ${module_name} } @@ -144,20 +128,17 @@ proc lreverse_n { list n } { set res } - - # # set standard environment variables # -proc set_std_environment { PREFIX name version } { +proc _pmodules_setenv { PREFIX name version } { # # Hack for supporting legacy modules - if { "${::family}" == "Legacy" } { + if { "${::group}" == "Legacy" } { debug "this is a legacy module..." return } - set NAME [string toupper $name] regsub -- "-" ${NAME} "_" NAME @@ -242,75 +223,34 @@ proc set_std_environment { PREFIX name version } { setenv ${NAME}_LIBRARY_DIR $PREFIX/lib64 } } - } -# -# What's the game plan here? -# Determine from path of module to be loaded: -# - name, -# - version -# - installation PREFIX -# -set current_modulefile [file split $ModulesCurrentModulefile] -set psi_prefix [file split $env(PSI_PREFIX)] - -# return, if module is not in $env(PSI_PREFIX) -set module_prefix [file join {*}[lrange ${current_modulefile} 0 [llength ${psi_prefix}]-1]] -if { $env(PSI_PREFIX) != ${module_prefix} } { - debug "stop sourcing: $env(PSI_PREFIX) != ${module_prefix}" - return -} - -set MODULE_ROOT_PATH $env(PSI_PREFIX)/$env(PSI_MODULES_ROOT) -set module_root_path [file split ${MODULE_ROOT_PATH}] -set len [llength $module_root_path] - -set name [lindex $current_modulefile end-1] -set version [lindex $current_modulefile end] -set family [lrange $current_modulefile $len $len] -set implementation [lrange $current_modulefile [expr $len + 1] end] - -set prefix "$psi_prefix [regsub "(.unstable|.deprecated)" $family ""] [lreverse_n [lrange $current_modulefile $len end] 2]" -set PREFIX [file join {*}$prefix] - -debug "PREFIX=$PREFIX" -debug "family of module $name: $family" - -# -# we cannot load another module with the same name -# -conflict $name - -if { [module-info mode load] } { - debug "${name}/${version}: loading ... " - if { [ string match "*.deprecated" ${family} ] == 1 } { - puts stderr "${name}/${version}: this module is deprecated!" - } - - for {set i [expr [llength ${prefix}] - 1]} {$i >= ${len}} {incr i -2} { - set info_file [lrange ${prefix} 0 $i] - lappend info_file ".info" - set fname [file join {*}${info_file}] - if { [ file exists "${fname}" ] } { - set fp [open "${fname}" r] - set info_data [read $fp] - close $fp - puts stderr ${info_data} - } - } - load_dependencies "${PREFIX}/.dependencies" +proc module-url { _url } { + set ::url ${_url} } -set_std_environment ${PREFIX} ${name} ${version} -update_active_modules ${family} ${name} ${version} +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}" @@ -326,6 +266,75 @@ proc ModulesHelp { } { } } +# +# 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/scripts/Bootstrap/Pmodules/libpmodules.bash b/scripts/Bootstrap/Pmodules/libpmodules.bash index f3db564..caadc17 100644 --- a/scripts/Bootstrap/Pmodules/libpmodules.bash +++ b/scripts/Bootstrap/Pmodules/libpmodules.bash @@ -21,7 +21,7 @@ error() { } debug() { - [[ ${PSI_DEBUG} ]] || return 0 + [[ ${PMODULES_DEBUG} ]] || return 0 log 2 "$@" } @@ -72,10 +72,9 @@ get_options() { } check_pmodules_env_vars() { - [[ -n "${PSI_PREFIX}" ]] && - [[ -n "${PSI_CONFIG_DIR}" ]] && - [[ -n "${PSI_MODULES_ROOT}" ]] && - [[ -n "${PSI_TEMPLATES_DIR}" ]] && + [[ -n "${PMODULES_ROOT}" ]] && + [[ -n "${PMODULES_CONFIG_DIR}" ]] && + [[ -n "${PMODULES_TEMPLATES_DIR}" ]] && [[ -n "${PMODULES_HOME}" ]] && [[ -n "${PMODULES_VERSION}" ]] || die 1 " Error: the module environment you are going to use as source has not been @@ -86,16 +85,15 @@ check_pmodules_directories() { local -r src_prefix="$1" [[ -d "${src_prefix}" ]] && - [[ -d "${src_prefix}/${PSI_CONFIG_DIR}" ]] && - [[ -d "${src_prefix}/${PSI_MODULES_ROOT}" ]] && - [[ -d "${src_prefix}/${PSI_TEMPLATES_DIR}" ]] && + [[ -d "${src_prefix}/${PMODULES_CONFIG_DIR}" ]] && + [[ -d "${src_prefix}/${PMODULES_TEMPLATES_DIR}" ]] && [[ -d "${src_prefix}/Tools/Pmodules/${PMODULES_VERSION}" ]] || die 1 " Error: the module environment '${src_prefix}' has not been initialized properly!" } check_pmodules_env() { check_pmodules_env_vars - check_pmodules_directories "${PSI_PREFIX}" + check_pmodules_directories "${PMODULES_ROOT}" } append_path () { diff --git a/scripts/Bootstrap/Pmodules/modmanage.bash.in b/scripts/Bootstrap/Pmodules/modmanage.bash.in index a218cde..9744cad 100755 --- a/scripts/Bootstrap/Pmodules/modmanage.bash.in +++ b/scripts/Bootstrap/Pmodules/modmanage.bash.in @@ -98,7 +98,7 @@ 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[@]}; i+=2)); do + for ((i=1; i<${#comp[@]}-1; i+=2)); do path+="/${comp[$((-i-1))]}/${comp[$((-i))]}" done echo "${path}" @@ -120,6 +120,10 @@ get_releasefile_name() { # - 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 @@ -139,10 +143,10 @@ sync_module() { "${src_prefix}/${rel_module_prefix}/" \ "${target_prefix}/${rel_module_prefix}/" || return $? fi - local -r src_modulefile="${src_prefix}/${PSI_MODULES_ROOT}/${rel_modulefile}" - local -r src_releasefile="${src_prefix}/${PSI_MODULES_ROOT}/${rel_releasefile}" - local -r target_modulefile="${target_prefix}/${PSI_MODULES_ROOT}/${rel_modulefile}" - local -r target_releasefile="${target_prefix}/${PSI_MODULES_ROOT}/${rel_releasefile}" + 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 @@ -161,17 +165,6 @@ sync_module() { $DRY rsync --links --perms --recursive \ "${src_releasefile}" "${target_releasefile}" || return $? fi - - # if modulefile is a sym-link, sync link target file - #if [[ -L "${src_modulefile}" ]]; then - # local canonical_fname=$(readlink -f "${src_modulefile}") - # local src_template=$(dirname "${canonical_fname}") - # local modulename=$(basename "${src_template}") - # local target_template="${target_prefix}/${PSI_TEMPLATES_DIR}/${modulename}" - # $DRY rsync --links --perms --recursive --delete \ - # "${src_template}/" \ - # "${target_template}" - #fi } # @@ -181,15 +174,15 @@ sync_module() { # $2: target prefix of Pmodule environment # sync_config() { - src="$1/${PSI_CONFIG_DIR}/" - dst="$2/${PSI_CONFIG_DIR}/" + src="$1/${PMODULES_CONFIG_DIR}/" + dst="$2/${PMODULES_CONFIG_DIR}/" $DRY rsync --recursive --links --perms --delete \ "${src}" "${dst}" || die 1 "Error: synch operation failed!" sed -i.bak "s/PMODULES_VERSION=\(.*\)/PMODULES_VERSION=${PMODULES_VERSION}/" "${dst}/environment.bash" echo - src="$1/${PSI_TEMPLATES_DIR}/" - dst="$2/${PSI_TEMPLATES_DIR}/" + src="$1/${PMODULES_TEMPLATES_DIR}/" + dst="$2/${PMODULES_TEMPLATES_DIR}/" $DRY rsync --recursive --links --perms --delete \ "${src}" "${dst}" || die 1 "Error: synch operation failed!" echo @@ -271,11 +264,11 @@ subcommand_init() { echo " Attempting to create a minimal module environment from the -environment at '${PSI_PREFIX}' +environment at '${PMODULES_ROOT}' " init_pmodules_environment() { - local -r src_prefix="${PSI_PREFIX}" + local -r src_prefix="${PMODULES_ROOT}" local -r target_prefix=$1 local src='' local dst='' @@ -292,21 +285,16 @@ environment at '${PSI_PREFIX}' echo echo "Syncing configuration ..." - sync_config "${PSI_PREFIX}" \ + sync_config "${PMODULES_ROOT}" \ "${target_prefix}" || die 1 "Error: configuration synchronization failed!" - dst="${target_prefix}/${PSI_MODULES_ROOT}/" - echo "Creating root directory '${dst}' for module hierarchy ..." - $DRY mkdir -p "${dst}" - echo - echo "Syncing Pmodules ${PMODULES_VERSION} from '${src_prefix}' to '${target_prefix}'..." sync_module "Tools/Pmodules/${PMODULES_VERSION}" \ "${src_prefix}" \ "${target_prefix}" || die 1 "Error: sync Pmodules failed!" echo - dst="${target_prefix}/${PSI_CONFIG_DIR}/environment.bash" + 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}" @@ -320,7 +308,7 @@ environment at '${PSI_PREFIX}' 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/${PSI_CONFIG_DIR}/profile.bash" + echo " source /opt/psi/${PMODULES_CONFIG_DIR}/profile.bash" } umask 022 @@ -336,7 +324,7 @@ subcommand_install() { local -a releases=() local -a module_pattern=() local -r src_prefix="${PMODULES_INSTALL_SOURCE}" - local -r target_prefix="${PSI_PREFIX}" + local -r target_prefix="${PMODULES_ROOT}" opts=$(get_options -o hf -l dry-run -l force -l with: -l release: -l help -l src: -- "$@") if [[ $? != 0 ]]; then @@ -396,7 +384,7 @@ subcommand_install() { (( n == 0 )) && die 0 "Nothing to install..." echo -e "The following modules will be installed/updated:\n" 1>&2 for key in "${!modules_to_install[@]}"; do - echo " ${key}" 1>&2 + echo " ${key/\/${PMODULES_MODULEFILES_DIR}\//: }" 1>&2 done echo 1>&2 get_YN_answer "Do you want to continue? [n] " || die 1 "Aborting..." @@ -415,7 +403,7 @@ subcommand_install() { } subcommand_sync() { - [[ -z "${PSI_PREFIX}" ]] && die 1 "Error: No current module environment is configured!" + [[ -z "${PMODULES_ROOT}" ]] && die 1 "Error: No current module environment is configured!" local delete=false local opts='' @@ -456,10 +444,10 @@ subcommand_sync() { unset -v opts if [[ -z "${dst_prefix}" ]]; then - dst_prefix="${PSI_PREFIX}" + dst_prefix="${PMODULES_ROOT}" fi ( - PSI_PREFIX="${dst_prefix}" check_pmodules_env || \ + PMODULES_ROOT="${dst_prefix}" check_pmodules_env || \ die 1 "Error: invalid destination modules environment!" ) || die 1 "Giving up..." @@ -468,12 +456,12 @@ subcommand_sync() { die 1 "Error: no source module environment was specified!" fi ( - PSI_PREFIX="${src_prefix}" check_pmodules_env || \ + PMODULES_ROOT="${src_prefix}" check_pmodules_env || \ die 1 "Error: invalid source modules environment!" ) || die 1 "Giving up..." [[ "$( cd "$src_prefix"; pwd -P )" == "$( cd "$dst_prefix"; pwd -P )" ]] && \ die 1 "Error: source and destination are equal!" - local modbin=${PMODULES_HOME#"${PSI_PREFIX}/"}/bin/modulecmd.tcl + 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}" ]] || \ @@ -504,7 +492,7 @@ subcommand_sync() { exit 1 } - local -a destination_modules=( $(cd "${dst_prefix}/${PSI_MODULES_ROOT}"; find -L . -type f | while read f; do n=${f##*/}; [[ "${n:0:1}" == "." ]] || echo ${f#./}; done) ) + 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 function set_difference() { # $1 \ $2 diff --git a/scripts/Bootstrap/Pmodules/modsync.bash b/scripts/Bootstrap/Pmodules/modsync.bash index b4e83e2..988f8f3 100755 --- a/scripts/Bootstrap/Pmodules/modsync.bash +++ b/scripts/Bootstrap/Pmodules/modsync.bash @@ -25,8 +25,8 @@ function die() { # check if directory $1 is a valid prefix function is_module_prefix() { if [[ -d "$1" ]] && - [[ -d "$1/$PSI_CONFIG_DIR" ]] && - [[ -d "$1/$PSI_MODULES_ROOT" ]] + [[ -d "$1/$PMODULES_CONFIG_DIR" ]] && + [[ -d "$1/$PMODULES_MODULEFILES_DIR" ]] then return 0 fi @@ -69,7 +69,7 @@ function get_options() { dst_dir=$( cd "$dst_dir"; pwd -P ) [[ "$src_dir" == "$dst_dir" ]] && { die "same source and destination installations"; } local modbin=$( cd "$PMODULES_HOME"; pwd -P ) - local prefix=$( cd "$PSI_PREFIX"; 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 ) @@ -114,9 +114,9 @@ function delete_module() { [[ -z "$modpath" ]] && { die "Unable to retrieve module file and installation paths"; } - echo "rm -v \"$3/$PSI_MODULES_ROOT/$2\"" - echo "rm -v \"$3/$PSI_MODULES_ROOT/$( get_release_path $2 )\"" - echo "rmdir -vp \"$( dirname "$3/$PSI_MODULES_ROOT/$2" )\"" + 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 @@ -133,11 +133,11 @@ function copy_module() { fi local modpath=$( get_modpath "$2" ) [[ -z "$modpath" ]] && { die "Unable to retrieve module file and installation paths"; } - install -d $( dirname "$3/$PSI_MODULES_ROOT/$2" ) + install -d $( dirname "$3/$PMODULES_MODULEFILES_DIR/$2" ) ( cd $3 - rsync --links --perms --relative --verbose "$PSI_MODULES_ROOT/$2" "$4" - rsync --links --perms --relative --verbose "$PSI_MODULES_ROOT/$( get_release_path "$2" )" "$4" + 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 @@ -156,7 +156,7 @@ function sync_modules() { local delete="${options[3]}" unset options - local profile_script="$src_dir/$PSI_CONFIG_DIR/profile.bash" + local profile_script="$src_dir/$PMODULES_CONFIG_DIR/profile.bash" [[ -r "$profile_script" ]] || { die "Unable to find profile script of installation $profile_script"; } @@ -188,7 +188,7 @@ function sync_modules() { module_picker "$dst_dir" < <("$search_script" bash search --no-header -a 2>&1) - local -a destination_modules=( $(cd "$dst_dir/$PSI_MODULES_ROOT"; find -L . -type f | while read f; do echo ${f#./}; done) ) + 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 function set_difference() { # $1 \ $2 @@ -217,13 +217,13 @@ function sync_modules() { local -a modules_copy=( $(set_difference "${selected_modules[*]}" "${destination_modules[*]}") ) [[ -z $modules_copy ]] || { if [[ "$dryrun" != "false" ]]; then - echo "(dryrun) update: $dst_dir/$PSI_CONFIG_DIR from $src_dir/$PSI_CONFIG_DIR" 1>&2 + 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 "$PSI_CONFIG_DIR" "$dst_dir" - echo "updated: $PSI_CONFIG_DIR from $src_dir" 1>&2 + 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 diff --git a/scripts/Bootstrap/Pmodules/modulecmd.in b/scripts/Bootstrap/Pmodules/modulecmd.in index 1bb5692..63371be 100755 --- a/scripts/Bootstrap/Pmodules/modulecmd.in +++ b/scripts/Bootstrap/Pmodules/modulecmd.in @@ -5,7 +5,7 @@ # we have to unset CDPATH, otherwise 'cd' prints the directoy! unset CDPATH -#declare -r CMD=$(basename "$0") +# used inside output text only declare -r CMD='module' declare -r bindir=$(cd $(dirname "$0") && pwd) @@ -18,9 +18,9 @@ declare -r version='@PMODULES_VERSION@' declare -r modulecmd="${bindir}/modulecmd.tcl" declare -rx TCL_LIBRARY="${libdir}/tcl8.6" -declare -rx PSI_LIBMODULES="${libdir}/libmodules.tcl" -declare -r modulepath_root="${PSI_PREFIX}/${PSI_MODULES_ROOT}" +# required by pre 0.99.3 modulefiles +declare -rx PSI_LIBMODULES="${TCL_LIBRARY}/libmodules.tcl" # :FIXME: this is not save, if a component contains spaces. declare -ra modulepath=( ${MODULEPATH//:/ } ) @@ -28,8 +28,8 @@ declare -ra modulepath=( ${MODULEPATH//:/ } ) declare verbosity_lvl=${PMODULES_VERBOSITY:-'verbose'} shopt -s nullglob -declare -a FAMILIES='()' -declare -A HIERARCHY_DEPTHS='()' +declare -a Groups='()' +declare -A HierarchyDepths='()' save_env() { local s='' @@ -48,7 +48,7 @@ export_env() { done } -trap 'save_env FAMILIES HIERARCHY_DEPTHS USED_RELEASES PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES PMODULES_DEFAULT_RELEASES' EXIT +trap 'save_env Groups HierarchyDepths UsedReleases PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES PMODULES_DEFAULT_RELEASES' EXIT print_version() { echo " @@ -74,8 +74,8 @@ SUBCOMMANDS: + display|show modulefile [modulefile ...] + avail [ switches ] [modulefile [modulefile ...]] + search [ switches ] [ args ] - + use [ switches ] [dir|family|release ...] - + unuse dir|family|release [dir|family|release ...] + + use [ switches ] [dir|group|release ...] + + unuse dir|group|release [dir|group|release ...] + refresh + purge + list [ switches ] @@ -99,7 +99,7 @@ USAGE: module add modulefile... module load modulefile... Load modulefile(s) into the shell environment. Loading a - 'family-head' will extend the MODULEPATH. E.g.: 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 @@ -116,7 +116,8 @@ USAGE: module rm modulefile... moudle unload modulefile... Remove modulefile(s) from the shell environment. Removing - a 'family-head' will also unload all modules in the family. + a 'group-head' will also unload all modules belonging to + this group. " 1>&2 die 1 } @@ -225,7 +226,7 @@ SWITCHES: subcommand_help_use() { echo " USAGE: - module use [-a|--append|-p|--prepend] [directory|family|release...] + 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 @@ -235,7 +236,7 @@ USAGE: prepended or appended to the module search path. The default is to prepend the directory. - With a family as argument, the modules in this family will + With a group as argument, the modules in this group will be made available. With a release as argument, this modules with this release @@ -251,8 +252,8 @@ SWITCHES: subcommand_help_unuse() { echo " -unuse directory|family|release... - Remove the given directory, family or release from the search +unuse directory|group|release... + Remove the given directory, group or release from the search path. " 1>&2 die 1 @@ -395,8 +396,8 @@ USAGE: # # get release of module # Note: -# - the release of a modulefile outside ${PSI_PREFIX} is 'stable' -# - the release of a modulefile inside ${PSI_PREFIX} without a +# - 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: @@ -405,13 +406,13 @@ USAGE: get_release() { local -r modulefile=$1 - # is modulefile outside ${PSI_PREFIX}? - if [[ ! ${modulefile} =~ ${PSI_PREFIX} ]]; then + # is modulefile outside ${PMODULES_ROOT}? + if [[ ! ${modulefile} =~ ${PMODULES_ROOT} ]]; then echo 'stable' return 0 fi - # we are inside ${PSI_PREFIX} + # we are inside ${PMODULES_ROOT} local -r releasefile="${modulefile%/*}/.release-${modulefile##*/}" if [[ -r ${releasefile} ]]; then # read releasefile, remove empty lines, spaces etc @@ -430,13 +431,13 @@ is_release() { } is_used_release() { - [[ ":${USED_RELEASES}:" =~ :$1: ]] + [[ ":${UsedReleases}:" =~ :$1: ]] } -declare used_families=":${PMODULES_USED_GROUPS}:" +declare used_groups=":${PMODULES_USED_GROUPS}:" -is_used_family() { - [[ ${used_families} =~ :$1: ]] +is_used_group() { + [[ ${used_groups} =~ :$1: ]] } module_is_loaded() { @@ -571,7 +572,7 @@ subcommand_load() { # is_loadable() { release=$( get_release "$1" ) - [[ :${USED_RELEASES}: =~ ${release} ]] && return 0 + [[ :${UsedReleases}: =~ ${release} ]] && return 0 return 1 } @@ -599,7 +600,7 @@ subcommand_load() { # The variable 'm' in function 'subcommand_load()' may be set. # is_available() { - local -r m=$1 + local m=$1 # handle the case of an absolute or relative file- or link-name if [[ -f ${m} ]]; then @@ -609,7 +610,7 @@ subcommand_load() { fi is_modulefile "${m}" || return 2 is_loadable "${m}" || return 3 - if [[ "${m}" =~ "${PSI_PREFIX}" ]]; then + if [[ "${m}" =~ "${PMODULES_ROOT}" ]]; then for dir in "${modulepath[@]}"; do [[ "${m}" =~ "${dir}" ]] && return 0 done @@ -674,7 +675,7 @@ subcommand_load() { while read -a line; do output[n]="module load ${line[@]:3} ${line[0]}" release[n]=${line[1]} - if [[ ":${USED_RELEASES}:" =~ "${release[n]}" ]]; then + if [[ ":${UsedReleases}:" =~ "${release[n]}" ]]; then loadable[n]='yes' else loadable[n]='no' @@ -778,7 +779,7 @@ subcommand_show() { get_available_modules() { local -r dir=$1 local -r module=$2 - local -r use_releases=${3:-${USED_RELEASES}} + local -r use_releases=${3:-${UsedReleases}} local -a mods=() while read mod; do local release=$( get_release "${dir}/${mod}" ) @@ -802,7 +803,9 @@ subcommand_avail() { cols=$(tput cols) output_header() { - local -r caption=${dir/${modulepath_root}\/} + 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 @@ -932,62 +935,62 @@ subcommand_avail() { done } -# get available family groups +# get available groups # $1: root of modulefile hierarchy # -get_families () { - local -r module_hierarchy_root="$1" - if [[ -d "${module_hierarchy_root}" ]]; then - { - cd "${module_hierarchy_root}" - for f in *; do - FAMILIES+=( $f ) - done - } - fi -} - -# -# $1: root of modulefile hierarchy -get_hierarchy_depth () { - local -r module_hierarchy_root="$1" +get_groups () { + local -r root="$1" { - cd "${module_hierarchy_root}" - for family in "${FAMILIES[@]}"; do - local tmp=$(find "${family}/" -depth -type f -o -type l | head -1) - local -a tmp2=( ${tmp//\// } ) - local depth=${#tmp2[@]} - let depth-=3 - HIERARCHY_DEPTHS[$family]=${depth} + cd "${root}" + for f in [A-Z]*; do + Groups+=( $f ) done }; } # -# use [-a|--append|-p|--prepend] [directory|family|release...] +# $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}/modulefiles" -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 (( ${#FAMILIES[@]} == 0 )); then - get_families "${modulepath_root}" - get_hierarchy_depth "${modulepath_root}" + if (( ${#Groups[@]} == 0 )); then + get_groups "${PMODULES_ROOT}" + get_hierarchy_depth "${PMODULES_ROOT}" fi print_info() { local f local r info "Used groups:" - for f in ${used_families//:/ }; do + for f in ${used_groups//:/ }; do info "\t${f}" done info "\nUnused groups:" - for family in "${FAMILIES[@]}"; do - local -i depth=${HIERARCHY_DEPTHS[$family]} - if ! is_used_family "${family}" && (( depth == 0 )); then - info "\t${family}" + local _group + for _group in "${Groups[@]}"; do + local -i depth=${HierarchyDepths[${_group}]} + if ! is_used_group "${_group}" && (( depth == 0 )); then + info "\t${_group}" fi done info "\nUsed releases:" - for r in ${USED_RELEASES//:/ }; do + for r in ${UsedReleases//:/ }; do info "\t${r}" done info "\nUnused releases:" @@ -1000,7 +1003,7 @@ subcommand_use() { info "\nAdditonal directories in MODULEPATH:" let n=0 for (( i=0; i<${#modulepath[@]}; i++)); do - if [[ ! ${modulepath[i]} =~ ${PSI_PREFIX} ]]; then + if [[ ! ${modulepath[i]} =~ ${PMODULES_ROOT} ]]; then info "\t${modulepath[i]}" let n+=1 fi @@ -1025,20 +1028,21 @@ subcommand_use() { # ... # elif is directory # ... + local modulfiles_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* - append_path USED_RELEASES "${arg}" - elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulepath_root}/${arg} ]]; then - if (( ${HIERARCHY_DEPTHS[$arg]} != 0 )); then + append_path UsedReleases "${arg}" + elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulefiles_dir} ]]; then + if (( ${HierarchyDepths[$arg]} != 0 )); then die 3 "${CMD} ${0##_}: cannot add group ${arg} to module path" fi append_path PMODULES_USED_GROUPS "${arg}" - dirs_to_add+=( ${modulepath_root}/${arg} ) - elif [[ ${arg} =~ ^${modulepath_root} ]]; then + dirs_to_add+=( ${modulefiles_dir} ) + elif [[ ${arg} =~ ^${PMODULES_ROOT} ]]; then die 3 "${CMD} ${0##_}: illegal directory: ${arg}" elif [[ -d ${arg} ]]; then local normalized_dir=$(cd "${arg}" && pwd) @@ -1066,7 +1070,7 @@ subcommand_use() { } # -# unuse directory|family|release... +# unuse directory|group|release... # subcommand_unuse() { local opts='' @@ -1087,18 +1091,19 @@ subcommand_unuse() { # ... # elif is directory # ... + local modulfiles_dir="${PMODULES_ROOT}/${arg}/${PMODULES_MODULEFILES_DIR}" if is_release "${arg}"; then - remove_path USED_RELEASES "${arg}" - elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulepath_root}/${arg} ]]; then - if (( ${HIERARCHY_DEPTHS[$arg]} != 0 )); then + remove_path UsedReleases "${arg}" + elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulefiles_dir} ]]; then + if (( ${HierarchyDepths[$arg]} != 0 )); then die 3 "${CMD} ${0##_}: cannot remove group ${arg} from module path" fi remove_path PMODULES_USED_GROUPS "${arg}" - dirs_to_remove+=( ${modulepath_root}/${arg} ) + dirs_to_remove+=( ${modulefiles_dir}/${arg} ) elif [[ -d ${arg} ]]; then local normalized_dir=$(cd "${arg}" && pwd) dirs_to_remove+=( ${normalized_dir} ) - elif [[ ${arg} =~ ^${modulepath_root} ]]; then + elif [[ ${arg} =~ ^${PMODULES_ROOT} ]]; then die 3 "${CMD} ${0##_}: illegal directory: ${arg}" elif [[ ${arg} =~ "-*" ]]; then die 3 "${CMD} ${0##*_}: illegal option: ${arg}" @@ -1173,6 +1178,26 @@ subcommand_list() { "${modulecmd}" "${shell}" list "${opts}" } +pmodules_init() { + 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 + append_path MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}" + append_path PMODULES_USED_GROUPS "${group}" + done + declare -ag Groups='()' + declare -Ag HierarchyDepths='()' + declare -g UsedReleases='' + for r in ${PMODULES_DEFAULT_RELEASES//:/ }; do + append_path UsedReleases "${r}" + done + +} + # # clear # @@ -1190,18 +1215,7 @@ subcommand_clear() { ;; esac done - LOADEDMODULES='' - PMODULES_USED_GROUPS='' - MODULEPATH='' - _LMFILES_='' - for f in ${PMODULES_DEFAULT_GROUPS}; do - append_path MODULEPATH "${PSI_PREFIX}/${PSI_MODULES_ROOT}/$f" - append_path PMODULES_USED_GROUPS "${f}" - done - USED_RELEASES='' - for r in ${PMODULES_DEFAULT_RELEASES//:/ }; do - append_path USED_RELEASES "${r}" - done + pmodules_init export_env LOADEDMODULES PMODULES_USED_GROUPS MODULEPATH _LMFILES_ } @@ -1216,7 +1230,6 @@ subcommand_search() { local _print_modulefiles='no' local use_releases=':' local -r fmt="%-20s %-10s %-12s %-s\n" - local module_hierarchy_root='' # no args print_header() { @@ -1233,24 +1246,24 @@ subcommand_search() { # we must write temporary results to a file for sorting local -r tmpfile=$( mktemp /tmp/$(basename $0).XXXXXX ) \ || die 1 "Oops: unable to create tmp file!" - local family + local _group # loop over all groups - for family in "${FAMILIES[@]}"; do - local depth=${HIERARCHY_DEPTHS[$family]} - # get all potential directories of family $f with module-files + for _group in "${Groups[@]}"; do + local depth=${HierarchyDepths[${_group}]} + # get all potential directories of group with module-files local mpaths=( $(find \ - "${module_hierarchy_root}/${family}/" \ + "${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/${module_hierarchy_root}}" + local p="${mpath/${src_prefix}}" p=( ${p//\// } ) local deps=() local -i i - for ((i=1; i < ${#p[@]}; i+=2)); do + for ((i=2; i < ${#p[@]}; i+=2)); do deps+=( ${p[i]}/${p[i+1]} ) done local requires=${deps[@]} @@ -1264,7 +1277,7 @@ subcommand_search() { [[ ${#mods[@]} == 0 ]] && continue for (( i=0; i<${#mods[@]}; i+=2 )); do printf "${fmt}" ${mods[i]} "${mods[i+1]}" \ - ${family} "${requires}" >> "${tmpfile}" + ${_group} "${requires}" >> "${tmpfile}" done done done @@ -1272,7 +1285,10 @@ subcommand_search() { 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 @@ -1337,11 +1353,11 @@ subcommand_search() { shift done if [[ -z "${src_prefix}" ]]; then - src_prefix="${PSI_PREFIX}" + src_prefix="${PMODULES_ROOT}" fi if [[ "${use_releases}" == ":" ]]; then - use_releases=":${USED_RELEASES}:" + use_releases=":${UsedReleases}:" fi [[ "${_print_header}" == "yes" ]] && print_header @@ -1349,10 +1365,9 @@ subcommand_search() { modules+=( '' ) fi - module_hierarchy_root="${src_prefix}/${PSI_MODULES_ROOT}" - if (( ${#FAMILIES[@]} == 0 )) || [[ ${src_prefix} != ${PSI_PREFIX} ]]; then - get_families "${module_hierarchy_root}" - get_hierarchy_depth "${module_hierarchy_root}" + if (( ${#Groups[@]} == 0 )) || [[ ${src_prefix} != ${PMODULES_ROOT} ]]; then + get_groups "${src_prefix}" + get_hierarchy_depth "${src_prefix}" fi for module in "${modules[@]}"; do @@ -1389,7 +1404,7 @@ subcommand_help() { subcommand_help_${arg} else # :FIXME: print help of newest *available* module - # (respecting USED_RELEASES) + # (respecting UsedReleases) subcommand_generic1plus help "${arg}" fi } @@ -1456,6 +1471,8 @@ subcommand_initclear() { if [[ -n ${PMODULES_ENV} ]]; then eval "$("${PMODULES_HOME}/bin/base64" -d <<< "${PMODULES_ENV}" 2>/dev/null)" +else + pmodules_init fi case $1 in diff --git a/scripts/Bootstrap/Pmodules/profile.bash b/scripts/Bootstrap/Pmodules/profile.bash index 67db682..b8b9bd3 100644 --- a/scripts/Bootstrap/Pmodules/profile.bash +++ b/scripts/Bootstrap/Pmodules/profile.bash @@ -15,12 +15,12 @@ unset _init_env_file ############################################################################ # check configuration # -if [[ -z ${PSI_PREFIX} ]]; then +if [[ -z ${PMODULES_PREFIX} ]]; then echo "Oops: Pmodules prefix not set." 1>&2 return 1 fi -if [[ ! -d ${PSI_PREFIX} ]]; then - echo "Oops: ${PSI_PREFIX}: Set as Pmodules prefix, but this is not a directory." 1>&2 +if [[ ! -d ${PMODULES_PREFIX} ]]; then + echo "Oops: ${PMODULES_PREFIX}: Set as Pmodules prefix, but this is not a directory." 1>&2 return 1 fi if [[ -z ${PMODULES_VERSION} ]]; then diff --git a/scripts/Bootstrap/Pmodules/profile.csh b/scripts/Bootstrap/Pmodules/profile.csh index 683c306..0aee6f5 100755 --- a/scripts/Bootstrap/Pmodules/profile.csh +++ b/scripts/Bootstrap/Pmodules/profile.csh @@ -15,16 +15,16 @@ unset _init_env_file ############################################################################ # check configuration # -if ( ! $?PSI_PREFIX ) then +if ( ! $?PMODULES_PREFIX ) then echo "Oops: Pmodules prefix not set." return 1 endif -if ( "$PSI_PREFIX" == "" ) then +if ( "$PMODULES_PREFIX" == "" ) then echo "Oops: Pmodules prefix set to empty string!" endif -if ( ! -d ${PSI_PREFIX} ) then - echo "Oops: ${PSI_PREFIX}: Set as Pmodules prefix, but this is not a directory!" +if ( ! -d ${PMODULES_PREFIX} ) then + echo "Oops: ${PMODULES_PREFIX}: Set as Pmodules prefix, but this is not a directory!" return 1 endif diff --git a/scripts/Bootstrap/Pmodules_version.conf b/scripts/Bootstrap/Pmodules_version.conf index a0bf643..edff869 100644 --- a/scripts/Bootstrap/Pmodules_version.conf +++ b/scripts/Bootstrap/Pmodules_version.conf @@ -1,4 +1,4 @@ -declare -x PMODULES_VERSION=0.99.2 +declare -x PMODULES_VERSION=0.99.3 declare -x MODULES_VERSION=3.2.10 declare -a COMPILER_VERSIONS=( 'gcc/4.7.4' 'gcc/4.8.3' 'gcc/4.8.4' 'gcc/4.9.2' ) diff --git a/scripts/Bootstrap/install_pmodules.sh b/scripts/Bootstrap/install_pmodules.sh index a6fb606..437eabf 100755 --- a/scripts/Bootstrap/install_pmodules.sh +++ b/scripts/Bootstrap/install_pmodules.sh @@ -13,7 +13,7 @@ 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.in" > "${SRC_DIR}/modulecmd" -sed "${sed_cmd}" "${SRC_DIR}/modmanage.in" > "${SRC_DIR}/modmanage.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" @@ -33,4 +33,9 @@ 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}/libmodules.tcl" "${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/scripts/Bootstrap/mkindex.tcl b/scripts/Bootstrap/mkindex.tcl new file mode 100755 index 0000000..297872f --- /dev/null +++ b/scripts/Bootstrap/mkindex.tcl @@ -0,0 +1,3 @@ +#!/usr/bin/env tclsh + +auto_mkindex . *.tcl