-
Notifications
You must be signed in to change notification settings - Fork 5
/
JamfPro-Casper-EA-ComputerName_AssetID.sh
executable file
·87 lines (63 loc) · 2.07 KB
/
JamfPro-Casper-EA-ComputerName_AssetID.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
#!/bin/sh
#Purpose - Jamf Pro EA to check if Computer Name matches ASSET ID
## API READ ONLY user info for Jamf Pro. Please specify
apiuser="apiuser"
apipass="apipass"
## Local Copy of ASSET ID
Asset_PATH="/Library/Application Support/JAMF/assetid"
#Have we checked this before#
if [ -e "${Asset_PATH}" ]
then
Local_Asset_Tag=$(head -n 1 "${Asset_PATH}")
fi
if [ -z "${Local_Asset_Tag}" ]
then
## Grab Jamf Pro URL
jssurl=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's:/*$::')
## Get the computer's serial number (for locating the record in the API)
Serial_Num=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
if [ -z "${Serial_Num}" ]
then
echo "<result>SERIAL NUMBER ERROR</result>"
exit 1
fi
## Generate variable containing "location" information on the computer record
Comp_Location_Data_RAW=$(curl -H "Accept: text/xml" -isku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers/serialnumber/${Serial_Num}/subset/general")
## Check API Call
API_CHECK=$(echo "${Comp_Location_Data_RAW}" | head -n 1 | cut -d' ' -f2 | awk '{print $1}' 2>/dev/null)
if [ "${API_CHECK}" = "401" ]
then
echo "<result>BAD API USER</result>"
exit 1
fi
if [ "${API_CHECK}" != "200" ]
then
echo "<result>BAD API CALL</result>"
exit 1
fi
Comp_Location_Data=$(echo "${Comp_Location_Data_RAW}" | grep "<?xml" | xmllint --format - 2>/dev/null)
## Extract items from the above variable
Asset_Tag=$(echo "${Comp_Location_Data}" | awk -F'>|<' '/<asset_tag/{print $3}' 2>/dev/null)
echo "${Asset_Tag}" > "${Asset_PATH}"
else
#Use existing value#
Asset_Tag="${Local_Asset_Tag}"
fi
if [ -z "${Asset_Tag}" ]
then
echo "<result>NO ASSET TAG</result>"
exit 1
fi
Computer_Name=$(/usr/local/bin/jamf getComputerName | awk -F'>|<' '/<computer_name/{print $3}' 2>/dev/null)
if [ -z "${Computer_Name}" ]
then
echo "<result>COMPUTER NAME ERROR</result>"
exit 1
fi
## Print back what was found
if [ "${Asset_Tag}" = "${Computer_Name}" ]
then
echo "<result>True</result>"
else
echo "<result>False</result>"
fi