I am trying to create a module file for an application I have installed on the cluster. To run the program, I have to run a script named "phenix_env.sh" which contains the following:
#!/bin/sh
#
export PHENIX="/src/phenix-1.19.2-4158"
export PHENIX_VERSION=1.19.2-4158
. $PHENIX/build/setpaths.sh
While the "setpaths.sh" contains the following
# THIS IS AN AUTOMATICALLY GENERATED FILE.
# DO NOT EDIT! CHANGES WILL BE LOST.
ocwd="`pwd`"
if [ -n "$LIBTBX_BUILD_RELOCATION_HINT" ]; then
cd "$LIBTBX_BUILD_RELOCATION_HINT"
LIBTBX_BUILD_RELOCATION_HINT=
export LIBTBX_BUILD_RELOCATION_HINT
elif [ -n "$BASH_SOURCE" ]; then
LIBTBX_BUILD=`dirname "$BASH_SOURCE[0]"`
cd "$LIBTBX_BUILD"
else
cd "/util/opt/phenix/1.19.2/gcc/9.1/phenix-1.19.2-4158/build"
fi
LIBTBX_BUILD=`pwd -P`
export LIBTBX_BUILD
LIBTBX_OPATH="$PATH"
export LIBTBX_OPATH
PATH="$LIBTBX_BUILD/bin:$PATH"
export PATH
# DIALS_ENABLE_COMMAND_LINE_COMPLETION
[ -n "$BASH_VERSION" ] && {
source $(libtbx.find_in_repositories dials/util/autocomplete.sh) && source $LIBTBX_BUILD/dials/autocomplete/bash.sh || echo dials command line completion not available
}
cd "$ocwd"
ocwd=
alias libtbx.setpaths_all=". \"$LIBTBX_BUILD/setpaths_all.sh\""
alias libtbx.unsetpaths=". \"$LIBTBX_BUILD/unsetpaths.sh\""
if [ -n "$LIBTBX_OPATH" ]; then
LIBTBX_TMPVAL="$LIBTBX_OPATH"
else
LIBTBX_TMPVAL=
fi
export LIBTBX_TMPVAL
PATH=`libtbx.path_utility prepend LIBTBX_TMPVAL "$LIBTBX_BUILD/bin" < /dev/null`
export PATH
if [ "$PATH" = "L_I_B_T_B_X_E_M_P_T_Y" ]; then unset PATH; fi
LIBTBX_TMPVAL=
LIBTBX_OPATH=
LIBTBX_BUILD=
Any idea how to create a module file for it?
You can not.
Lua executes shell scripts in a subshell.
This means all
cdandexportcommands will affect only that subshell but not the parent shell where the Lua script runs.In other words, your changes will be nullified after returning from
os.executeYou can workaround it if you are allowed to
require()a Lua modules written on C.You need a module which provides wrappers around OS-native functions for changing the current directory and setting env variable.