@@ -37,6 +37,30 @@ file_changed_in_pr() {
3737 ) && return 0 || return 1
3838}
3939
40+ sed_update_if_changed () {
41+ # Usage: sed_update_if_changed 's/foo/bar/' file.txt
42+ if [ " $# " -ne 2 ]; then
43+ echo " Usage: sed_update_if_changed 'sed_command' file" >&2
44+ return 1
45+ fi
46+
47+ local sed_command=" $1 "
48+ local file=" $2 "
49+ local tmp_file=" $( mktemp " ${file} .XXXXXX" ) "
50+
51+ sed " $sed_command " " $file " > " $tmp_file " || {
52+ rm -f " $tmp_file "
53+ echo " sed command failed" >&2
54+ return 1
55+ }
56+
57+ if ! cmp -s " $file " " $tmp_file " ; then
58+ mv " $tmp_file " " $file "
59+ else
60+ rm -f " $tmp_file "
61+ fi
62+ }
63+
4064compare_and_copy () {
4165 if [ " $# " -ne 2 ]; then
4266 echo " Usage of function: compare_and_copy <source_file> <destination_file>"
@@ -134,8 +158,6 @@ init_files=(
134158 minimal_eessi_env README.md test.py lmod_eessi_archdetect_wrapper.sh lmod_eessi_archdetect_wrapper_accel.sh
135159
136160)
137- # make sure that scripts in init/ and scripts/ use correct EESSI version
138- sed -i " s/__EESSI_VERSION_DEFAULT__/${EESSI_VERSION} /g" ${TOPDIR} /init/eessi_defaults
139161copy_files_by_list ${TOPDIR} /init ${INSTALL_PREFIX} /init " ${init_files[@]} "
140162
141163# Copy for the init/arch_specs directory
@@ -154,16 +176,12 @@ copy_files_by_list ${TOPDIR}/init/Magic_Castle ${INSTALL_PREFIX}/init/Magic_Cast
154176mc_files=(
155177 2023.06.lua
156178)
157- # replace EESSI version used in comments in EESSI module
158- sed -i " s@/<EESSI_VERSION>/@/${EESSI_VERSION} /@g" ${TOPDIR} /init/modules/EESSI/${EESSI_VERSION} .lua
159179copy_files_by_list ${TOPDIR} /init/modules/EESSI ${INSTALL_PREFIX} /init/modules/EESSI " ${mc_files[@]} "
160180
161181# Copy for init/lmod directory
162- init_script_files=$( ls ${TOPDIR} /init/lmod)
163- # replace placeholder for default EESSI version in Lmod init scripts
164- for shell in $init_script_files ; do
165- sed -i " s/__EESSI_VERSION_DEFAULT__/${EESSI_VERSION} /g" ${TOPDIR} /init/lmod/${shell}
166- done
182+ init_script_files=(
183+ bash zsh ksh fish csh
184+ )
167185copy_files_by_list ${TOPDIR} /init/lmod ${INSTALL_PREFIX} /init/lmod " ${init_script_files[@]} "
168186
169187# Copy for the scripts directory
@@ -192,6 +210,22 @@ ${INSTALL_PREFIX}/scripts/gpu_support/nvidia/easystacks "${host_injections_easys
192210hook_files=(
193211 eb_hooks.py
194212)
195- # replace EESSI version used in EasyBuild hooks
196- sed -i " s@/eessi-<EESSI_VERSION>/@/eessi-${EESSI_VERSION} /@g" ${TOPDIR} /eb_hooks.py
197213copy_files_by_list ${TOPDIR} ${INSTALL_PREFIX} /init/easybuild " ${hook_files[@]} "
214+
215+ # replace version placeholders in scripts;
216+ # note: the commands below are always run, regardless of whether the scripts were changed,
217+ # but that should be fine (no changes are made if version placeholder is not present anymore)
218+
219+ # make sure that scripts in init/ and scripts/ use correct EESSI version
220+ sed_update_if_changed " s/__EESSI_VERSION_DEFAULT__/${EESSI_VERSION} /g" ${INSTALL_PREFIX} /init/eessi_defaults
221+
222+ # replace placeholder for default EESSI version in Lmod init scripts
223+ for shell in $( ls ${INSTALL_PREFIX} /init/lmod) ; do
224+ sed_update_if_changed " s/__EESSI_VERSION_DEFAULT__/${EESSI_VERSION} /g" ${INSTALL_PREFIX} /init/lmod/${shell}
225+ done
226+
227+ # replace EESSI version used in comments in EESSI module
228+ sed_update_if_changed " s@/<EESSI_VERSION>/@/${EESSI_VERSION} /@g" ${INSTALL_PREFIX} /init/modules/EESSI/${EESSI_VERSION} .lua
229+
230+ # replace EESSI version used in EasyBuild hooks
231+ sed_update_if_changed " s@/<EESSI_VERSION>/@/${EESSI_VERSION} /@g" ${INSTALL_PREFIX} /init/easybuild/eb_hooks.py
0 commit comments