Goal: A policy to force minor OS updates, then run a script alerting the end user twice that a reboot is required. The second alert is locked on screen. If the user does not interact with the script, the machine will reboot in 4 hours and successfully complete the policy. If the user force quits the second warning (cmd + q), the machine immediately reboots and successfully completes the policy. If the user manually reboots their machine, the policy is successfully completed.
Script:
#!/bin/sh
jamf displayMessage -message "Minor OS updates have been installed and your machine will reboot in 4 hours. It is recommended that you save your work and reboot immediately to prevent loss of work."
sleep 12600
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Reboot" -description "Your machine will reboot at $(date -v +30M). Please ensure all work is saved and restart within the next 30 minutes. Attempting to force quit (CMD + Q) will result in your machine restarting IMMEDIATELY." -lockHUD -timeout 1800
jamf reboot -immediately
As you can see, the user has 4 hours to reboot. The first message displays and immediately starts a 3h30 sleep (key point is that it doesn't wait for them to click OK to start the "timer"). Then a jamfHelper displays for 30 minutes warning users that they are about to reboot. With this code, if the user clicks OK to the initial warning and then has no further interaction with the script (i.e. let the second warning sit on screen for 30 minutes), then the script completes, and the policy is marked in JSS as completed.
The issue: If the user manually reboots at any point while the script is running, the script does NOT complete, which means (since no exit code 0) the policy remains as pending in the JSS. This gets the user stuck in a loop of the policy happening over and over again. If the user force quits (cmd + q) the 30 minute warning, it appropriately reboots the machine, however without exit code 0, and therefore the policy remains at pending in the JSS and the policy loop happens.
I've tried just using jamf reboot -minutes 30 -message "blah blah blah" -background, but I don't like this for two reasons; firstly, it reboots 30 minutes from acknowledging the message, and secondly, you can force quit the message. Granted, the message will continue popping up if you force quit it, but there is potential to just leave the message alone indefinitely and not reboot at all. Due to this, I would like to keep the jamf reboot -immediately portion.
If someone could help point me toward a method of getting the script to return an exit code 0 when the second warning is force quit, or the user manually reboots the machine at any point while the script is running, I believe this would resolve my issues. Any help is deeply appreciated!