mirror of
https://github.com/PurpleComputing/mdmscripts.git
synced 2026-02-12 01:54:26 +00:00
Create computer-rename.sh
This commit is contained in:
25
computer-rename.sh
Normal file
25
computer-rename.sh
Normal file
@@ -0,0 +1,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
|
||||
Reference in New Issue
Block a user