-
Notifications
You must be signed in to change notification settings - Fork 2
/
Reinstalls Jamf Framework for group
82 lines (64 loc) · 2.03 KB
/
Reinstalls Jamf Framework for group
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
#!/bin/bash
#Reinstalls Jamf Management Framework on every computer in a group
###########################
#Jamf credentials
username=""
password=""
url="https://xxxxxx.jamfcloud.com"
source credentials.sh
#Group ID number -- found in URL on computer group's page
groupid=""
###########################
#Token function -- based on https://developer.jamf.com/jamf-pro/docs/jamf-pro-api-overview
getBearerToken() {
response=$(curl -s -u "$username":"$password" "$url"/api/v1/auth/token -X POST)
bearerToken=$(echo "$response" | plutil -extract token raw -)
tokenExpiration=$(echo "$response" | plutil -extract expires raw - | awk -F . '{print $1}')
tokenExpirationEpoch=$(date -j -f "%Y-%m-%dT%T" "$tokenExpiration" +"%s")
}
#get token
getBearerToken
#pull XML data from Jamf, change it to a list
#curl: pull XML data based on group ID
#xmllint: keep only the mobile device IDs from the XML (e.g. <id>456</id>)
#1st sed: delete "<id>"s
#2nd sed: replace "</id>"s with spaces
#3rd sed: delete extra final space
devices=$(curl --request GET \
--silent \
--url $url/JSSResource/computergroups/id/$groupid \
--header 'Accept: application/xml' \
--header "Authorization: Bearer ${bearerToken}" \
| xmllint --xpath "//computer/id" - \
| sed 's/<id>//g' \
| sed 's/<\/id>/ /g' \
| sed 's/.$//')
#get total count of devices -- counting the number of "words" in $devices
numberDevices=$(echo -n "$devices" | wc -w)
echo $numberDevices Devices
echo
echo 0 /$numberDevices
#iterate over the IDs in this device group
counter=0
for value in $devices
do
#redeploy Jamf management framework for $value
curl --request POST \
--silent \
--url $url/api/v1/jamf-management-framework/redeploy/$value \
--header 'accept: application/json' \
--header "Authorization: Bearer $bearerToken" \
--output /dev/null
#print status every 10
let "counter+=1"
if [[ $(expr $counter % 10) = "0" ]]
then
echo $counter /$numberDevices
fi
#reset token every 500
if [[ $(expr $counter % 500) = "0" ]]
then
getBearerToken
fi
done
echo $numberDevices /$numberDevices