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 cd
and export
commands 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.execute
You 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.
With recent version of Environment Modules (>=4.6), the sh-to-mod
sub-command enables you to generate a modulefile containing the resulting environment changes made by a script passed as argument
$ module sh-to-mod sh ./phenix_env.sh
#%Module
prepend-path PATH /home/user/bin
set-alias libtbx.setpaths_all {. "/home/xa/setpaths_all.sh"}
set-alias libtbx.unsetpaths {. "/home/xa/unsetpaths.sh"}
setenv LIBTBX_BUILD {}
setenv LIBTBX_OPATH {}
setenv LIBTBX_TMPVAL {}
setenv PHENIX /src/phenix-1.19.2-4158
setenv PHENIX_VERSION 1.19.2-4158
Note that result obtained here is not totally accurate as I have just copied the script you described but I did not have the phenix
software installed which is called to get the environment fully setup.
See also this answer: How to automatically generate the modulefile for Intel compilers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.