Created
December 4, 2020 10:15
-
-
Save bochoven/6ef8d65621fc597dae3b02c65e95f4f3 to your computer and use it in GitHub Desktop.
Set MunkiReport Machinegroup based on Jamf department
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This ugly script sets the proper passphrase per department | |
# it retrieves the department via the JAMF API | |
API_URL=https://YOURJAMFSERVER:8443/JSSResource | |
API_USER=api_user | |
API_PASS=$4 | |
# Get serial number | |
myserial=$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}') | |
# Get department | |
department=$(curl -sku "$API_USER":"$API_PASS" \ | |
-X GET \ | |
-H "accept: text/xml" \ | |
"$API_URL"/computers/serialnumber/$myserial | xmllint --xpath '/computer/location/department/text()' -) | |
# convert html entities | |
department=$( echo $department | php -r 'while(($line=fgets(STDIN)) !== FALSE) echo html_entity_decode($line, ENT_QUOTES|ENT_HTML401);') | |
MACHINEKEY="this.machine.is.unassigned" | |
case $department in | |
'Department 1') | |
MACHINEKEY="xxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxx" | |
;; | |
'Department 2') | |
MACHINEKEY="xxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxx" | |
;; | |
'Etc.') | |
MACHINEKEY="xxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxx" | |
;; | |
*) | |
esac | |
defaults write MunkiReport Passphrase $MACHINEKEY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment