Commit f9786954 authored by gsell's avatar gsell
Browse files

Bootstrap code added; put everything into Pmodules/VERSION

parent e1b0cd10
#!/bin/bash
#set -o functrace
source "$(dirname $0)/../../lib/libem.bash"
TCL_DIR="${PSI_PREFIX}/Tools/Pmodules/0.99.0"
PATH="${TCL_DIR}/bin:${PATH}"
function em.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="${PSI_PREFIX}/${PSI_MODULES_ROOT}" \
--with-tcl="${TCL_DIR}/lib" \
--without-x \
--disable-versioning \
|| exit 1
}
function em.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
em.add_to_family 'Tools'
em.make_all
# Local Variables:
# mode: sh
# sh-basic-offset: 8
# tab-width: 8
# End:
../Programming/Tcl.build
\ No newline at end of file
#!/bin/bash
if [ ${BASH_VERSINFO:-0} -lt 3 ]; then
echo "BASH version ${BASH_VERSION} ist not supported! You need at least version 3..."
return
fi
if [ "${LOADEDMODULES:-}" = "" ]; then
declare -x LOADEDMODULES=
fi
if [[ -r "${PSI_BASH_COMPLETION}" ]]; then
source "${PSI_BASH_COMPLETION}"
fi
module() {
local -r modulecmd="${PMODULES_HOME}/bin/modulecmd"
local -a args=()
local -a switches=()
local -a sub_switches=()
local subcommand=''
while (( $# > 0 )); do
case $1 in
-u|--userlvl )
switches+=( $1 $2 )
shift 2
;;
-* )
switches+=( $1 )
shift
;;
[a-z]* )
subcommand=$1
shift
break
;;
esac
done
while (( $# > 0 ));do
case $1 in
-* )
sub_switches+=( $1 )
;;
[a-zA-Z]* )
args+=( $1 )
;;
esac
shift
done
if [[ ${subcommand} == '' ]]; then
subcommand='help'
fi
if (( ${#args} == 0 )); then
args+=( '' )
fi
for arg in "${args[@]}"; do
eval $( "${modulecmd}" bash ${switches[@]} "${subcommand}" "${sub_switches[@]}" "${arg}" )
done
}
export -f module
# Local Variables:
# mode: sh
# sh-basic-offset: 8
# tab-width: 8
# End:
../System/bash.build
\ No newline at end of file
#
# Bash commandline completion (bash 3.0 and above) for Modules 3.2.10
#
_module_avail() {
"${MODULESHOME}"/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
#!/bin/bash
declare -r BASE_DIR=$(cd "$(dirname $0)/../.." && pwd)
declare -r BOOTSTRAP_DIR="${BASE_DIR}/scripts/Bootstrap"
${BOOTSTRAP_DIR}/build_pmodules.sh
${BOOTSTRAP_DIR}/install_pmodules.sh
#!/bin/bash
declare -r BASE_DIR=$(cd "$(dirname $0)/../.." && pwd)
declare -r BOOTSTRAP_DIR="${BASE_DIR}/scripts/Bootstrap"
source "/opt/psi/config/environment.bash"
source "${BASE_DIR}/config/pmodules_version.conf"
${BOOTSTRAP_DIR}/gettext.build --bootstrap
${BOOTSTRAP_DIR}/getopt.build --bootstrap
${BOOTSTRAP_DIR}/dialog.build --bootstrap
${BOOTSTRAP_DIR}/bash.build --bootstrap
${BOOTSTRAP_DIR}/Tcl.build --bootstrap
# we have to remove the init directory - otherwise the next build will fail...
rm -rf "${PMODULES_HOME}/init"
${BOOTSTRAP_DIR}/Modules.build --bootstrap
mv -v "${PMODULES_HOME}/bin/modulecmd" "${PMODULES_HOME}/bin/modulecmd.tcl"
#!/usr/bin/env bash
# Hardcoded path to dialog software
LOCAL_DIALOGHOME=Tools/dialog/1.2.1
DIALOG_CMD=$PSI_PREFIX/$LOCAL_DIALOGHOME/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
function 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[@]}
}
function 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
}
function 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
function 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
}
function mod_path() { # $1: module info index
local -i i
local -a m=(${modlist[$1]})
local res="$PSI_PREFIX/${fmmap[${m[0]%%/*}]}/${m[0]}"
for (( i=${#m[@]}; i>3; i-- )); do
res+="/${m[i-1]}"
done
echo "$res"
}
function 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[@]}"
}
function 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
}
function 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
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
uidmap[$(unique_id $i)]=$i
depcnt[i]=0
[[ -z ${fmmap[$name]} ]] && { fmmap[$name]=${mc[2]}; }
relmap[i]=${mc[1]}
i+=1
done
}
function 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 "${PSI_PREFIX}/${PSI_MODULES_ROOT}")
}
function 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"
}
function 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
pushd "$1/$PSI_MODULES_ROOT" > /dev/null || exit 1;
trap "popd" EXIT
for m in $(find . -follow -type f); do
uid=""
mpc=( ${m//\// } )
for ((i=2; i<${#mpc[@]}-2; i+=2)); do
uid+="${mpc[i]}/${mpc[i+1]} "
done
uid+="${mpc[-2]}/${mpc[-1]}"
PSI_PREFIX="$1" select_uid "$uid"
done
popd
trap - EXIT
}
function 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
}
function 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 $?
}
function module_id() { # $@: module info components
echo "$1 ${@:4}"
}
function module_release() { # $@: module info components
echo "$2"
}
function 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
function module_out() { # $1: module info index
local -a args=(${modlist[$1]})
echo "${args[@]}"
}
# "$1": prefix for preselected modules
function module_picker() {
find_families
find_modules
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
update_deps -1 "$(set_difference "$oldsel" "${selected[$sel]}")" # remove dependencies
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 ${PSI_PREFIX}/${PSI_CONFIG_DIR}/modulecmd.bash ]]; then
module_picker "$1" < <(${PSI_PREFIX}/${PSI_CONFIG_DIR}/modulecmd.bash bash search --no-header -a 2>&1)
else
echo "ERROR: module environment configuration: ${PSI_PREFIX}/${PSI_CONFIG_DIR}/modulecmd.bash is not an executable!"
fi
}
../Tools/dialog.build
\ No newline at end of file
../Tools/gettext.build
\ No newline at end of file
#!/usr/bin/env bash
function usage() {
PROG=$(basename $0)
echo "Usage: $PROG --dir=<directory> [--user=<user>]"
echo " Initializes a local module environment in <directory>"
echo " for user <user>. <directory> must not exist yet."
echo " The <user> parameter must only be present if"
echo " $PROG is executed as root."
}
declare force='no'
while (($# > 0)); do
if [[ "${1#--dir}" != "$1" ]]; then
option="${1#--dir}"
option="${option#=}"
[[ -z "$option" ]] && { shift; option="$1"; }
ENV_DIR="$option"
elif [[ "${1#--user}" != "$1" ]]; then
option="${1#--user}"
option="${option#=}"
[[ -z "$option" ]] && { shift; option="$1"; }
ENV_USER="$option"