forked from jmahlman/Mac-Admin-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-ComputerName-EA.sh
56 lines (52 loc) · 1.47 KB
/
set-ComputerName-EA.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
#!/bin/sh
#
#
# Created by John Mahlman, University of the Arts Philadelphia ([email protected])
# Name: EA-computerName
#
# Purpose: Update our Computer Name receipt EA via the API.
#
#
# Changelog
#
# 7/27/18 - New script
#
# 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}')
if [ -f /Library/JAMF\ DM/ComputerName/ComputerName.txt ]; then
computerName=$(cat /Library/JAMF\ DM/ComputerName/ComputerName.txt)
else
computerName=""
fi
# Create xml
cat << EOF > /var/tmp/name.xml
<computer>
<extension_attributes>
<extension_attribute>
<name>New Computer Name</name>
<value>$computerName</value>
</extension_attribute>
</extension_attributes>
</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/name.xml -X PUT