Skip to content

Instantly share code, notes, and snippets.

@sgmills
Last active July 27, 2022 12:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgmills/b485206863efacb3e612c7025c238e7f to your computer and use it in GitHub Desktop.
Save sgmills/b485206863efacb3e612c7025c238e7f to your computer and use it in GitHub Desktop.
#!/bin/sh
# Location of macOS Build plist for comparison
# Subsitute your org name for anyOrg, or place in another location
buildPlist="/usr/local/anyOrg/macOSBuild.plist"
# Get the local os build version
# Using build version accounts for supplimental updates as well as dot updates and os upgrades
localOS=$( /usr/bin/sw_vers | awk '/BuildVersion/{print $2}' )
# If the macOS Buld plist key does not exist, create it and write the local os into it
if ! /usr/libexec/PlistBuddy -c 'print "macOSBuild"' $buildPlist &> /dev/null; then
echo "macOS Build plist does not exist. Creating now..."
defaults write $buildPlist macOSBuild $localOS
else
echo "macOS Build plist already exists. Skipping creation..."
fi
# Get the os from the macOS build plist now that we have ensured it exists
plistOS=$( defaults read $buildPlist macOSBuild )
# If the local OS does not match the plist OS do some maintainance
if [[ $localOS != $plistOS ]]; then
echo "macOS was updated. Performing maintenance now..."
# Update inventory
echo "Updating inventory..."
/usr/local/bin/jamf recon
# Update the local plist file
echo "Updating plist with new OS build version..."
defaults write $buildPlist macOSBuild $localOS
else
echo "macOS was not updated. Nothing to do here."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment