|
This is something I've been wanting to make public for some time now. In the
dusty back archives of macosxlabs is my old StartupItem version of this which
depended upon ncutil.
The new version (well, not new here but...) uses launchd and scutil so no
extra software. We've been running it fine here on everything since 10.4 came
out:
Click here to download the Cornell Namer.
Instructions:
Copy cornellnamer.plist to /Library/LaunchDaemons
Create /Library/AdminItems and copy cornellNamer.sh to this directory
Edit the dnsbase variable as appropriate for your domain
The script assumes that you have static IPs and a DNS that names each computer
uniquely (in our case the name matches the asset tag for the machine)
cornellNamer.sh:
#! /bin/sh
#
# Cornell Computer Namer
# Modifications by
# Sam Agnew
# Weill Cornell Medical College in Qatar
# January 22, 2004
#
# Based upon
# Panther Post-Image Setup SPRING 2004
# ComputerName
# January 9, 2004
#
# Now launched via launchd
# Now using scutil
# Now using qatar-med.cornell.edu
# Sam Agnew
# July 31, 2005
# Minor cleanup for release November 9, 2005
test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d'
-e '/inet/p' | wc -l)
# Max wait for network in seconds / 2
limit=60
# Set domain name base here
dnsbase=".qatar-med.cornell.edu"
# Set Initial Name and try to make it unique
TEMPNAME="Waiting-for-network${RANDOM}"
scutil --set ComputerName $TEMPNAME
scutil --set LocalHostName $TEMPNAME
# Wait for network
X=0
while [ $test != 1 ]
do
echo Network not currently up
test=$(ifconfig -a inet 2>/dev/null
| sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l)
X=$((X+1))
if [ $X -ge $limit ]; then
break
fi
sleep 2
done
HWADDRESS=`ifconfig en0 | grep ether | awk '{print $2}'`
IPADDRESS=`ifconfig en0 | grep inet\ | awk '{print $2}'`
COMPUTERNAME=$(host $IPADDRESS | awk '{ print $5 }' | sed s/${dnsbase}.//)
###### IF COMPUTERNAME IS BLANK, SET NAME TO HWADDRESS, OTHERWISE SET TO
VALUE CALCULATED FROM DNS LOOKUP ######
if [ "$COMPUTERNAME" = "no" ]; then
NONAME="`echo $HWADDRESS`-DHCP-Error"
scutil --set ComputerName $NONAME
scutil --set LocalHostName $NONAME
elif [ "$COMPUTERNAME" = "" ]; then
NONAME="`echo $HWADDRESS`-Network-Connection-Failure"
scutil --set ComputerName $NONAME
scutil --set LocalHostName $NONAME
elif [ "$COMPUTERNAME" = "3(NXDOMAIN)" ]; then
NONAME="`echo $HWADDRESS`-No-DNS-Record-For-Host"
scutil --set ComputerName $NONAME
scutil --set LocalHostName $NONAME
else
scutil --set ComputerName $COMPUTERNAME
scutil --set LocalHostName $COMPUTERNAME
fi
if [ $(who|grep console|wc -l) == 0 ]; then
if [ $(ps wwaux|grep WaitingForLoginWindow|grep -v grep|wc
-l) == 0 ]; then
killall loginwindow
fi
fi
killall syslogd
cornellnamer.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>edu.cornell.qatar-med.cornellcomputernamer</string>
<key>ServiceDescription</key>
<string>Names computer based upon DNS resolution</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Library/AdminItems/cornellNamer.sh</string>
</array>
</dict>
</plist>
|