-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-nudge.sh
executable file
·119 lines (89 loc) · 3.26 KB
/
update-nudge.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
requiredInstallationFutureTime="T00:00:00Z"
leadTimeInDays="14"
# Shared functions for each major release
function setAboutUpdate {
# Set the About Update URL for each major release
if [[ "${majorVersionNumber}" == "11" ]] ; then
aboutUpdateURL="https://support.apple.com/en-us/HT211896" # What's new in the updates for macOS Big Sur
elif [[ "${majorVersionNumber}" == "12" ]] ; then
aboutUpdateURL="https://support.apple.com/en-us/HT212585" # What's new in the updates for macOS Monterey
else
aboutUpdateURL="https://support.apple.com/en-us/HT201541" # Update macOS on Mac
fi
echo "Setting About Update URL for ${majorVersionName} to ${aboutUpdateURL}…"
}
function getPatchResults {
# Get the latest release info from Jamf Patch
jamfPatchResults=$(curl -s "https://jamf-patch.jamfcloud.com/v1/software/${majorVersionPatchID}")
}
function getLatestVersionNumber {
# Get the latest version's version number, based on the Jamf Patch information
latestVersionNumber=$( echo "$jamfPatchResults" | grep currentVersion | tr -d '"' | awk '{ print $2 }')
echo "Latest version of ${majorVersionName} is ${latestVersionNumber}…"
}
function setRequiredInstallationDate {
# Get the latest version's release date, based on the Jamf Patch information
latestVersionReleaseDate=$( echo "$jamfPatchResults" | grep lastModified | tr -d '"' | awk '{ print $2 }' | cut -c1-10)
# Calculate the required installation date in the future, based upon the release date
# …for macOS
requiredInstallationFutureDate=$(date -j -v +${leadTimeInDays}d -f "%Y-%m-%d" "$latestVersionReleaseDate" +%Y-%m-%d)
# …for Linux
# requiredInstallationFutureDate=$(date -d "+$leadTimeInDays days" -I)
# Combine the date with the time for required installation
requiredInstallationDate="$requiredInstallationFutureDate$requiredInstallationFutureTime"
echo "Latest release date for ${majorVersionName} is ${latestVersionReleaseDate}, setting required installation date to ${requiredInstallationDate}…"
}
# Create a Nudge Event for each major release, and write them to nudge.json
function defineNudgeEvent {
setAboutUpdate
getPatchResults
getLatestVersionNumber
setRequiredInstallationDate
nudgeEventData="
{ // $majorVersionName
\"aboutUpdateURL\": \"$aboutUpdateURL\",
\"requiredInstallationDate\": \"$requiredInstallationDate\",
\"requiredMinimumOSVersion\": \"$latestVersionNumber\",
\"targetedOSVersionsRule\": \"$majorVersionNumber\"
}"
}
function createNudgeFile {
cat <<-EOF > nudge.json
{
"osVersionRequirements": [
EOF
echo "${osVersionMonterey},${osVersionBigSur}" >> nudge.json
scriptResult+="Updated nudge.json! "
echo $scriptResult
echo "
]
}" >> nudge.json
}
# Define major release
function nudgeMonterey {
majorVersionName="macOS Monterey"
majorVersionNumber="12"
majorVersionPatchID="41F"
defineNudgeEvent
osVersionMonterey="$nudgeEventData"
}
function nudgeBigSur {
majorVersionName="macOS Big Sur"
majorVersionNumber="11"
majorVersionPatchID="303"
defineNudgeEvent
osVersionBigSur="$nudgeEventData"
}
function nudgeLatest {
majorVersionName="macOS"
majorVersionNumber="default"
majorVersionPatchID="macOS"
defineNudgeEvent
osVersionLatest="$nudgeEventData"
}
nudgeBigSur
nudgeMonterey
# nudgeLatest
createNudgeFile
exit 0