#!/bin/bash

title="Please Update Your Device"
description="Your Admin is asking for you to please update your Mac as soon as possible.

Clicking Open Software Update will open the Software Update pane for you to update your devices. Be sure to save all your files and close them before updating!
"
acceptText="Open Software Update"
closeText="Close"
timeOut=600
forefront="True"

/bin/launchctl kickstart -k system/com.apple.softwareupdated
if process=$(pgrep "System Preferences"); then
    kill -9 $(process)
fi
mv /Library/Receipts/InstallHistory.plist /Library/Receipts/InstallHistory.plist.old
sleep 3


if /Library/Addigy/macmanage/MacManage.app/Contents/MacOS/MacManage action=notify title="${title}" description="${description}" closeLabel="${closeText}" acceptLabel="${acceptText}" timeout="$timeOut" forefront="$forefront"; then
        # executes a desired command if the user clicks the Accept label.
        echo "Accept label clicked"
        open "x-apple.systempreferences:com.apple.preferences.softwareupdate"
        /Library/Addigy/macmanage/MacManage.app/Contents/MacOS/MacManage action=notify forefront="$forefront" closeLabel="${closeText}" title="${title}" description="WARNING: You may see a button to 'UPGRADE' your device. Do NOT click here as this prompt is to UPDATE your device.

If you see that the button appear as Upgrade Now, then under 'Other updates are available.' click 'More info', then click 'Install Now', and then 'Agree' to the prompts.

If you do not see any updates, please restart your Mac and check again.

If you've already updated and are still seeing this pop-up, please ignore this."
        exit 0
    else
        # executes a desired command if the user clicks the Close label.
        echo "Update was denied"
        exit 1
    fi