From 3351bab8c4439bcbf632bd9b3e94cb20b04e70b9 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Wed, 11 Aug 2021 15:52:09 +0100
Subject: [PATCH] RF: Tweak wrapper create scripts to accommodate GUI wrappers

---
 share/fsl/sbin/createFSLWrapper | 14 ++++++++++++++
 share/fsl/sbin/removeFSLWrapper |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/share/fsl/sbin/createFSLWrapper b/share/fsl/sbin/createFSLWrapper
index cfb9c6e..c804c9c 100755
--- a/share/fsl/sbin/createFSLWrapper
+++ b/share/fsl/sbin/createFSLWrapper
@@ -66,6 +66,20 @@ fi
 
 for script in $targets; do
   sourceScript="${PREFIX}/bin/$script"
+
+  # FSL GUIs are called (e.g.) <Command> om Linux,
+  # but <Command>_gui on macOS, because macOS 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 only specify
+  # <Command>_gui. Here, we remove the _gui suffix
+  # if no source file exists (in which we are
+  # likely running on Linux)
+  if [ "$sourceScript" = *"_gui" ] && [ ! -f "$sourceScript" ]; then
+    sourceScript=${sourceScript/_gui/}
+  fi
+
   targetScript="${FSLDIR}/share/fsl/bin/$script"
 
   if [ ! -f "$sourceScript" ]; then
diff --git a/share/fsl/sbin/removeFSLWrapper b/share/fsl/sbin/removeFSLWrapper
index b99fdc3..feecb9f 100755
--- a/share/fsl/sbin/removeFSLWrapper
+++ b/share/fsl/sbin/removeFSLWrapper
@@ -32,6 +32,11 @@ fi
 for script in $targets; do
   targetScript="${FSLDIR}/share/fsl/bin/$script"
 
+  # See comment about FSL GUIs in post-link.sh
+  if [ "$targetScript" = *"_gui" ] && [ ! -f "$targetScript" ]; then
+    targetScript=${targetScript/_gui/}
+  fi
+
   if [ -f "$targetScript" ]; then
     rm "$targetScript"
   fi
-- 
GitLab