grahampugh / erase-install

A script that automates downloading macOS installers, and optionally erasing or upgrading macOS in a single process. Watch the video!
https://grahamrpugh.com/2023/05/14/macaduk-presentation-eraseinstall.html
Apache License 2.0
845 stars 132 forks source link

Bug: Exit Code 1 Not returned when power source or free disk space check fails #265

Closed pro4tlzz closed 1 year ago

pro4tlzz commented 2 years ago

I use erase-install with Jamf Pro. I deploy a self service policy for OS upgrades using erase-install and I specify a power source needs to be connected. I do this with --check-power The problem is if a power source isn't found erase-install doesn't return an exit code on completion. As a result of this Jamf Pro shows the policy as 'Completed'. Ideally one would rather see 'Failed'

erase-install is supposed to return an exit code (1) which indicates a failure if a condition such as the requirement for a power source or free disk space fails.

Here is an example of the current exit code (0) when the power source condition fails

   [erase-install] v26.0 script execution started: Mon Jul 11 16:33:46 BST 2022
   [erase-install] Caffeinating this script (pid=92016)
   [check_free_space] OK - 416 GB free/purgeable disk space detected
   [check_power_status] WARNING - No AC power detected
   [wait_for_power] Waiting for AC power...

   [erase-install] attempting to terminate the 'jamfHelper' process - Termination message indicates success
/Library/Management/erase-install/erase-install.sh: line 1042: 92046 Terminated: 15          "$jamfHelper" -windowType "utility" -title "${!dialog_power_title}" -description "${!dialog_power_desc} ${power_wait_timer_friendly}" -alignDescription "left" -icon "$dialog_confirmation_icon"

   [wait_for_power] ERROR - No AC power detected after waiting for 00h:01m:00s, cannot continue.

   [erase-install] attempting to terminate the 'caffeinate' process - Termination message indicates success
/Library/Management/erase-install/erase-install.sh: line 1042: 92032 Terminated: 15          /usr/bin/caffeinate -dimsu -w $$

0

I've tested with erase-install v26.0 so obviously I should update my pkg as well

pro4tlzz commented 2 years ago

Had a quick read through the code base, Exit code 1 is supposed to be returned for power check failures https://github.com/grahampugh/erase-install/blob/main/erase-install.sh#L1428

Another example for free disk space https://github.com/grahampugh/erase-install/blob/main/erase-install.sh#L305

grahampugh commented 2 years ago

As explained in Slack, the Run Processes field always returns 0. There is a PR open which provides an example script for adding to your Jamf policy to run erase-install.sh from the package with parameters: https://github.com/grahampugh/erase-install/pull/257

I'll take a look at this over the next few days and decide whether to support the script. I think it might be necessary for those of you that care about the exit status.

pro4tlzz commented 2 years ago

As explained in Slack, the Run Processes field always returns 0. There is a PR open which provides an example script for adding to your Jamf policy to run erase-install.sh from the package with parameters: #257

I'll take a look at this over the next few days and decide whether to support the script. I think it might be necessary for those of you that care about the exit status.

Thanks.

I've had a look and I like the idea of a launcher script aswell, I could just copy pasta my files and processes commands into a simple script but when it comes to helping people its easier if everyone used a standardised script for running erase-install

grahampugh commented 2 years ago

I have incorporated #257 into the pre-release of 27.0. Please test out the launcher script and see if it solves your issue.

pro4tlzz commented 2 years ago

Thank you! I'll definitely test

pro4tlzz commented 2 years ago

This works great

Added the launcher script to Jamf Pro

image

Executed from a device without power and a failure is returned image