Assistance with a script

jonlju
Contributor

Hello,

By using DerFlounders post on upgrading OSX, I've started preparing a package for updating to macOS Sierra for those in our organization who are still on older versions of OSX. I got the following script from the same source but have modified it a bit...sadly, I know very little of scripting and while this seems to work, the issue is that while the script will prompt me if my power isn't connected (for example), it will not stop the script or policy from running. Everything else seems fine so far though.

Would anyone be able to assist me with what I'm doing wrong?

#!/bin/bash

available_free_space=$(df -g / | tail -1 | awk '{print $4}')
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
PowerSource=$(pmset -g ps | grep "Battery Power")
needed_free_space="$4"
os_name="$5"
insufficient_free_space_for_install_dialog="message goes here $os_name message goes here $available_free_space"
adequate_free_space_for_install_dialog="$os_name message goes here."
no_ac_power="Power message goes here"

if [ "$PowerSource" = "Now drawing from 'Battery Power'" ]; then
   jamf displayMessage -message "$no_ac_power"
   exit 1
fi 

if [[ "$available_free_space" -lt "$needed_free_space" ]]; then
   jamf displayMessage -message "$insufficient_free_space_for_install_dialog"
fi

if [[ "$available_free_space" -ge "$needed_free_space" ]]; then
   echo "$available_free_space gigabytes found as free space on boot drive. Installing OS."

   jamf displayMessage -message "$adequate_free_space_for_install_dialog"
fi

exit 0

Thank you in advance.

1 ACCEPTED SOLUTION

tthurman
Contributor III

Also assuming here, my guess is he runs the script with the policy. Rather than running a policy with the script.

So, the policy continues regardless of the script results.

My suggestion is to put a trigger in the script when it is okay to continue. That trigger would kick off the update.

--
TJ

View solution in original post

6 REPLIES 6

tthurman
Contributor III

Does it display the message for the "On Battery Power" part and then exit?

I don't understand your issue.

Could you rephrase?

Regards,
TJ

mike_pinto
New Contributor III

@tthurman Assuming they mean they receive the message, but it continues with the installation?

@jonlju What does the rest of your policy look like?

tthurman
Contributor III

Also assuming here, my guess is he runs the script with the policy. Rather than running a policy with the script.

So, the policy continues regardless of the script results.

My suggestion is to put a trigger in the script when it is okay to continue. That trigger would kick off the update.

--
TJ

jonlju
Contributor

@tthurman @mike.pinto You're both right! The script will prompt with a message if the power is not connected or there is insufficient disk space but the policy will still move on to download and install the macOS Sierra package.

The policy first runs the script and then downloads and installs the macOS Sierra package.

I'll do some reading on the triggers, I'm very new in this area. Thank you!

jonlju
Contributor

Hm, okay. The trigger seems to work better, but I might still be doing something wrong.

Here's the script now, I'm using two policies instead. One which contains the .dmg package (it was created by drag'n'dropping the installer package into Casper Admin) and then the one containing the script, triggering the other policy by a custom trigger.

This is what I get when I try to run it now:

jamf[4522]: Checking for policy ID 113...
jamf[4522]: Executing Policy macOS Sierra
jamf[4731]: Checking for policies triggered by "installmacOSSierra" for user "jonlju"...
jamf[4731]: Executing Policy Install macOS Sierra
jamf[4731]: Verifying package integrity...
jamf[4731]: Installing macOS Sierra.dmg...
jamf[4731]: Preparing for in-place OS upgrade...
jamf[4522]: Inventory will be updated when all queued actions in Self Service are complete.

However nothing happened past this point, so the upgrade never started running.

jonlju
Contributor

Marking this as solved, I added a trigger for restart as well and the upgrade will now run automatically using two policies with a custom trigger. Thank you!