-
Notifications
You must be signed in to change notification settings - Fork 4
/
DEP-DEPNotify-assignFacstaff
68 lines (63 loc) · 1.93 KB
/
DEP-DEPNotify-assignFacstaff
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
#!/bin/bash
#
#
# Created by John Mahlman, University of the Arts Philadelphia ([email protected])
# Name: DEP-DEPNotify-assignFacstaff
#
# Purpose: Will populate the server with appropriate username and rename the machine
# at deployment time. Run AFTER DEPNotify collects information.
#
# Changelog
#
# 8/22/18 - New script to go with single DEPprovisioning instance.
#
#
# Get the JSS URL from the Mac's jamf plist file
if [ -e "/Library/Preferences/com.jamfsoftware.jamf.plist" ]; then
JSSURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)
else
echo "No JSS server set. Exiting..."
exit 1
fi
# Define API username and password information & JSS Group name from passed parameters
if [ ! -z "$4" ]; then
APIUSER="$4"
else
echo "No value passed to $4 for api username. Exiting..."
exit 1
fi
if [ ! -z "$5" ]; then
APIPASS="$5"
else
echo "No value passed to $5 for api password. Exiting..."
exit 1
fi
SERIAL=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
MODEL=$(system_profiler SPHardwareDataType | awk '/Model Identifier/ {print $3}')
if echo "$MODEL" | grep -q "MacBookAir"
then
PREFIX="MBA"
elif echo "$MODEL" | grep -q "MacBookPro"
then
PREFIX="MBP"
else
echo "No model identifier found."
PREFIX=""
fi
DNPLIST=/var/tmp/DEPNotify.plist
USERNAME=$(/usr/libexec/plistbuddy $DNPLIST -c "print 'Computer or User Name'" | tr [A-Z] [a-z])
COMPUTERNAME="${USERNAME}-${PREFIX}"
COMPUTERNAME=`echo ${COMPUTERNAME:0:15}`
# Update User in JSS
cat << EOF > /var/tmp/tempInfo.xml
<computer>
<location>
<username>$USERNAME</username>
</location>
</computer>
EOF
## Upload the xml file
/usr/bin/curl -sfku "$APIUSER":"$APIPASS" "$JSSURL"JSSResource/computers/serialnumber/"$SERIAL" -H "Content-type: text/xml" -T /var/tmp/tempInfo.xml -X PUT
rm -Rf /var/tmp/tempInfo.xml
# rename the computer
/usr/local/jamf/bin/jamf setComputerName -name "${COMPUTERNAME}"