From 3f347d5c88b2017a822e8bb1d678d99e4b0988e2 Mon Sep 17 00:00:00 2001 From: Daniel Kerwin Date: Tue, 1 Feb 2022 13:31:39 +0100 Subject: [PATCH] Fail the scripts when command fail and return 1 in error cases --- reissueKey.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/reissueKey.sh b/reissueKey.sh index 4cb5b79..886cfbd 100644 --- a/reissueKey.sh +++ b/reissueKey.sh @@ -73,6 +73,10 @@ # Parameter 7 = Custom Branding - Defaults to Self Service Icon #Customizing Window +## Exit the script when a command or piped action fails +set -e +set -o pipefail + selfServiceBrandIcon="/Users/$3/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png" jamfBrandIcon="/Library/Application Support/JAMF/Jamf.app/Contents/Resources/AppIcon.icns" fileVaultIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/FileVaultIcon.icns" @@ -99,7 +103,6 @@ else brandIcon=$fileVaultIcon fi - ## Get the logged in user's name userName=$(/usr/bin/stat -f%Su /dev/console) @@ -147,7 +150,7 @@ end run") if [ "$?" == "1" ] then echo "User Canceled" -exit 0 +exit 1 fi try=$((try+1)) if [[ $BUILD -ge 13 ]] && [[ $BUILD -lt 17 ]]; then @@ -196,7 +199,7 @@ end run" if [ "$?" == "1" ] then echo "User Canceled" -exit 0 +exit 1 else try=$(($try+1)) fi @@ -220,7 +223,7 @@ if [ $try -ge $maxTry ] then haltAlert echo "Quitting.. Too Many failures" -exit 0 +exit 1 else echo $result errorAlert