-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer-rename.sh
More file actions
25 lines (18 loc) · 859 Bytes
/
computer-rename.sh
File metadata and controls
25 lines (18 loc) · 859 Bytes
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
#!/bin/sh
jssUser=$4
jssPass=$5
jssHost=$6
serial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
username=$(/usr/bin/curl -H "Accept: text/xml" -sfku "${jssUser}:${jssPass}" "${jssHost}/JSSResource/computers/serialnumber/${serial}/subset/location" | xmllint --format - 2>/dev/null | awk -F'>|<' '/<real_name>/{print $3}')
if [ "$username" == "" ]; then
echo "Error: Username field is blank."
exit 1
else
username="${username// /-}"
type=$(sysctl -n hw.model | cut -d "," -f 1 | tr -d '[0-9]_')
mac=$(networksetup -getmacaddress Wi-Fi | awk '{ field = substr($3,10,8) }; END{ print field }' | sed s/://g)
computerName="${username}-${type}-${mac}"
/usr/sbin/scutil --set HostName "$computerName"
/usr/sbin/scutil --set LocalHostName "$computerName"
/usr/sbin/scutil --set ComputerName "$computerName"
fi