Merge branch 'master' of gitorious.psi.ch:pmodules/src
Conflicts: scripts/Bootstrap/Pmodules/libpmodules.bash scripts/Bootstrap/Pmodules/modmanage.in
This commit is contained in:
@@ -90,27 +90,50 @@ prepend_path () {
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Replace or remove a directory in a path variable.
|
||||
#
|
||||
# To remove a dir:
|
||||
# replace_path PATH <pattern>
|
||||
#
|
||||
# To replace a dir:
|
||||
# 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
|
||||
#
|
||||
function 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|:$||')
|
||||
}
|
||||
|
||||
module purge
|
||||
|
||||
#############################################################################
|
||||
# setup environment
|
||||
#
|
||||
if [[ -z ${LOADEDMODULES} ]]; then
|
||||
declare -x LOADEDMODULES=''
|
||||
fi
|
||||
|
||||
if [[ -z ${MODULEPATH} ]]; then
|
||||
declare -x MODULEPATH=''
|
||||
fi
|
||||
|
||||
if [[ -z ${PSI_LOADEDFAMILIES} ]]; then
|
||||
declare -x PSI_LOADEDFAMILIES=''
|
||||
fi
|
||||
declare -x LOADEDMODULES=''
|
||||
declare -x PSI_LOADEDFAMILIES=''
|
||||
declare -x MODULEPATH=''
|
||||
for f in ${PSI_DEFAULT_FAMILIES}; do
|
||||
append_path MODULEPATH "${PSI_PREFIX}/${PSI_MODULES_ROOT}/$f"
|
||||
append_path PSI_LOADEDFAMILIES "${f}"
|
||||
done
|
||||
|
||||
append_path PATH "${PMODULES_HOME}/bin"
|
||||
append_path MANPATH "${PMODULES_HOME}/share/man"
|
||||
replace_path PATH "${PMODULES_HOME%/*}/.*"
|
||||
replace_path MANPATH "${PMODULES_HOME%/*}/.*"
|
||||
append_path PATH "${PMODULES_HOME}/bin"
|
||||
append_path MANPATH "${PMODULES_HOME}/share/man"
|
||||
|
||||
#############################################################################
|
||||
# initialize bash completion
|
||||
@@ -122,10 +145,9 @@ fi
|
||||
#############################################################################
|
||||
# legacy...
|
||||
#
|
||||
declare -x MODULE_VERSION=${PMODULES_VERSION}
|
||||
declare -x MODULE_VERSION_STACK="${PMODULE_VERSION}"
|
||||
declare -x MODULESHOME="${PMODULES_HOME}"
|
||||
|
||||
unset MODULE_VERSION
|
||||
unset MODULE_VERSION_STACK
|
||||
unset MODULESHOME
|
||||
|
||||
# Local Variables:
|
||||
# mode: sh
|
||||
|
||||
@@ -338,7 +338,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" < <(${PMODULES_HOME}/bin/modulecmd bash search --no-header -a 2>&1)
|
||||
module_picker "${1:-$PSI_PREFIX}" < <(${PMODULES_HOME}/bin/modulecmd bash search --src="${2:-/afs/psi.ch/sys/psi.x86_64_slp6}" --no-header -a 2>&1)
|
||||
else
|
||||
echo "ERROR: module environment configuration: ${PMODULES_HOME}/bin/modulecmd is not an executable!"
|
||||
fi
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
declare -x PSI_PREFIX=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
|
||||
|
||||
if [[ -z ${PMODULES_VERSION} ]]; then
|
||||
declare -x PMODULES_VERSION="0.99.1"
|
||||
declare -x PMODULES_VERSION="@PMODULES_VERSION@"
|
||||
fi
|
||||
declare -x PMODULES_HOME="${PSI_PREFIX}/Tools/Pmodules/${PMODULES_VERSION}"
|
||||
|
||||
@@ -181,6 +181,8 @@ proc set_std_environment { PREFIX name version } {
|
||||
if { [lsearch ${::dont-setenv} "${NAME}_HOME"] == -1 } {
|
||||
setenv ${NAME}_HOME $PREFIX
|
||||
}
|
||||
} else {
|
||||
debug "$PREFIX is not a directory"
|
||||
}
|
||||
|
||||
if { [file isdirectory "$PREFIX/bin"] } {
|
||||
|
||||
@@ -58,22 +58,30 @@ get_options() {
|
||||
"${bindir}/getopt" "$@"
|
||||
}
|
||||
|
||||
check_pmodules_env() {
|
||||
check_pmodules_env_vars() {
|
||||
[[ -n "${PSI_PREFIX}" ]] &&
|
||||
[[ -n "${PSI_CONFIG_DIR}" ]] &&
|
||||
[[ -n "${PSI_MODULES_ROOT}" ]] &&
|
||||
[[ -n "${PSI_TEMPLATES_DIR}" ]] &&
|
||||
[[ -n "${PMODULES_HOME}" ]] &&
|
||||
[[ -n "${PMODULES_VERSION}" ]] || die 1 "
|
||||
Error: not running within a valid module environment!"
|
||||
Error: the module environment you are going to use as source has not been
|
||||
initialized properly!"
|
||||
}
|
||||
|
||||
[[ -d "${PSI_PREFIX}" ]] &&
|
||||
[[ -d "${PSI_PREFIX}/${PSI_CONFIG_DIR}" ]] &&
|
||||
[[ -d "${PSI_PREFIX}/${PSI_MODULES_ROOT}" ]] &&
|
||||
[[ -d "${PSI_PREFIX}/${PSI_TEMPLATES_DIR}" ]] &&
|
||||
[[ -d "${PMODULES_HOME}" ]] || die 1 "
|
||||
Error: the module environment '$PSI_PREFIX' is invalid!"
|
||||
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}/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}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!@PMODULES_HOME@/bin/bash
|
||||
|
||||
unset CDPATH
|
||||
|
||||
shopt -s expand_aliases
|
||||
|
||||
declare -r bindir=$(cd $(dirname "$0") && pwd)
|
||||
@@ -25,7 +27,7 @@ Switches:
|
||||
--force force overwrite
|
||||
|
||||
Available SubCommands and Args:
|
||||
init [--src=<src>] [--user=<user>] --dst=<dst>
|
||||
init [--src=<src>] [--user=<user>] <dst>
|
||||
Initialize a new minimal Pmodule environment.
|
||||
|
||||
install <module> [--with=<dep>...]
|
||||
@@ -54,7 +56,7 @@ init [--src=<src>] [--user=<user>] <dst>
|
||||
|
||||
subcommand_help_install() {
|
||||
echo "
|
||||
install <module> [--with=<dep>...]
|
||||
install <module>... [--with=<dep>...] [--release=<release>...] [--src=<src>]
|
||||
Install matching modules
|
||||
" 1>&2
|
||||
}
|
||||
@@ -125,11 +127,12 @@ sync_module() {
|
||||
local -r rel_module_prefix=$( get_module_prefix "${rel_modulefile}" )
|
||||
local -r rel_releasefile=$( get_releasefile_name "${rel_modulefile}" )
|
||||
|
||||
$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}/" || return $?
|
||||
|
||||
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}/" || 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}"
|
||||
@@ -174,7 +177,7 @@ subcommand_init() {
|
||||
local target_prefixes=()
|
||||
local user=''
|
||||
local opts=''
|
||||
opts=$(get_options -o h -l src: -l user: -l help -- "$@")
|
||||
opts=$(get_options -o h -l src: -l user: -l help -l version: -- "$@")
|
||||
if [[ $? != 0 ]]; then
|
||||
subcommand_help_init
|
||||
exit 1
|
||||
@@ -190,6 +193,10 @@ subcommand_init() {
|
||||
user=$2
|
||||
shift
|
||||
;;
|
||||
--version )
|
||||
PMODULES_VERSION=$2
|
||||
shift
|
||||
;;
|
||||
-- )
|
||||
:
|
||||
;;
|
||||
@@ -231,6 +238,7 @@ environment at '${PSI_PREFIX}'
|
||||
"
|
||||
|
||||
init_pmodules_environment() {
|
||||
local -r src_prefix="${PSI_PREFIX}"
|
||||
local -r target_prefix=$1
|
||||
local src=''
|
||||
local dst=''
|
||||
@@ -250,12 +258,23 @@ environment at '${PSI_PREFIX}'
|
||||
sync_config "${PSI_PREFIX}" \
|
||||
"${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 ..."
|
||||
sync_module "Tools/Pmodules/${PMODULES_VERSION}" \
|
||||
"${PSI_PREFIX}" \
|
||||
"${src_prefix}" \
|
||||
"${target_prefix}" || die 1 "Error: sync Pmodules failed!"
|
||||
echo
|
||||
|
||||
dst="${target_prefix}/${PSI_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}" || die 1 "Error: changing owner failed!"
|
||||
@@ -279,8 +298,10 @@ subcommand_install() {
|
||||
local -a with=()
|
||||
local -a releases=()
|
||||
local -a module_pattern=()
|
||||
local -r src_prefix="${PMODULES_INSTALL_SOURCE}"
|
||||
local -r target_prefix="${PSI_PREFIX}"
|
||||
|
||||
opts=$(get_options -o h -l with: -l release: -l help -- "$@")
|
||||
opts=$(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
|
||||
@@ -288,9 +309,18 @@ subcommand_install() {
|
||||
eval set -- "${opts}"
|
||||
while (($# > 0)); do
|
||||
case $1 in
|
||||
--dry-run )
|
||||
DRY='echo'
|
||||
;;
|
||||
--force | -f )
|
||||
force='yes'
|
||||
;;
|
||||
--release )
|
||||
releases+=( "$2" )
|
||||
echo $2
|
||||
shift
|
||||
;;
|
||||
--src )
|
||||
src_prefix="$2"
|
||||
shift
|
||||
;;
|
||||
--with )
|
||||
@@ -300,7 +330,11 @@ subcommand_install() {
|
||||
-- )
|
||||
:
|
||||
;;
|
||||
-* | -h | --help )
|
||||
-h | --help )
|
||||
subcommand_help_install
|
||||
exit 1
|
||||
;;
|
||||
-* )
|
||||
echo "$1: illegal option" 1>&2
|
||||
subcommand_help_init
|
||||
exit 1
|
||||
@@ -311,7 +345,36 @@ subcommand_install() {
|
||||
esac
|
||||
shift
|
||||
done
|
||||
${PMODULES_HOME}/bin/modulecmd bash search "${module_pattern[@]}" "${with[@]/#/--with}" "${releases[@]/#/--release=}" --no-header
|
||||
local -A modules_to_install
|
||||
local -i n=0
|
||||
while read rel_modulefile; do
|
||||
modules_to_install["${rel_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)
|
||||
(( 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
|
||||
done
|
||||
echo 1>&2
|
||||
get_YN_answer "Do you want to continue? [n] " || die 1 "Aborting..."
|
||||
echo 1>&2
|
||||
for rel_modulefile in "${!modules_to_install[@]}"; do
|
||||
if [[ -d "${target_prefix}/${rel_modulefile}" ]]; then
|
||||
echo " Updating; ${rel_modulefile}..." 1>&2
|
||||
else
|
||||
echo " Installing: ${rel_modulefile}..."
|
||||
fi
|
||||
sync_module "${rel_modulefile}" \
|
||||
"${src_prefix}" \
|
||||
"${target_prefix}"
|
||||
done
|
||||
echo -e "\nDone!\n" 1>&2
|
||||
}
|
||||
|
||||
subcommand_sync() {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#!@PMODULES_HOME@/bin/bash
|
||||
#
|
||||
|
||||
# we have to unset CDPATH, otherwise 'cd' prints the directoy!
|
||||
unset CDPATH
|
||||
|
||||
declare -r PMODULES_DIR=$( cd "$(dirname $0)/.." && pwd )
|
||||
declare -r version='@PMODULES_VERSION@'
|
||||
@@ -10,6 +14,8 @@ declare -rx PSI_LIBMODULES="${PMODULES_DIR}/lib/libmodules.tcl"
|
||||
declare -r modulepath_root="${PSI_PREFIX}/${PSI_MODULES_ROOT}"
|
||||
declare -ra modulepath=( ${MODULEPATH//:/ } )
|
||||
|
||||
source "${PMODULES_DIR}/lib/libpmodules.bash"
|
||||
|
||||
if set -o | grep 'xtrace' | grep -q 'on'; then
|
||||
declare -r __XTRACE__='on'
|
||||
else
|
||||
@@ -462,6 +468,11 @@ subcommand_generic1plus() {
|
||||
"${modulecmd}" "${shell}" "${subcommand}" "$@"
|
||||
}
|
||||
|
||||
#
|
||||
# load module
|
||||
#
|
||||
# $1: module to load
|
||||
#
|
||||
subcommand_load() {
|
||||
output_load_hints() {
|
||||
local -ra rels=( ${available_releases//:/ } )
|
||||
@@ -507,7 +518,9 @@ subcommand_load() {
|
||||
}
|
||||
|
||||
local -r m=$1
|
||||
if module_is_available "${m}"; then
|
||||
if [[ "${m}" == "" ]]; then
|
||||
echo "No module specified." 1>&2
|
||||
elif module_is_available "${m}"; then
|
||||
"${modulecmd}" "${shell}" load "${m}"
|
||||
else
|
||||
if [[ ${userlvl} = 'novice' ]]; then
|
||||
@@ -668,22 +681,25 @@ subcommand_avail() {
|
||||
}
|
||||
|
||||
get_families () {
|
||||
if [[ ! -d "${modulepath_root}" ]]; then
|
||||
local -r module_hierarchy_root="$1"
|
||||
if [[ ! -d "${module_hierarchy_root}" ]]; then
|
||||
echo ""
|
||||
else
|
||||
{
|
||||
cd "${modulepath_root}"
|
||||
cd "${module_hierarchy_root}"
|
||||
ls -1
|
||||
}
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# $1: family name (not path!)
|
||||
# $1: root of modulefile hierarchy
|
||||
# $2: family name (not path!)
|
||||
compute_family_depth () {
|
||||
local -r module_hierarchy_root="$1"
|
||||
local -r family=$2
|
||||
{
|
||||
local -r family=$1
|
||||
cd "${modulepath_root}"
|
||||
cd "${module_hierarchy_root}"
|
||||
local -r tmp=$(find "${family}" -depth -type f -o -type l | head -1)
|
||||
local -ar tmp2=( ${tmp//\// } )
|
||||
local depth=${#tmp2[@]}
|
||||
@@ -701,8 +717,8 @@ subcommand_use() {
|
||||
echo -e "\t${f}" 1>&2
|
||||
done
|
||||
echo -e "\nFamilies you may use in addition:" 1>&2
|
||||
for family in $(get_families); do
|
||||
local -i depth=$( compute_family_depth "${family}")
|
||||
for family in $(get_families "${modulepath_root}"); do
|
||||
local -i depth=$( compute_family_depth "${modulepath_root}" "${family}")
|
||||
if ! is_used_family $f && (( depth == 0 )); then
|
||||
echo -e "\t${f}" 1>&2
|
||||
fi
|
||||
@@ -739,7 +755,7 @@ subcommand_use() {
|
||||
# releases are always *appended*
|
||||
append_path PSI_USED_RELEASES "${arg}"
|
||||
elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulepath_root}/${arg} ]]; then
|
||||
local -i depth=$(compute_family_depth "${arg}")
|
||||
local -i depth=$(compute_family_depth "${modulepath_root}" "${arg}")
|
||||
if (( depth == 0 )); then
|
||||
dirs_to_add+=( ${modulepath_root}/${arg} )
|
||||
else
|
||||
@@ -816,6 +832,7 @@ subcommand_clear() {
|
||||
subcommand_search() {
|
||||
local modules=()
|
||||
local with_modules='//'
|
||||
local src_prefix=''
|
||||
local _print_header='yes'
|
||||
local _print_modulefiles='no'
|
||||
local use_releases=':'
|
||||
@@ -833,22 +850,23 @@ subcommand_search() {
|
||||
# $1: module name pattern
|
||||
search () {
|
||||
local -r module=$1
|
||||
local -r module_hierarchy_root="${src_prefix}/${PSI_MODULES_ROOT}"
|
||||
# we must write temporary results to a file for sorting
|
||||
local -r tmpfile=$( mktemp /tmp/$(basename $0).XXXXXX ) || exit 1
|
||||
local family
|
||||
# loop over all families
|
||||
for family in $(get_families); do
|
||||
local -i depth=$( compute_family_depth ${family} )
|
||||
for family in $(get_families "${module_hierarchy_root}"); do
|
||||
local -i depth=$( compute_family_depth "${module_hierarchy_root}" "${family}" )
|
||||
# get all potential directories of family $f with module-files
|
||||
local mpaths=( $(find \
|
||||
"${modulepath_root}/${family}" \
|
||||
"${module_hierarchy_root}/${family}" \
|
||||
-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/${modulepath_root}}"
|
||||
local p="${mpath/${module_hierarchy_root}}"
|
||||
p=( ${p//\// } )
|
||||
local deps=()
|
||||
local -i i
|
||||
@@ -870,15 +888,15 @@ subcommand_search() {
|
||||
done
|
||||
done
|
||||
done
|
||||
if [[ "{_print_modulefiles}" == "no" ]]; then
|
||||
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
|
||||
echo -n "${line[2]}/"
|
||||
echo -n "${line[2]}/" 1>&2
|
||||
for d in "${line[@]:3}"; do
|
||||
echo -n "$d/"
|
||||
echo -n "$d/" 1>&2
|
||||
done
|
||||
echo "${line[0]}"
|
||||
echo "${line[0]}" 1>&2
|
||||
done < <(sort -k 1,1 -k 4,4 -k 5,5 "${tmpfile}" | awk "${with_modules}")
|
||||
fi
|
||||
rm -f "${tmpfile}"
|
||||
@@ -914,6 +932,10 @@ subcommand_search() {
|
||||
-a | --all-releases )
|
||||
use_releases=${available_releases}
|
||||
;;
|
||||
--src=* )
|
||||
src_prefix=${1/--src=}
|
||||
check_pmodules_directories "${src_prefix}"
|
||||
;;
|
||||
-? | -h | --help )
|
||||
usage
|
||||
;;
|
||||
@@ -927,9 +949,12 @@ subcommand_search() {
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -z "${src_prefix}" ]]; then
|
||||
src_prefix="${PSI_PREFIX}"
|
||||
fi
|
||||
|
||||
if [[ "${use_releases}" == ":" ]]; then
|
||||
use_releases=":${PSI_USED_RELEASES}:"
|
||||
use_releases=":${PSI_USED_RELEASES}:"
|
||||
fi
|
||||
|
||||
[[ "${_print_header}" == "yes" ]] && print_header
|
||||
|
||||
Reference in New Issue
Block a user