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

RF: Change variable names to make script easier to follow

parent 8f6351a6
No related branches found
No related tags found
1 merge request!47ENH: New option in createFSLWrapper to generate wrapper script with different name to executable
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
# file systems are usually case-sensitive. # file systems are usually case-sensitive.
# #
# To work around this, and to not accidentally create a link called <Command> # To work around this, and to not accidentally create a link called <Command>
# to <command>, the FSL package post link scripts should only specify # to <command>, the FSL package post link scripts must only specify
# "<Command>_gui", and *not* "<Command>". This script will create a wrapper # "<Command>_gui", and *not* "<Command>". This script will create a wrapper
# script for the appropriate variant ("<Command>_gui" on macOS, or "<Command>" # script for the appropriate variant ("<Command>_gui" on macOS, or "<Command>"
# on Linux). # on Linux).
...@@ -60,60 +60,66 @@ targets="$@" ...@@ -60,60 +60,66 @@ targets="$@"
# Only create wrappers if the FSL_CREATE_WRAPPER_SCRIPTS # Only create wrappers if the FSL_CREATE_WRAPPER_SCRIPTS
# environment variable is set # environment variable is set
if [ -z "$FSL_CREATE_WRAPPER_SCRIPTS" ]; then if [ -z "${FSL_CREATE_WRAPPER_SCRIPTS}" ]; then
exit 0 exit 0
fi fi
# Only create wrappers if FSLDIR exists # Only create wrappers if FSLDIR exists
if [ ! -d "$FSLDIR" ]; then if [ ! -d "${FSLDIR}" ]; then
exit 0 exit 0
fi fi
# and if FSLDIR == PREFIX # and if FSLDIR == PREFIX
if [ "$FSLDIR" != "$PREFIX" ]; then if [ "${FSLDIR}" != "${PREFIX}" ]; then
exit 0 exit 0
fi fi
for script in $targets; do for targetName in ${targets}; do
sourceScript="${PREFIX}/bin/$script"
# Wrapper script for a FSL TCL GUI - here, we target="${PREFIX}/bin/${targetName}"
# remove the _gui suffix if no source file
# exists (in which we are likely running on
# Linux).
if [[ "$script" == *"_gui" ]] && [ ! -f "$sourceScript" ]; then
script=${script/_gui/}
sourceScript="${PREFIX}/bin/$script"
fi
targetScript="${FSLDIR}/share/fsl/bin/$script" # Wrapper script for a FSL TCL GUI - here,
# we remove the _gui suffix if the target
# file does not exist (in which case we are
# likely running on Linux).
if [[ "${targetName}" == *"_gui" ]] && [ ! -f "${target}" ]; then
targetName=${targetName/%_gui}
target=${target/%_gui}
fi
if [ ! -f "$sourceScript" ]; then # Don't create wrapper scripts for non-
# existent targets (e.g. the post-link.sh
# script for a package may be out-dated,
# and request wrappers for commmands that
# have been removed).
if [ ! -f "${target}" ]; then
continue continue
fi fi
wrapper="${FSLDIR}/share/fsl/bin/${targetName}"
# 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 wrapper script if it already exists
if [ -e "$targetScript" ]; then if [ -e "${wrapper}" ]; then
rm "$targetScript" rm "${wrapper}"
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. # executable.
id=$(head -c 1024 "$sourceScript" | grep -e '^#!.*pythonw\?$') id=$(head -c 1024 "${target}" | grep -e '^#!.*pythonw\?$')
# Non-python executable - use # Non-python executable - use
# a pass-through script # a pass-through script
if [ -z "$id" ]; then if [ -z "${id}" ]; then
echo "#!/usr/bin/env bash" > "$targetScript" echo "#!/usr/bin/env bash" > "${wrapper}"
echo "$FSLDIR/bin/$script "'"$@"' >> "$targetScript" echo "${target} "'"$@"' >> "${wrapper}"
else else
# Python executable - run it via # Python executable - run it via
...@@ -121,21 +127,21 @@ for script in $targets; do ...@@ -121,21 +127,21 @@ for script in $targets; do
# mode. Under macOS, GUI apps are # mode. Under macOS, GUI apps are
# invoked with pythonw, so we need # invoked with pythonw, so we need
# to preserve the interpreter. # to preserve the interpreter.
if [[ "$id" == *"pythonw" ]]; then if [[ "${id}" == *"pythonw" ]]; then
interp="pythonw" interp="pythonw"
else else
interp="python" interp="python"
fi fi
echo "#!/usr/bin/env bash" > "$targetScript" echo "#!/usr/bin/env bash" > "${wrapper}"
echo "${FSLDIR}/bin/${interp} -I $sourceScript "'"$@"' >> "$targetScript" echo "${FSLDIR}/bin/${interp} -I ${target} "'"$@"' >> "${wrapper}"
fi fi
# Preserve file permissions # Preserve file permissions
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "${OSTYPE}" == "darwin"* ]]; then
perms=$(stat -f "%A" "$sourceScript") perms=$(stat -f "%A" "${target}")
chmod ${perms} "$targetScript" chmod ${perms} "${wrapper}"
else else
chmod --reference="$sourceScript" "$targetScript" chmod --reference="${target}" "${wrapper}"
fi fi
done done
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