From 183e7f40a260ef6e09745183ce768986bab29daf Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 7 May 2021 15:51:28 +0200 Subject: [PATCH 1/5] libstd.bash: function to check Bash variable type added --- Pmodules/libstd.bash | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Pmodules/libstd.bash b/Pmodules/libstd.bash index eb8525d..e5a2f46 100644 --- a/Pmodules/libstd.bash +++ b/Pmodules/libstd.bash @@ -244,6 +244,33 @@ std::get_os_release() { ${func_map[${OS}]} } +std::get_type() { + local -a signature=$(typeset -p "$1") + case ${signature[1]} in + -Ai* ) + echo 'int dict' + ;; + -A* ) + echo 'dict' + ;; + -ai* ) + echo 'int array' + ;; + -a* ) + echo 'array' + ;; + -i* ) + echo 'integer' + ;; + -- ) + echo 'string' + ;; + * ) + echo 'none' + return 1 + esac +} + # Local Variables: # mode: sh # sh-basic-offset: 8 From bff9055b20cb0fa2cd4eb5b111218e57e4ce4aeb Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 7 May 2021 16:40:08 +0200 Subject: [PATCH 2/5] modulecmd: bugfix in tmp file setup/cleanup --- Pmodules/modulecmd.bash.in | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 84b586e..6937055 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1465,7 +1465,6 @@ subcommand_purge() { local output=$("${modulecmd}" 'bash' 'purge' 2> "${tmpfile}") local error=$( < "${tmpfile}") - ${rm} "${tmpfile}" if [[ "${error}" =~ ":ERROR:" ]]; then local s=${error%%$'\n'*} local error_txt='failed' @@ -1755,8 +1754,6 @@ subcommand_search() { func_print_line='print_line_csv' } - local -r tmpfile=$1 - if [[ "${opt_print_modulefiles}" == 'yes' ]]; then print_modulefiles elif [[ "${opt_print_csv}" == 'yes' ]]; then @@ -1852,7 +1849,6 @@ subcommand_search() { done done print_result "${tmpfile}" - ${rm} -f "${tmpfile}" } while (( $# > 0 )); do @@ -2277,6 +2273,9 @@ case ${subcommand} in declare -r tmpfile=$( ${mktemp} /tmp/Pmodules.XXXXXX ) \ || std::die 1 "Oops: unable to create tmp file!" ;; + * ) + declare -r tmpfile='' + ;; esac declare options From d32f04ea832c5043435e8aacad0d2ec9c31f7193 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 7 May 2021 16:41:00 +0200 Subject: [PATCH 3/5] modulecmd: bugfix in basic initialization --- Pmodules/modulecmd.bash.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 6937055..e497fb2 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1394,8 +1394,8 @@ pmodules_init() { unset UseFlags declare -Ag UseFlags=() declare -g Version="${PMODULES_VERSION}" - reset_modulepath reset_used_groups + reset_modulepath reset_used_releases init_manpath export_env \ From ca4c530a5e27af157d4dd2bb21fb6a51fb520d59 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Mon, 10 May 2021 15:53:06 +0200 Subject: [PATCH 4/5] modulecmd: prevent loading Pmodules module if other modules are loaded --- Pmodules/modulecmd.bash.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index e497fb2..5599f5e 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -508,8 +508,20 @@ subcommand_load() { fi if [[ ${current_modulefile} =~ ${PMODULES_ROOT} ]] \ && [[ ! ${m} =~ / ]]; then + # the module is in our hierarchy but no version + # has been specified. We take the version from + # current_modulefile and append it m+="/${current_modulefile##*/}" fi + if [[ ${m} == Pmodules/* ]] && [[ -n ${LOADEDMODULES} ]]; then + std::error "%s %s: %s" \ + "${CMD}" "${subcommand}" \ + "cannot load a Pmodules module because other modules are already load!" + std::die 3 "%s %s: %s -- %s\n" \ + "${CMD}" "${subcommand}" \ + "failed" \ + "${m}" + fi if [[ ":${LOADEDMODULES}:" =~ ":${m}:" ]]; then continue fi From fcec9f77c205095bdfc94e3a1252fda30985c3fa Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Mon, 10 May 2021 15:55:19 +0200 Subject: [PATCH 5/5] modulecmd: restore some env.vars after loading Pmodules module --- Pmodules/modulecmd.bash.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 5599f5e..871caf0 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -2270,7 +2270,16 @@ fi if [[ -n ${PMODULES_ENV} ]]; then eval "$("${base64}" -d <<< "${PMODULES_ENV}" 2>/dev/null)" if [[ -z ${Version} ]] || [[ ${Version} != ${PMODULES_VERSION} ]]; then + # the Pmodules version changed! + # we save _LMFILES_ and LOADEDMODULES and restore them + # later. Otherwise the Pmodules module would not be listed + # by module list + declare saved_LMFILES_="${_LMFILES_}" + declare saved_LOADEDMODULES="${LOADEDMODULES}" pmodules_init + _LMFILES_="${saved_LMFILES_}" + LOADEDMODULES="${saved_LOADEDMODULES}" + export_env _LMFILES_ LOADEDMODULES fi else pmodules_init