diff --git a/share/fsl/sbin/createFSLWrapper b/share/fsl/sbin/createFSLWrapper index 5ad8a0bcf86c81184272ed0ca464b8c1ebaea075..07dfab0b5f9b71001225597246a5849c919c3a21 100755 --- a/share/fsl/sbin/createFSLWrapper +++ b/share/fsl/sbin/createFSLWrapper @@ -48,7 +48,7 @@ # file systems are usually case-sensitive. # # 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 # script for the appropriate variant ("<Command>_gui" on macOS, or "<Command>" # on Linux). @@ -60,60 +60,66 @@ targets="$@" # Only create wrappers if the FSL_CREATE_WRAPPER_SCRIPTS # environment variable is set -if [ -z "$FSL_CREATE_WRAPPER_SCRIPTS" ]; then +if [ -z "${FSL_CREATE_WRAPPER_SCRIPTS}" ]; then exit 0 fi # Only create wrappers if FSLDIR exists -if [ ! -d "$FSLDIR" ]; then +if [ ! -d "${FSLDIR}" ]; then exit 0 fi # and if FSLDIR == PREFIX -if [ "$FSLDIR" != "$PREFIX" ]; then +if [ "${FSLDIR}" != "${PREFIX}" ]; then exit 0 fi -for script in $targets; do - sourceScript="${PREFIX}/bin/$script" +for targetName in ${targets}; do - # Wrapper script for a FSL TCL GUI - here, we - # 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 + target="${PREFIX}/bin/${targetName}" - 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 fi + wrapper="${FSLDIR}/share/fsl/bin/${targetName}" + # create share/fsl/bin/ if it doesn't # already exist - if [ ! -e "$FSLDIR/share/fsl/bin" ]; then - mkdir -p "$FSLDIR/share/fsl/bin" + if [ ! -e "${FSLDIR}/share/fsl/bin" ]; then + mkdir -p "${FSLDIR}/share/fsl/bin" fi - # remove target script if it already exists - if [ -e "$targetScript" ]; then - rm "$targetScript" + # remove wrapper script if it already exists + if [ -e "${wrapper}" ]; then + rm "${wrapper}" fi # Figure out whether this is a python # executable or some other type of # executable. - id=$(head -c 1024 "$sourceScript" | grep -e '^#!.*pythonw\?$') + id=$(head -c 1024 "${target}" | grep -e '^#!.*pythonw\?$') # Non-python executable - use # a pass-through script - if [ -z "$id" ]; then - echo "#!/usr/bin/env bash" > "$targetScript" - echo "$FSLDIR/bin/$script "'"$@"' >> "$targetScript" + if [ -z "${id}" ]; then + echo "#!/usr/bin/env bash" > "${wrapper}" + echo "${target} "'"$@"' >> "${wrapper}" else # Python executable - run it via @@ -121,21 +127,21 @@ for script in $targets; do # mode. Under macOS, GUI apps are # invoked with pythonw, so we need # to preserve the interpreter. - if [[ "$id" == *"pythonw" ]]; then + if [[ "${id}" == *"pythonw" ]]; then interp="pythonw" else interp="python" fi - echo "#!/usr/bin/env bash" > "$targetScript" - echo "${FSLDIR}/bin/${interp} -I $sourceScript "'"$@"' >> "$targetScript" + echo "#!/usr/bin/env bash" > "${wrapper}" + echo "${FSLDIR}/bin/${interp} -I ${target} "'"$@"' >> "${wrapper}" fi # Preserve file permissions - if [[ "$OSTYPE" == "darwin"* ]]; then - perms=$(stat -f "%A" "$sourceScript") - chmod ${perms} "$targetScript" + if [[ "${OSTYPE}" == "darwin"* ]]; then + perms=$(stat -f "%A" "${target}") + chmod ${perms} "${wrapper}" else - chmod --reference="$sourceScript" "$targetScript" + chmod --reference="${target}" "${wrapper}" fi done