-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathModelCheckCA.sh
33 lines (28 loc) · 1.32 KB
/
ModelCheckCA.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
#!/bin/bash
#
# File Name: ModelCheckCA.sh https://github.com/acodega/mosyle
# Custom command attribute to look up and report a Mac's marketing name
# MDMs including Mosyle use MDM commands to return a Mac's model identifier
# for inventory purposes, but Apple reuses model identifiers across model years.
# This CA checks Apple's support web service to retrieve the marketing name.
# Custom command attributes are intended for use with Mosyle MDM
#
## Get the Mac's serial number
serialNum=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
## Check the length of the serial number and set an appropriate string to use for the lookup
if [[ ${#serialNum} -ge 12 ]]; then
Serial=$(echo "$serialNum" | tail -c 5)
else
Serial=$(echo "$serialNum" | tail -c 4)
fi
## Get the full model name from Apple's support page, using the portion of the Serial Number
fullModelName=$(curl -s "https://support-sp.apple.com/sp/product?cc=${Serial}" | xmllint --format - 2>/dev/null | awk -F'>|<' '/<configCode>/{print $3}')
## If we didn't get an empty response, echo the full model name
if [ "$fullModelName" != "" ]; then
echo "$fullModelName"
## Echo the result for the EA
echo "$fullModelName"
else
## If we really weren't able to find anything, set "Not Found" as our result
echo "Not Found"
fi