Skip to content

Commit fd62084

Browse files
committed
only add directory to MODULEPATH if it is not yet included
1 parent c1ab568 commit fd62084

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

EESSI-install-software.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ function copy_build_log() {
5353
fi
5454
}
5555

56+
function safe_module_use {
57+
# add a given non-empty directory to $MODULEPATH if and only if it is not yet in
58+
directory=${1}
59+
60+
if [[ -z ${directory+x} ]]; then
61+
echo "safe_module_use: given directory unset or empty; not adding it to \$MODULEPATH (${MODULEPATH})"
62+
return
63+
fi
64+
if [[ ":${MODULEPATH}:" == *":${directory}:"* ]]; then
65+
echo "safe_module_use: directory '${directory}' is already in \$MODULEPATH (${MODULEPATH}); not adding it again"
66+
return
67+
else
68+
echo "safe_module_use: directory '${directory}' is not yet in \$MODULEPATH (${MODULEPATH}); adding it"
69+
module use ${directory}
70+
fi
71+
}
72+
5673
POSITIONAL_ARGS=()
5774

5875
while [[ $# -gt 0 ]]; do
@@ -308,7 +325,8 @@ if [[ "${EESSI_CVMFS_REPO}" == /cvmfs/dev.eessi.io ]]; then
308325
fi
309326

310327
echo "DEBUG: adding path '$EASYBUILD_INSTALLPATH/modules/all' to MODULEPATH='${MODULEPATH}'"
311-
module use $EASYBUILD_INSTALLPATH/modules/all
328+
#module use $EASYBUILD_INSTALLPATH/modules/all
329+
safe_module_use $EASYBUILD_INSTALLPATH/modules/all
312330
echo "DEBUG: after adding module path // MODULEPATH='${MODULEPATH}'"
313331

314332
if [[ -z ${MODULEPATH} ]]; then

0 commit comments

Comments
 (0)