Skip to content

Commit aef777f

Browse files
committed
2tag: Correctly restore user-overwritten O2DPG env vars
1 parent f7eb97c commit aef777f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

MC/run/ANCHOR/anchorMC.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ fi
198198
#<----- START OF part that should run under a clean alternative software environment if this was given ------
199199
if [ "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" ]; then
200200
if [ "${LOADEDMODULES}" ]; then
201-
export > env_before_stashing.env
201+
printenv > env_before_stashing.printenv
202202
echo "Stashing initial modules"
203203
module save initial_modules.list # we stash the current modules environment
204204
module list --no-pager
205205
module purge --no-pager
206-
export > env_after_stashing.env
206+
printenv > env_after_stashing.printenv
207207
echo "Modules after purge"
208208
module list --no-pager
209209
fi
@@ -272,10 +272,17 @@ if [ "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" ]; then
272272
echo "Restoring initial environment"
273273
module --no-pager restore initial_modules.list
274274
module saverm initial_modules.list
275-
if [ "${ALIEN_JDL_O2DPG_OVERWRITE}" ]; then
276-
echo "Setting back O2DPG_ROOT to overwritten path ${ALIEN_JDL_O2DPG_OVERWRITE}"
277-
export O2DPG_ROOT=${ALIEN_JDL_O2DPG_OVERWRITE}
278-
fi
275+
276+
# Restore overwritten O2DPG variables set by modules but changed by user
277+
# (in particular custom O2DPG_ROOT and O2DPG_MC_CONFIG_ROOT)
278+
printenv > env_after_restore.printenv
279+
comm -12 <(grep '^O2DPG' env_before_stashing.printenv | cut -d= -f1 | sort) \
280+
<(grep '^O2DPG' env_after_restore.printenv | cut -d= -f1 | sort) |
281+
while read -r var; do
282+
b=$(grep "^$var=" env_before_stashing.printenv | cut -d= -f2-)
283+
a=$(grep "^$var=" env_after_restore.printenv | cut -d= -f2-)
284+
[[ "$b" != "$a" ]] && export "$var=$b" && echo "Reapplied: $var to ${b}"
285+
done
279286
fi
280287
#<----- END OF part that should run under a clean alternative software environment if this was given ------
281288

0 commit comments

Comments
 (0)