From f175fb86dc07d2b8a2fbeb5eec91ba8dcf3369ca Mon Sep 17 00:00:00 2001 From: Zack T Date: Mon, 29 Jan 2018 22:06:18 -0700 Subject: [PATCH] v1.2 = Improved search for Existing App Bundles + Changed the interpreter to bash (was causing issues) + Changed up the while loop App existence check, as previously couldn't properly report "No versions found" --- Software/SPSS Statistics/uninstall_SPSS.sh | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Software/SPSS Statistics/uninstall_SPSS.sh b/Software/SPSS Statistics/uninstall_SPSS.sh index b5bb270..433027b 100644 --- a/Software/SPSS Statistics/uninstall_SPSS.sh +++ b/Software/SPSS Statistics/uninstall_SPSS.sh @@ -1,9 +1,9 @@ -#! /bin/sh +#! /bin/bash ################################################################################################### # Script Name: uninstall_SPSS.sh # By: Zack Thompson / Created: 11/1/2017 -# Version: 1.1 / Updated: 1/18/2018 / By: ZT +# Version: 1.2 / Updated: 1/25/2018 / By: ZT # # Description: Remove previous version(s) of SPSS from /Applications # @@ -11,18 +11,24 @@ /bin/echo "***** Uninstall SPSS process: START *****" -# If the machine has multiple SPSS Applications, loop through them... -/usr/bin/find -E /Applications -iregex ".*[/](SPSS) ?(Statistics) ?(\d\d)?[.]app" -type d -prune | while IFS="\n" read -r appPath; do +/bin/echo "Searching for existing SPSS instances..." +appPaths=$(/usr/bin/find -E /Applications -iregex ".*[/](SPSS) ?(Statistics) ?([0-9]{2})?[.]app" -type d -prune) - # Get the App Bundle name - appName=$(/bin/echo $appPath | /usr/bin/awk -F "/" '{print $NF}') - # Get only the install path - installPath=$(/bin/echo $appPath | /usr/bin/awk -F "/$appName" '{print $1}') - # Delete the old version - /bin/echo "Uninstalling: ${appPath}" - /bin/rm -rf "${installPath}" - -done +# Verify that a SPSS version was found. +if [[ -z "${appPaths}" ]]; then + /bin/echo "Did not find an instance SPSS!" +else + # If the machine has multiple SPSS Applications, loop through them... + while IFS="\n" read -r appPath; do + # Get the App Bundle name + appName=$(/bin/echo $appPath | /usr/bin/awk -F "/" '{print $NF}') + # Get only the install path + installPath=$(/bin/echo $appPath | /usr/bin/awk -F "/$appName" '{print $1}') + # Delete the old version + /bin/echo "Uninstalling: ${appPath}" + /bin/rm -rf "${installPath}" + done < <(/bin/echo "${appPaths}") +fi /bin/echo "***** Uninstall SPSS process: COMPLETE *****"