From 11e52777bca147cd63cc89553cfcb3e7cadf90f9 Mon Sep 17 00:00:00 2001 From: Steffen Bollmann Date: Mon, 13 Nov 2023 06:49:02 +0000 Subject: [PATCH] add correct handling of apptainer --- run_transparent_singularity.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/run_transparent_singularity.sh b/run_transparent_singularity.sh index 3c6ccb1..2a54022 100755 --- a/run_transparent_singularity.sh +++ b/run_transparent_singularity.sh @@ -215,19 +215,27 @@ singularity exec $singularity_opts --pwd $_base $container $_base/ts_binaryFinde echo "create singularity executable for each regular executable in commands.txt" # $@ parses command line options. #test executable="fslmaths" -singularity_version=$(singularity version | cut -d'-' -f1) + +# The --env option requires singularity > 3.6 or apptainer. Test here: required_version="3.6" +if which apptainer >/dev/null 2>&1; then + echo "Apptainer is installed." + singularity_version=3.6 +else + echo "Apptainer is not installed. Testing for singularity version." + singularity_version=$(singularity version | cut -d'-' -f1) +fi + while read executable; do \ echo $executable > $_base/${executable}; \ echo "#!/usr/bin/env bash" > $executable echo "export PWD=\`pwd -P\`" >> $executable + # neurodesk_singularity_opts is a global variable that can be set in neurodesk for example --nv for gpu support # --silent is required to suppress bind mound warnings (e.g. for /etc/localtime) # --cleanenv is required to prevent environment variables on the host to affect the containers (e.g. Julia and R packages), but to work # correctly with GUIs, the DISPLAY variable needs to be set as well. This only works in singularity >= 3.6.0 - if printf '%s\n' "$required_version" "$singularity_version" | sort -V | head -n1 | grep -q "$required_version"; then - echo "Singularity version is equal to or newer than $required_version. All features should work." echo "singularity --silent exec --cleanenv --env DISPLAY=\$DISPLAY \$neurodesk_singularity_opts --pwd \$PWD $_base/$container $executable \"\$@\"" >> $executable else echo "Singularity version is older than $required_version. GUIs will not work correctly!"