Skip to content

Instantly share code, notes, and snippets.

@badstreff
Created October 12, 2017 21:33
Show Gist options
  • Save badstreff/291ce88226a21d05bb2e2dce8c89b66c to your computer and use it in GitHub Desktop.
Save badstreff/291ce88226a21d05bb2e2dce8c89b66c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Apply Updates
defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
sleep 1
output="$(softwareupdate --install --all 2>&1)"
sleep 1
defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool false
# restart and notifcy user if needed
grep -i -q "restart" "$output"
if [ $? -eq 0 ] ; then
echo "Restarting in 2 minute and notifying user..."
jamf DisplayMessage -message "Your machine has installed updates that require a restart. Please save your work and quit any applications you have open. Your machine will restart in 2 minutes."
shutdown -r +2
else
echo "Restart not required"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment