Created
February 11, 2015 23:07
-
-
Save gjpalau/f30fbf432ab62540ece0 to your computer and use it in GitHub Desktop.
Rename your computer depending on your chassis+yourmacserialnumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# uniMIS renamer script -- use with ComputerName name below | |
# By Gilbert Palau, Enterprise OS X - www.enterpriseosx.com | |
# | |
# this script renames the mac by chassi type + serial number: ??-SERIAL | |
# | |
# variables: | |
laptop="ML-" | |
workstation="MW-" | |
server="S-" | |
tld="your.network.com" | |
# grabbing mac serial number... | |
serial=$(ioreg -l |grep "IOPlatformSerialNumber"|cut -d ""="" -f 2|sed -e s/[^[:alnum:]]//g) | |
# and model name... | |
model=$(ioreg -l |grep "product-name" |cut -d ""="" -f 2|sed -e s/[^[:alnum:]]//g | sed s/[0-9]//g) | |
# renaming based on model ie. prefix-computerserial.tld | |
case "$model" in | |
"MacBookPro" ) | |
/usr/sbin/scutil --set ComputerName "$laptop$serial" | |
/usr/sbin/scutil --set LocalHostName "$laptop$serial" | |
/usr/sbin/scutil --set HostName "${laptop}${serial}.${tld}" | |
echo "$model" | |
echo "$laptop$serial" | |
echo "${laptop}${serial}.${tld}" | |
;; | |
"MacBookAir" ) | |
/usr/sbin/scutil --set ComputerName "$laptop$serial" | |
/usr/sbin/scutil --set LocalHostName "$laptop$serial" | |
/usr/sbin/scutil --set HostName "${laptop}${serial}.${tld}" | |
echo "$model" | |
echo "$laptop$serial" | |
echo "${laptop}${serial}.${tld}" | |
;; | |
"MacPro" ) | |
/usr/sbin/scutil --set ComputerName "$workstation$serial" | |
/usr/sbin/scutil --set LocalHostName "$workstation$serial" | |
/usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}" | |
echo "$model" | |
echo "$workstation$serial" | |
echo "${workstation}${serial}.${tld}" | |
;; | |
"iMac" ) | |
/usr/sbin/scutil --set ComputerName "$workstation$serial" | |
/usr/sbin/scutil --set LocalHostName "$workstation$serial" | |
/usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}" | |
echo "$model" | |
echo "$workstation$serial" | |
echo "${workstation}${serial}.${tld}" | |
;; | |
"Macmini" ) | |
/usr/sbin/scutil --set ComputerName "$workstation$serial" | |
/usr/sbin/scutil --set LocalHostName "$workstation$serial" | |
/usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}" | |
echo "$model" | |
echo "$workstation$serial" | |
echo "${workstation}${serial}.${tld}" | |
;; | |
"Xserve" ) | |
/usr/sbin/scutil --set ComputerName "$server$serial" | |
/usr/sbin/scutil --set LocalHostName "$server$serial" | |
/usr/sbin/scutil --set HostName "${server}${serial}.${tld}" | |
echo "$model" | |
echo "$server$serial" | |
echo "${server}${serial}.${tld}" | |
;; | |
* ) | |
echo "Computer model not found." | |
exit 0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment