Skip to content

Commit fd82b02

Browse files
committed
Support dash init shell with Lmod approach, make sure second initialisation gives expected EESSI version
1 parent 693e5ac commit fd82b02

7 files changed

Lines changed: 45 additions & 156 deletions

File tree

.github/workflows/scripts/test_init_scripts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ ! -d assert.sh ]; then
2626
fi
2727
. assert.sh/assert.sh
2828

29-
TEST_SHELLS=("bash" "zsh" "fish" "ksh" "csh")
29+
TEST_SHELLS=("bash" "zsh" "fish" "ksh" "csh" "sh")
3030
SHELLS=$@
3131

3232
for shell in ${SHELLS[@]}; do
@@ -139,7 +139,7 @@ for shell in ${SHELLS[@]}; do
139139
fi
140140

141141
# Optional test 10, check if the prompt has been updated
142-
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ]; then
142+
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ] || [ "$shell" = "sh" ]; then
143143
# Typically this is a non-interactive shell, so manually unset PS1 and reset to a non-exported variable when testing
144144
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; source init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
145145
TEST_EESSI_NO_PS1_UPDATE=$($shell -c "unset PS1 ; source init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")

init/lmod/bash

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
# SPDX-License-Identifier: GPL-2.0-only
44
# Copyright (C) 2020-2026 EESSI contributors
@@ -49,7 +49,12 @@ EESSI_CVMFS_REPO="${EESSI_CVMFS_REPO:-/cvmfs/software.eessi.io}"
4949
# (Note: in the repository which is home to this file a template value __EESSI_VERSION_DEFAULT__ is present in
5050
# the line below which is replaced within our deployment pipeline.)
5151
EESSI_VERSION_DEFAULT="${__EESSI_VERSION_USED_FOR_INIT:-__EESSI_VERSION_DEFAULT__}"
52-
EESSI_VERSION="${EESSI_VERSION:-${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
5358
# On the first run we want to record the EESSI version used for init as an environment variable so that if a different
5459
# version of this script is called (e.g, for a a different EESSI version) it retains a memory which EESSI
5560
# version was actually used in the initialisation. This is useful as __Init_EESSI_Default_Modules used below will
@@ -75,7 +80,7 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
7580

7681
# Lmod version in 2023.06 has a problem with newer Lmod caches, so let's stick to more recent Lmod
7782
# (has no effect except on Lmod itself, and compatible caches are still created/supported by EESSI)
78-
LMOD_EESSI_VERSION=${EESSI_VERSION/2023.06/2025.06}
83+
LMOD_EESSI_VERSION=$(printf '%s\n' "$EESSI_VERSION" | sed 's/2023\.06/2025\.06/')
7984

8085
# Let's attempt a purge of any loaded modules as any environment variables currently set will survive EESSI initialisation
8186
# (it's ok if the module command does not exist)
@@ -96,10 +101,21 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
96101
export EESSI_MODULE_UPDATE_PS1=1
97102
fi
98103

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+
99115
# Path to top-level module tree
100116
# - EESSI_EXTRA_MODULEPATH environment variable allows a site to append to MODULEPATH (lower priority than EESSI MODULEPATH)
101117
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
102-
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/bash"
118+
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/${shell}"
103119
module --initial_load --no_redirect restore
104120

105121
# After initialising, we now know the architecture(s) that was/were selected so let's report them

init/lmod/csh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ if ( ! $?__EESSI_VERSION_USED_FOR_INIT ) then
2020
else
2121
set EESSI_VERSION_DEFAULT = "$__EESSI_VERSION_USED_FOR_INIT"
2222
endif
23-
if ( ! $?EESSI_VERSION ) then
24-
set EESSI_VERSION = "$EESSI_VERSION_DEFAULT"
23+
if ( ! $?__Init_EESSI_Default_Modules ) then
24+
if ( $?EESSI_VERSION ) then
25+
# keep existing value
26+
else
27+
set EESSI_VERSION "$EESSI_VERSION_DEFAULT"
28+
endif
29+
else
30+
# If we have already initialised and this is being called again,
31+
# then we must want the specific version
32+
set EESSI_VERSION "__EESSI_VERSION_DEFAULT__"
2533
endif
2634
# On first run, record the EESSI version used for init as an environment variable.
2735
# We use setenv to ensure it is available to child processes (equivalent to export).

init/lmod/fish

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ if not set -q __EESSI_VERSION_USED_FOR_INIT
1818
else
1919
set EESSI_VERSION_DEFAULT "$__EESSI_VERSION_USED_FOR_INIT"
2020
end
21-
if not set -q EESSI_VERSION
22-
set EESSI_VERSION "$EESSI_VERSION_DEFAULT"
21+
if not set -q __Init_EESSI_Default_Modules
22+
if set -q EESSI_VERSION
23+
# keep existing value
24+
else
25+
set EESSI_VERSION $EESSI_VERSION_DEFAULT
26+
end
27+
else
28+
# If we have already initialised and this is being called again,
29+
# then we must want the specific version
30+
set EESSI_VERSION "__EESSI_VERSION_DEFAULT__"
2331
end
2432

2533
# Record version used for init; -x exports it to the environment

init/lmod/ksh

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

init/lmod/ksh

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

init/lmod/sh

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

init/lmod/zsh

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

init/lmod/zsh

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

0 commit comments

Comments
 (0)