Commit 9b106fd4 authored by gsell's avatar gsell

Bootstrap (building Pmodules itself) removed

parent 2601c606
environment.bash
modulecmd.bash
modmanage.bash
#!/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:
#!/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 <pattern>
#
# To replace a dir:
# std::replace_path PATH <pattern> /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:
#
# 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
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
This diff is collapsed.
#!/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}"
#!/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'
#
# :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]