From 2b20fcd816b2c01805bc06358bff7b61092de19a Mon Sep 17 00:00:00 2001 From: dwshore Date: Fri, 15 Nov 2019 14:02:08 -0500 Subject: [PATCH] Validate Installer Package Added error code #21 checkPackage runs a validation check with `codesign` and if it errors, exit the script and notify the user. --- OS_Upgrade.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/OS_Upgrade.sh b/OS_Upgrade.sh index eba6638..5165a03 100755 --- a/OS_Upgrade.sh +++ b/OS_Upgrade.sh @@ -59,6 +59,7 @@ # 17: Logged in user is not on the list of the FileVault enabled users. # 18: Password mismatch. User may have forgotten their password. # 19: FileVault error with fdesetup. Authenticated restart unsuccessful. +# 21: Installer failed validation. Replace your installer and try again. # Variables to determine paths, OS version, disk space, and power connection. Do not edit. available_free_space=$(/bin/df -g / | /usr/bin/tail -1 | /usr/bin/awk '{print $4}') @@ -484,6 +485,17 @@ minOSReqCheck (){ return 0 } +# Command to check validity of the installer package. If it's not valid, the install process resets and warns the user. +checkPackage () { + echo "Running validity check." + codesign -v $mac_os_installer_path + if [[ $? != 0 ]]; then + echo "Installer package is invalid. Reseting process" + "$jamfHelper" -windowType utility -icon "$alerticon" -heading "Installation Failure" -description "$upgrade_error" -button1 "Exit" -defaultButton 1 & + exit 21 + fi +} + # Function that determines what OS is on the macOS installer.app so that the appropriate startosinstall options are used as Apple has changed it with 10.12.4 # Supply a parameter $1 for this function that includes the macOS app installer you are using to upgrade. installCommand (){ @@ -546,6 +558,10 @@ installOS (){ exit 0 } +# Check the package is valid before installing +echo "Checking package integrity." +checkPackage + if [[ ! -e "$mac_os_installer_path" ]]; then downloadOSInstaller @@ -566,4 +582,4 @@ else installOS "" fi -exit 0 \ No newline at end of file +exit 0