Skip to content
Snippets Groups Projects
Commit 0fa112b4 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: Only create wrappers if env vars look correct - $FSLDIR == $PREFIX, and

FSL_CREATE_WRAPPER_SCRIPTS is non-empty. Use
parent 9ba303fd
No related branches found
No related tags found
1 merge request!1Enh/create wrapper
#!/bin/sh #!/usr/bin/env bash
# #
# Create wrapper scripts in $FSLDIR/share/fsl/bin/ which invoke commands that # Create wrapper scripts in $FSLDIR/share/fsl/bin/ which invoke commands that
# are installed in $FSLDIR/bin/. # are installed in $FSLDIR/bin/.
...@@ -12,6 +12,13 @@ ...@@ -12,6 +12,13 @@
# fslinstaller.py script - it is not intended to be used when individual # fslinstaller.py script - it is not intended to be used when individual
# FSL projects are explicitly installed into a custom conda environment. # FSL projects are explicitly installed into a custom conda environment.
# #
# Wrapper scripts will only be created if the following conditions are met:
# - The $FSLDIR and $PREFIX environment variables are set, and
# are equivalent
# - The $FSL_CREATE_WRAPPER_SCRIPTS environment variable is set and is not
# empty.
# -
#
# Early versions of this script would create symlinks from $FSLDIR/bin/ into # Early versions of this script would create symlinks from $FSLDIR/bin/ into
# $FSLDIR/fslpython/envs/fslpython/bin/ (and, later, into # $FSLDIR/fslpython/envs/fslpython/bin/ (and, later, into
# $FSLDIR/share/fsl/bin/). However, wrapper scripts are now used instead to # $FSLDIR/share/fsl/bin/). However, wrapper scripts are now used instead to
...@@ -30,64 +37,71 @@ ...@@ -30,64 +37,71 @@
# to have a shebang line pointing to $FSLDIR/bin/python which does not # to have a shebang line pointing to $FSLDIR/bin/python which does not
# exceed 127 characters. # exceed 127 characters.
# Only create wrappers if the FSL_CREATE_WRAPPER_SCRIPTS
# environment variable is set
if [ -z "$FSL_CREATE_WRAPPER_SCRIPTS" ]; then
exit 0
fi
# Only create wrappers if FSLDIR exists
if [ ! -d "$FSLDIR" ]; then
exit 0
fi
# and if FSLDIR == PREFIX
if [ "$FSLDIR" != "$PREFIX" ]; then
exit 0
fi
# Names of all executables for which wrapper # Names of all executables for which wrapper
# scripts are to be created are passed as # scripts are to be created are passed as
# arguments # arguments
targets=$@ targets=$@
# Only create wrappers if scripts for script in $targets; do
# are in subdirectory of FSLDIR sourceScript="${PREFIX}/bin/$script"
if [ -z "$FSLDIR" ]; then targetScript="${FSLDIR}/share/fsl/bin/$script"
exit 1
fi
case "$PREFIX" in "$FSLDIR"*)
for script in $targets; do
sourceScript="${PREFIX}/bin/$script"
targetScript="${FSLDIR}/share/fsl/bin/$script"
if [ ! -f "$sourceScript" ]; then if [ ! -f "$sourceScript" ]; then
continue continue
fi fi
# create share/fsl/bin/ if it doesn't # create share/fsl/bin/ if it doesn't
# already exist # already exist
if [ ! -e "$FSLDIR/share/fsl/bin" ]; then if [ ! -e "$FSLDIR/share/fsl/bin" ]; then
mkdir -p "$FSLDIR/share/fsl/bin" mkdir -p "$FSLDIR/share/fsl/bin"
fi fi
# remove target script if it already exists # remove target script if it already exists
if [ -e "$targetScript" ]; then if [ -e "$targetScript" ]; then
rm "$targetScript" rm "$targetScript"
fi fi
# Figure out whether this is a python # Figure out whether this is a python
# executable or some other type of # executable or some other type of
# executable. We search for these strings # executable. We search for these strings
# in source file headers to ID them as # in source file headers to ID them as
# python scripts. We need to check both # python scripts. We need to check both
# match "#!/usr/bin/env python" and # match "#!/usr/bin/env python" and
# "#!<fsldir>/bin/python...", because # "#!<fsldir>/bin/python...", because
# conda might generate one or the other # conda might generate one or the other
# in different scenarios. # in different scenarios.
id1=$(head -c 1024 "$sourceScript" | grep "#!/usr/bin/env python") id1=$(head -c 1024 "$sourceScript" | grep "#!/usr/bin/env python")
id2=$(head -c 1024 "$sourceScript" | grep "/fslpython/bin/python") id2=$(head -c 1024 "$sourceScript" | grep "#!${FSLDIR%/}/bin/python")
# Non-python executable - use a # Non-python executable - use a
# pass-through script # pass-through script
if [ -z "$id1" ] && [ -z "$id2" ]; then if [ -z "$id1" ] && [ -z "$id2" ]; then
echo "#!/bin/sh" > "$targetScript" echo "#!/usr/bin/env bash" > "$targetScript"
echo "$FSLDIR/bin/$script \"$@\"" >> "$targetScript" echo "$FSLDIR/bin/$script "'"$@"' >> "$targetScript"
else else
# Python executable - run it via # Python executable - run it via
# $FSLDIR/bin/python in isolated mode # $FSLDIR/bin/python in isolated mode
echo "#!/bin/sh" > "$targetScript" echo "#!/usr/bin/env bash" > "$targetScript"
echo "$FSLDIR/bin/python -I $sourceScript \"$@\"" >> "$targetScript" echo "$FSLDIR/bin/python -I $sourceScript "'"$@"' >> "$targetScript"
fi fi
# Preserve file permissions # Preserve file permissions
chmod --reference="$sourceScript" "$targetScript" chmod --reference="$sourceScript" "$targetScript"
done done
esac
#!/bin/sh #!/usr/bin/env bash
# #
# Remove wrapper script/links in $FSLDIR/share/fsl/bin/ which invoke commands # Remove wrapper script/links in $FSLDIR/share/fsl/bin/ which invoke commands
# that are installed in $FSLDIR/bin/. See createFSLWrapper.sh for more # that are installed in $FSLDIR/bin/. See createFSLWrapper.sh for more
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment