Halt a policy from a "Before" Bash script? Want to allow to cancel a package install.

dungeonadept
New Contributor II

I'm trying to add a warning to our Big Sur installer in Self Serve. I have the policy set to make sure users have to view the description, but that doesn't seem to be enough.

I've made a script with jamfHelper. It's a simple warning message to back up important files to our Google Drive before continuing, with a button to cancel and a button to continue.

In the policy, this warning is set to run "Before". The policy is working correctly, giving me the warning before trying to run the erase-install (grahampugh) script. However, I can't seem to get the Cancel button to actually halt the policy execution..

 

Can this be done? This is what I have so far.

RESULT=$("$jamfHelper" -windowType hud -title "Before you continue... Warning from the HelpDesk" -icon "$jamfIcon" -heading "$heading" -description "$description" -button1 "Cancel" -button2 "I understand." -defaultButton 1 -lockHUD -iconSize 200)

if [ "$RESULT" == 0 ]; then
# do button1 stuff
echo "Cancel was pressed!"
echo "error: script failed"
exit 1
elif [ "$RESULT" == 2 ]; then
# do button2 stuff
echo "OK was pressed!"
exit 0
fi
exit 1

 

 

1 ACCEPTED SOLUTION

sdagley
Honored Contributor II

@dungeonadept You can't gracefully halt policy execution from your script. You can achieve the behavior you want by using 2 policies. The 1st runs your prompt script. Create a 2nd policy that does the actual install which is executed by a custom event, then change your prompt script so that it calls `jamf policy -event <YourCustomeEventNameHere>` if the user selects OK.

View solution in original post

2 REPLIES 2

sdagley
Honored Contributor II

@dungeonadept You can't gracefully halt policy execution from your script. You can achieve the behavior you want by using 2 policies. The 1st runs your prompt script. Create a 2nd policy that does the actual install which is executed by a custom event, then change your prompt script so that it calls `jamf policy -event <YourCustomeEventNameHere>` if the user selects OK.

I had not thought of this. This should work perfectly. Thanks!