-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_update_magic Flash_Java.sh
87 lines (77 loc) · 3.05 KB
/
auto_update_magic Flash_Java.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
###
#
# Name: auto_update_magic.sh
# Description: A Casper script to assist in automatically updating apps,
# meant to be used in conjunction with autopkg/AutoPkgr and
# the jss-autopkg-addon.
# Author: Elliot Jordan <elliot@lindegroup.com>
# Created: 2013-03-24
# Last Modified: 2014-10-22
# Version: 1.3
#
###
apps=(
############################# EDIT BELOW THIS LINE #############################
# Add a line for each auto-updated app. The first part of the line is the name
# of the app itself. The second part of the line is the name of the recipe.
# The first and second parts are separated by a comma. Each line should be
# wrapped in double quotes. Like so:
# "Firefox, Firefox"
# "Google Chrome, GoogleChrome"
# "Skype, Skype"
# "Flash Player, AdobeFlashPlayer"
# "Google Earth, GoogleEarth"
# "Handbreak, Handbreak"
# "VLC, VLC"
# "iBooks Author, iBooksAuthor"
############################# EDIT ABOVE THIS LINE #############################
);
# This function checks whether the apps are running, and updates them if not
function AutoUpdateMagic () {
for app in "${apps[@]}"; do
echo " " # for some visual separation between apps in the log
process=$(echo $app | awk -F',' {'print $1'} | awk '{$1=$1}{ print }')
recipe=$(echo $app | awk -F',' {'print $2'} | awk '{$1=$1}{ print }')
if [[ `ps ax | grep -v grep | grep "$process" | wc -l` -gt 0 ]]; then
echo "$process is running. Skipping auto update."
else
echo "$process is not running. Calling policy trigger autoupdate-$recipe."
/usr/sbin/jamf policy -trigger "autoupdate-$recipe"
fi
done
/usr/bin/defaults write /Library/"Application Support"/JAMF/com.jamfsoftware.jamfnation LastAutoUpdateFlashJava $(date +%s)
}
# This function calculates whether it's time to run the auto updates
function AutoUpdateTimeCheck () {
seconds=$((60*60*Hours))
timeNow=$(date +%s)
timeDiff=$((timeNow-lastAutoUpdateTime))
if [[ "$timeDiff" -ge "$seconds" ]]; then
AutoUpdateMagic
exit 0
else
if [[ "$timeDiff" -lt "36000" ]]; then
/bin/echo "Auto updates not needed, last ran $((timeDiff/60)) minutes ago. Will run again in $((Hours*60-timeDiff/60)) minutes."
else
/bin/echo "Auto updates not needed, last ran $((timeDiff/60/60)) hours ago. Will run again in $((Hours*60-timeDiff/60)) minutes."
fi
exit 0
fi
}
# Number of hours between auto updates is taken from parameter 4, or defaults to 1
if [[ $4 != "" ]]; then
Hours=$4
else
Hours=1
fi
echo "We are checking for auto updates every $Hours hours."
lastAutoUpdateTime=$(/usr/bin/defaults read /Library/"Application Support"/JAMF/com.jamfsoftware.jamfnation LastAutoUpdateFlashJava 2> /dev/null)
if [[ "$?" -ne "0" ]]; then
echo "Auto Update Magic has never run before. Checking for updates now..."
AutoUpdateMagic
exit 0
else
AutoUpdateTimeCheck
fi
exit 0