Commit 5899aadf authored by gsell's avatar gsell

scripts/Bootstrap/Pmodules/modmanage.bash.in:

- interupt handler added
- some simple fixes
- create Tools/modulefiles
- first code to handle dependencies added
parent 3193331a
#!@PMODULES_HOME@/bin/bash
# we have to unset CDPATH, otherwise 'cd' prints the directoy!
unset CDPATH
shopt -s expand_aliases
# used for some output only
declare -r CMD=$(basename "$0")
declare -r bindir=$(cd $(dirname "$0") && pwd)
declare -r libdir=$(cd "${bindir}/../lib" && pwd)
declare PMODULES_VERSION='@PMODULES_VERSION@'
declare -r mydir=$(cd $(dirname "$0") && pwd)
declare -r prefix=$(dirname "${mydir}")
declare -r bindir="${prefix}/bin"
declare -r libdir="${prefix}/lib"
declare -r libexecdir="${prefix}/libexec"
source "${libdir}/libpmodules.bash"
PATH="${bindir}:${PATH}"
_exit () {
die 1 "Interrupted..."
}
_err () {
info "Got an error in function '${FUNCNAME[1]}', line ${BASH_LINENO[0]}"
die 1 "Aborting ..."
}
trap '_exit' INT TERM
trap '_err' ERR
# make sure that everything is used from this version
declare PMODULES_VERSION='@PMODULES_VERSION@'
print_version() {
echo "
Pmodules @PMODULES_VERSION@ using Tcl Environment Modules @MODULES_VERSION@
......@@ -141,7 +160,7 @@ sync_module() {
$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 $?
"${target_prefix}/${rel_module_prefix}/" 2>/dev/null || return $?
fi
local -r src_modulefile="${src_prefix}/${rel_modulefile}"
local -r src_releasefile="${src_prefix}/${rel_releasefile}"
......@@ -157,13 +176,13 @@ sync_module() {
# copy modulefile
if [[ -e "${src_modulefile}" ]]; then
$DRY rsync --links --perms --recursive \
"${src_modulefile}" "${target_modulefile}" || return $?
"${src_modulefile}" "${target_modulefile}" 2>/dev/null || return $?
fi
# copy release-file
if [[ -e "${src_releasefile}" ]]; then
$DRY rsync --links --perms --recursive \
"${src_releasefile}" "${target_releasefile}" || return $?
"${src_releasefile}" "${target_releasefile}" 2>/dev/null|| return $?
fi
}
......@@ -177,14 +196,14 @@ sync_config() {
src="$1/${PMODULES_CONFIG_DIR}/"
dst="$2/${PMODULES_CONFIG_DIR}/"
$DRY rsync --recursive --links --perms --delete \
"${src}" "${dst}" || die 1 "Error: synch operation failed!"
"${src}" "${dst}" 2>/dev/null || return $?
sed -i.bak "s/PMODULES_VERSION=\(.*\)/PMODULES_VERSION=${PMODULES_VERSION}/" "${dst}/environment.bash"
echo
src="$1/${PMODULES_TEMPLATES_DIR}/"
dst="$2/${PMODULES_TEMPLATES_DIR}/"
$DRY rsync --recursive --links --perms --delete \
"${src}" "${dst}" || die 1 "Error: synch operation failed!"
$DRY rsync --recursive --links --perms --delete --exclude="${src}/.git*" \
"${src}" "${dst}" 2>/dev/null || return $?
echo
}
......@@ -292,6 +311,7 @@ environment at '${PMODULES_ROOT}'
sync_module "Tools/Pmodules/${PMODULES_VERSION}" \
"${src_prefix}" \
"${target_prefix}" || die 1 "Error: sync Pmodules failed!"
mkdir -p "${target_prefix}/Tools/${PMODULES_MODULEFILES_DIR}"
echo
dst="${target_prefix}/${PMODULES_CONFIG_DIR}/environment.bash"
......@@ -325,6 +345,14 @@ subcommand_install() {
local -a module_pattern=()
local -r src_prefix="${PMODULES_INSTALL_SOURCE}"
local -r target_prefix="${PMODULES_ROOT}"
local rel_modulefile=''
local -A modules_to_install
resolve_dependencies () {
for rel_modulefile in "${!modules_to_install[@]}"; do
:
done
}
opts=$(get_options -o hf -l dry-run -l force -l with: -l release: -l help -l src: -- "$@")
if [[ $? != 0 ]]; then
......@@ -370,7 +398,6 @@ subcommand_install() {
esac
shift
done
local -A modules_to_install
local -i n=0
while read rel_modulefile; do
modules_to_install["${rel_modulefile}"]+='.'
......@@ -382,24 +409,25 @@ subcommand_install() {
--no-header --print-modulefiles \
--src="${src_prefix}" 2>&1 1>/dev/null)
(( 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/\/${PMODULES_MODULEFILES_DIR}\//: }" 1>&2
resolve_dependencies
info "The following modules will be installed/updated:\n"
for rel_modulefile in "${!modules_to_install[@]}"; do
info " ${rel_modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }"
done
echo 1>&2
info ""
get_YN_answer "Do you want to continue? [n] " || die 1 "Aborting..."
echo 1>&2
info ""
for rel_modulefile in "${!modules_to_install[@]}"; do
if [[ -d "${target_prefix}/${rel_modulefile}" ]]; then
echo " Updating; ${rel_modulefile}..." 1>&2
if [[ -e "${target_prefix}/${rel_modulefile}" ]]; then
info " Updating: ${rel_modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }"
else
echo " Installing: ${rel_modulefile}..."
info " Installing: ${rel_modulefile/\/${PMODULES_MODULEFILES_DIR}\//: }"
fi
sync_module "${rel_modulefile}" \
"${src_prefix}" \
"${target_prefix}"
done
echo -e "\nDone!\n" 1>&2
info "\nDone!\n"
}
subcommand_sync() {
......@@ -561,7 +589,7 @@ while (($# > 0)); do
echo "$1: unknown sub-command" 1>&2
exit 1
esac
shift
shift || :
done
if [[ -z ${subcommand} ]]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment