#!/bin/csh -f
#
# Script to edit hostname in rc.conf...
#
# $Source: /afs/.net.mit.edu/tools/src/chhostname/RCS/chhostname,v $
# $Author: tom $
# $Header: /afs/.net.mit.edu/tools/src/chhostname/RCS/chhostname,v 1.2 92/08/05 14:30:23 tom Exp $
#
#

set path = (/bin/athena /usr/ucb /usr/bin /bin)

set CONFFILE = /etc/athena/rc.conf
set address  = no

if(! -w ${CONFFILE}) then
	echo "You do not have write access to ${CONFFILE} to change hostname."
	exit 1
endif

while ($address == "no") 
	echo -n "new hostname: "
	set hostname = ($<)
	if($hostname == "") then
		exit 0
	endif
	set address  = `hostinfo -a $hostname`
	if($status) then
		set address = no
		echo "$hostname is not registered, try again."
	else 	
		set hostname = `hostinfo -h $hostname`
		if($status) then
			echo "Error while getting canonical host name. Sorry."
			exit 1
		endif	
	endif
end

ed << EOF > /dev/null
r ${CONFFILE}
/HOST=/
d
i
HOST=$hostname; 	export HOST		# Hostname
.
/ADDR=/
d
i
ADDR=$address; 	export ADDR		# Address
.
w
q
EOF

echo "reboot for change to take effect."
