OS X computername and HD naming script snippets from first-run script for user workstations
setup with a real full name, eg: Joe Public.
For a MacBook Pro (for example), this will set the computername to: JPublic-MacBookPro
and the unit's drive name to: JPublic_HD
As you'll note, in this instance after your machine has been imaged, the default Hard Drive name ends with: Imaged,
but you could easily change it to grab whatever the current drive name is, and change that.
This is run via a launchd plist which is unloaded by the script. There's an extra failsafe via check for a file that's created as well.
In this example, your plist is named com.yourcompany.firstrun.plist
which runs /usr/local/firstrun.sh
Important: the dscl items are there for use with dslocal MCX.
Seehttp://www.afp548.com/article.php?story=using-mcx-in-the-dslocal-domain and
http://managingosx.wordpress.com/2008/02/07/mcx-dslocal-and-leopard
Snippets from firstrun.sh
if [ ! -f /Library/.firstrunsetup_done ]; then # setup hardware model, UUID, MAC address and username variables tUsr=$(/usr/bin/who | /usr/bin/grep console | /usr/bin/cut -d " " -f 1) fName=$(dscl . -read /Users/${tUsr} RealName | awk '/ / {print substr($1,1,1)}') lName=$(dscl . -read /Users/${tUsr} RealName | awk '/ / {print $2}') pName=${fName}${lName} cModel=$(sysctl -n hw.model | sed 's/[0-9]//g;s/,//g') nHost="${pName}"-"${cModel}" networksetup -setcomputername $nHost dscl . -create /Computers/localhost GeneratedUUID $(uuidgen) dscl . -create /Computers/localhost ENetAddress $(ifconfig en0 |grep ether | awk '{print $2}') hDorig=$(diskutil list | grep Imaged | awk '{ print $6 }') hDname="${pName}"_HD diskutil rename $hDorig $hDname touch /Library/.firstrunsetup_done launchctl unload -w /Library/LaunchAgents/com.yourcompany.firstrun.plist fi