Script Not running after policy Snooze

TCP
New Contributor

So I created a Script to Update Microsoft Office to Leverage .msupdate
The Scrip Also Leverages jamfhelper to allow deferral of the Proccess.

So the Basics are 1. Ask Mac if it has any Office apps that need Updating
2. If yes then pops up window asking user to install or Snooze

The problem arises when the policy is Snoozed It just ups and fails hard.
But if the policy is just install now it works fine.

The Computer I am testing against is a VM running 10.14.6
Please take a look at my script see what is going wrong.

#!/bin/bash

MSUpdate=$(/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/msupdate -l | grep "Updates available:" | awk '{print $2}')


if [[ "$MSUpdate" == available: ]]
    then
        echo "Updates Availible"
            else 
                echo "No MS Updates" 
                exit 0
                    fi


windowType=""     #   [hud | utility | fs]
windowPosition="" #   [ul | ll | ur | lr]
title=""          #   "string"
heading=""            #   "string"
description=""        #   "string"
icon=""               #   path
iconSize=""           #   pixels
timeout=""            #   seconds

[ "$4" != "" ] && [ "$windowType" == "" ] && windowType=$4
[ "$5" != "" ] && [ "$windowPosition" == "" ] && windowPosition=$5
[ "$6" != "" ] && [ "$title" == "" ] && title=$6
[ "$7" != "" ] && [ "$heading" == "" ] && heading=$7
[ "$8" != "" ] && [ "$description" == "" ] && description=$8
[ "$9" != "" ] && [ "$icon" == "" ] && icon=$9
[ "$10" != "" ] && [ "$iconSize" == "" ] && iconSize=$10
[ "$11" != "" ] && [ "$timeout" == "" ] && timeout=$11

function setSnooze ()
{

## Get the time right now in Unix seconds
timeNow=$(date +"%s")
## Calculate the time for the next available display of the prompt (adds the time now and time chosen together in seconds)
timeNextRun=$((timeNow+SnoozeVal))

## Create or update a plist value containing the above next time to run value
/usr/bin/defaults write /Library/Preferences/com.acme.policy_001.snooze.plist DelayUntil -int $timeNextRun

exit 0

}

function showPrompt ()
{

## Prompt, and capture the output
HELPER=$("/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfhelper" -windowType "$windowType" -windowPosition "$windowPosition" -title "$title" -heading "$heading" -description "$description"  -icon "$icon" -iconSize "$iconSize" -button1 Install Now” -button2 Snooze -defaultButton 2 -cancelButton "2" -countdown "$timeout" -timeout "$timeout" -showDelayOptions "900, 1800, 3600, 7200, 14400")

echo "jamf helper result was $HELPER"

## Dissect the response to get just the button clicked and the value selected from the drop down menu
ButtonClicked="${HELPER: -1}"
SnoozeVal="${HELPER%?}"

echo "$ButtonClicked"
echo "$SnoozeVal"

if [ "$ButtonClicked" == "1" ]; then
    echo "User chose Install"
    /Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/msupdate -i
    exit 0
elif [ "$ButtonClicked" == "2" ]; then
    echo "User chose Snooze"
    setSnooze
fi

}

## Get a value (if possible) from a plist of the next valid time we can prompt the user
SnoozeValueSet=$(/usr/bin/defaults read /Library/Preferences/com.acme.policy_001.snooze.plist DelayUntil 2>/dev/null)

## If we got something from the plist...
if [ -n "$SnoozeValueSet" ]; then
    ## See what time it is now, and compare it to the value in the plist.
    ## If the time now is greater or equal to the value in the plist, enough time has elapsed, so...
    timeNow=$(date +"%s")
    if [[ "$timeNow" -ge "$SnoozeValueSet" ]]; then
        ## Display the prompt to the user again
        showPrompt
    else
        ## If the time now is less than the value in the plist, exit
        echo "Not enough time has elapsed. Exiting..."
        exit 0
    fi
else
    ## If no value was in the plist or the plist wasn't there, assume it is the first run of the script and prompt them
    showPrompt
fi
0 REPLIES 0