Skip to content

Commit a5f278d

Browse files
committed
Make other POSIX-compatible shells symlinks to sh version
1 parent 87a850e commit a5f278d

4 files changed

Lines changed: 136 additions & 136 deletions

File tree

init/lmod/bash

Lines changed: 0 additions & 133 deletions
This file was deleted.

init/lmod/bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sh

init/lmod/ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bash
1+
sh

init/lmod/sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

init/lmod/sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env sh
2+
3+
# SPDX-License-Identifier: GPL-2.0-only
4+
# Copyright (C) 2020-2026 EESSI contributors
5+
#
6+
# EESSI - European Environment for Scientific Software Installations
7+
#
8+
# This file is a template for initialising EESSI via Lmod for the environment indicated by the shebang.
9+
#
10+
# Assumptions:
11+
# - EESSI accessible under $EESSI_CVMFS_REPO or /cvmfs/software.eessi.io
12+
# - expected to be true as this file is also meant to be shipped under that location
13+
# - Lmod must the shipped in the repository in the correct location
14+
#
15+
# Options:
16+
# - The script listens to environment variables so that it can be silently configured by a site
17+
# - EESSI_CVMFS_REPO: perform the initialisation from a repository other than /cvmfs/software.eessi.io
18+
# - EESSI_VERSION: loads a specific EESSI version ignoring the default in the file
19+
# - EESSI_DEFAULT_MODULES_PREPEND: environment variable allows you to prepend modules to the defaults (loaded last, : separated)
20+
# - EESSI_DEFAULT_MODULES_APPEND: environment variable allows you to append modules to the defaults (loaded first, : separated)
21+
# - EESSI_EXTRA_MODULEPATH: environment variable allows a site to append to MODULEPATH (: separated, lower priority than EESSI MODULEPATH)
22+
# - EESSI_NO_MODULE_PURGE_ON_INIT: environment variable that disables purging modules before initialisation
23+
#
24+
# Other options that can be set to influence the end result:
25+
# - The EESSI module also listens to environment variables so that it can be silently configured by a site
26+
# - EESSI_MODULE_FAMILY_NAME: use the value of the environment variable to set an Lmod family for the EESSI module
27+
# - EESSI_MODULE_STICKY: make the EESSI module sticky
28+
# - EESSI_MODULE_UPDATE_PS1: have the EESSI module update PS1 to give a prompt that is prepended with "{EESSI/...} " (requires exporting PS1)
29+
# (- EESSI_MODULE_DEBUG_INIT: enable debug print statements when loading the EESSI module)
30+
#
31+
# Effects:
32+
# - Should always succeed
33+
# - Initialises Lmod from specific version of EESSI
34+
# - Clobbers any existing Lmod configuration
35+
# - Some special environment variables that are internal to Lmod (__LMOD_REF_COUNT_MODULEPATH and
36+
# _ModuleTable001_) are used to force a hard reset of an existing Lmod installation. This
37+
# approach may be brittle.
38+
# - Then loads module EESSI/... to initialise EESSI
39+
# - use `module show EESSI/...` to see the environment variables set by the EESSI module
40+
#
41+
# Reverting the effects:
42+
# - EESSI initialisation via `module unload EESSI/...`
43+
# - Lmod initialisation cannot be undone
44+
45+
# Choose an EESSI CVMFS repository
46+
EESSI_CVMFS_REPO="${EESSI_CVMFS_REPO:-/cvmfs/software.eessi.io}"
47+
48+
# Choose an EESSI version (the default is only used if the EESSI_VERSION environment variable is not provided)
49+
# (Note: in the repository which is home to this file a template value __EESSI_VERSION_DEFAULT__ is present in
50+
# the line below which is replaced within our deployment pipeline.)
51+
EESSI_VERSION_DEFAULT="${__EESSI_VERSION_USED_FOR_INIT:-__EESSI_VERSION_DEFAULT__}"
52+
if [ -z "$__Init_EESSI_Default_Modules" ]; then
53+
EESSI_VERSION="${EESSI_VERSION:-${EESSI_VERSION_DEFAULT}}"
54+
else
55+
# If we have already initiaised and this is being called again, then we must want the specific version
56+
EESSI_VERSION="__EESSI_VERSION_DEFAULT__"
57+
fi
58+
# On the first run we want to record the EESSI version used for init as an environment variable so that if a different
59+
# version of this script is called (e.g, for a a different EESSI version) it retains a memory which EESSI
60+
# version was actually used in the initialisation. This is useful as __Init_EESSI_Default_Modules used below will
61+
# be defined on the first call and Lmod initialisation will not happen twice.
62+
# This sets the value only on first execution, if the variable already exists in the environment
63+
# the original value is retained.
64+
export __EESSI_VERSION_USED_FOR_INIT="${__EESSI_VERSION_USED_FOR_INIT:-${EESSI_VERSION}}"
65+
66+
# LMOD_SYSTEM_DEFAULT_MODULES are used by Lmod to load a default set of modules in the scenario
67+
# - where we initialise Lmod (the if part of the clause below)
68+
# - where we reset Lmod (the else part of the clause below)
69+
# This means that if we call this script twice we will get the same end result: an Lmod installation
70+
# with a set of default modules loaded.
71+
#
72+
# We also allow the ability to predefine elsewhere the default list of modules to load (colon separated):
73+
# - EESSI_DEFAULT_MODULES_PREPEND environment variable allows you to prepend modules (loaded last)
74+
# - EESSI_DEFAULT_MODULES_APPEND environment variable allows you to append modules (loaded first)
75+
LMOD_SYSTEM_DEFAULT_MODULES="${EESSI_DEFAULT_MODULES_PREPEND:+$EESSI_DEFAULT_MODULES_PREPEND:}EESSI/$EESSI_VERSION${EESSI_DEFAULT_MODULES_APPEND:+:$EESSI_DEFAULT_MODULES_APPEND}"
76+
export LMOD_SYSTEM_DEFAULT_MODULES
77+
78+
if [ -z "$__Init_EESSI_Default_Modules" ]; then
79+
export __Init_EESSI_Default_Modules=1;
80+
81+
# Lmod version in 2023.06 has a problem with newer Lmod caches, so let's stick to more recent Lmod
82+
# (has no effect except on Lmod itself, and compatible caches are still created/supported by EESSI)
83+
LMOD_EESSI_VERSION=$(printf '%s\n' "$EESSI_VERSION" | sed 's/2023\.06/2025\.06/')
84+
85+
# Let's attempt a purge of any loaded modules as any environment variables currently set will survive EESSI initialisation
86+
# (it's ok if the module command does not exist)
87+
if [ -z "$EESSI_NO_MODULE_PURGE_ON_INIT" ]; then
88+
module purge >/dev/null 2>&1 && echo "Modules purged before initialising EESSI"
89+
fi
90+
91+
# Lmod may have been initialised so we need to clear some internal variables to allow for a full reset
92+
# - make it forget about the system set MODULEPATH
93+
unset __LMOD_REF_COUNT_MODULEPATH
94+
# - and clear out any memory Lmod might have
95+
unset _ModuleTable001_
96+
97+
# For the shells that use PS1 for the prompt, let's add the trigger to enable updating that by default
98+
# (in an interactive shell PS1 is likely unset, so let's only do this if it is set)
99+
if [ -n "$PS1" ]; then
100+
export PS1
101+
export EESSI_MODULE_UPDATE_PS1=1
102+
fi
103+
104+
# Figure out what shell we have
105+
if [ -n "${BASH_VERSION-}" ]; then
106+
shell=bash
107+
elif [ -n "${ZSH_VERSION-}" ]; then
108+
shell=zsh
109+
elif [ -n "${KSH_VERSION-}" ]; then
110+
shell=ksh
111+
else
112+
shell=sh
113+
fi
114+
115+
# Path to top-level module tree
116+
# - EESSI_EXTRA_MODULEPATH environment variable allows a site to append to MODULEPATH (lower priority than EESSI MODULEPATH)
117+
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
118+
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/${shell}"
119+
module --initial_load --no_redirect restore
120+
121+
# After initialising, we now know the architecture(s) that was/were selected so let's report them
122+
echo "EESSI has selected ${EESSI_SOFTWARE_SUBDIR} as the compatible CPU target for EESSI/${EESSI_VERSION}"
123+
if [ -n "$EESSI_ACCEL_SUBDIR" ]; then
124+
echo "EESSI has selected ${EESSI_ACCEL_SUBDIR} as the compatible accelerator target for EESSI/${EESSI_VERSION}"
125+
else
126+
echo "EESSI did not identify an accelerator on the system"
127+
fi
128+
# If people want more detailed information about what EESSI is doing, they can also set an environment variable
129+
# for additional information.
130+
echo "(for debug information when loading the EESSI module, set the environment variable EESSI_MODULE_DEBUG_INIT)"
131+
else
132+
module reset
133+
fi

init/lmod/zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bash
1+
sh

0 commit comments

Comments
 (0)