Skip to content

scl-init.sh: Sets MODULESHOME unconditionally #52

@HenrikBengtsson

Description

@HenrikBengtsson

Background

We use Lmod (Lua-based; https://lmod.readthedocs.io/) as our environment module system, rather than the traditionally Tmod (Tcl-based) system.

We also install the gcc-toolset SCLs (we're on Rocky 8), and we have scl-utils.x86_64 installed.

Issue

With Lmod installed, we'd expect:

$ echo "MODULESHOME=${MODULESHOME}"
MODULESHOME=/usr/share/lmod/lmod

but we get:

$ echo "MODULESHOME=${MODULESHOME}"
MODULESHOME=/usr/share/Modules

Troubleshooting

During shell startup process, /etc/profile.d/scl-init.sh sets and exports MODULESHOME unconditionally;

MODULESHOME=/usr/share/Modules
export MODULESHOME
if [ "${MODULEPATH:-}" = "" ]; then
MODULEPATH=`sed -n 's/[ #].*$//; /./H; $ { x; s/^\n//; s/\n/:/g; p; }' ${MODULESHOME}/init/.modulespath`
fi

This overrides MODULESHOME already set while processing Lmod's /etc/profile.d/modules.sh (-> /etc/alternatives/modules.sh -> /usr/share/lmod/lmod/init/profile).

Suggestion / patch

I think scl-init.sh:

  1. should not hardcode MODULESHOME,
  2. should not make assumptions about MODULESHOME, and
  3. should not override MODULESHOME, if already set

Here's a backward-compatible patch that I think address these requirements:

 git diff -w
diff --git a/shell/scl-init.csh b/shell/scl-init.csh
index 45b22be..efc4695 100644
--- a/shell/scl-init.csh
+++ b/shell/scl-init.csh
@@ -1,6 +1,8 @@
 alias scl 'source /etc/scl/func_scl.csh'
 
+if (! $?MODULESHOME ) then
     setenv MODULESHOME /usr/share/Modules
+endif
 
 if (! $?MODULEPATH ) then
     setenv MODULEPATH `sed -n 's/[    #].*$//; /./H; $ { x; s/^\n//; s/\n/:/g; p; }' ${MODULESHOME}/init/.modulespath`
diff --git a/shell/scl-init.sh b/shell/scl-init.sh
index 6eeabea..373e00f 100644
--- a/shell/scl-init.sh
+++ b/shell/scl-init.sh
@@ -12,7 +12,7 @@ fi
 shell=`/bin/basename \`/bin/ps -p $$ -ocomm=\``
 [ "$shell" = "bash" ] && export -f scl # export -f works only in bash
 
-MODULESHOME=/usr/share/Modules
+MODULESHOME=${MODULESHOME:-/usr/share/Modules}
 export MODULESHOME
 
 if [ "${MODULEPATH:-}" = "" ]; then

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions