-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPI_UpdatePreStagemacOS.sh
More file actions
63 lines (52 loc) · 2.3 KB
/
API_UpdatePreStagemacOS.sh
File metadata and controls
63 lines (52 loc) · 2.3 KB
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
#!/bin/bash
# 2025 10 28 MK
# Update all prestages to specific minimium macOS using APIutil. Cool tool!
APIUTIL="/Applications/API Utility.app/Contents/MacOS/apiutil"
DATESTR="$(date '+%Y%m%d_%H%M%S')"
LOG="Prestage_MinOS_Log_${DATESTR}.log"
# Jamf variables
NEW_MIN_OS="${4:-15.6}"
DRY_RUN="${5:-True}" # "True" or "False" (case-insensitive)
if [[ -z "$NEW_MIN_OS" ]]; then
echo "ERROR: NEW_MIN_OS parameter (\$4) is required"
exit 1
fi
echo "PreStage Minimum OS Report $(date)" | tee "$LOG"
echo "Requested minimum OS: $NEW_MIN_OS" | tee -a "$LOG"
echo "Dry Run: $DRY_RUN" | tee -a "$LOG"
echo "-----------------------------------" | tee -a "$LOG"
"$APIUTIL" --path "api/v3/computer-prestages" \
| jq -c '.results[] | select(.minimumOsSpecificVersion != null and .minimumOsSpecificVersion != "") | {id, displayName, minimumOsSpecificVersion}' \
| while read -r prestage; do
id=$(echo "$prestage" | jq -r '.id')
name=$(echo "$prestage" | jq -r '.displayName')
minos=$(echo "$prestage" | jq -r '.minimumOsSpecificVersion')
# Get full PreStage and sanity check name
"$APIUTIL" --path "api/v3/computer-prestages/$id" > "${id}.json"
detailName=$(jq -r '.displayName' "${id}.json")
if [[ "$detailName" != "$name" ]]; then
msg="SANITY CHECK FAILED: ID $id API name '$detailName' does not match summary name '$name'. Skipping."
echo "$msg" | tee -a "$LOG"
rm -f "${id}.json"
continue
fi
if [[ "$minos" == "$NEW_MIN_OS" ]]; then
msg="ID: $id | Name: $name | Current min OS: $minos [OK]"
echo "$msg" | tee -a "$LOG"
rm -f "${id}.json"
else
if [[ "$DRY_RUN" =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
msg="DRY RUN would update ID: $id ($name) from $minos to $NEW_MIN_OS"
echo "$msg" | tee -a "$LOG"
rm -f "${id}.json"
else
jq --arg minos "$NEW_MIN_OS" '.minimumOsSpecificVersion = $minos' "${id}.json" > "${id}_updated.json"
"$APIUTIL" --path "api/v3/computer-prestages/$id" --method PUT --data "${id}_updated.json"
msg="Update ID: $id ($name) from $minos to $NEW_MIN_OS"
echo "$msg" | tee -a "$LOG"
rm -f "${id}.json" "${id}_updated.json"
fi
fi
done
echo "-----------------------------------" | tee -a "$LOG"
echo "Done. Log saved to $LOG"