:
#	%Z% %M% %I% %E% %Q%
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989, 1990.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#
PATH=/bin:/usr/bin:/etc:/.mitdir:/MIT/.mitdir:.
export PATH

# set the standard exit values
: ${OK=0} ${FAIL=1} ${STOP=10}

getyn() {
	while	echo "\n$* (y/n) \c">&2
	do	read yn rest
		case $yn in
		[yY])	return $OK 			;;
		[nN])	return $FAIL			;;
		*)	echo "Please answer y or n" >&2	;;
		esac
	done
}

TMP=/tmp/setname1$$
TMP2=/tmp/setname2$$
NBFILE=/etc/default/nbconf

TRAPMSG="<Del> key pressed or program killed.  Exiting."

# cleanup this mess

cleanup() {
	case $1 in
		$FAIL) echo "Error: $2" >&2 ;;
	esac
	rm -rf $TMP $TMP2
	exit $1
}

# main()

trap 'cleanup $FAIL "$TRAPMSG"' 1 2 3 15

echo "Setting the system name requires a kernel relink."
echo "To affect all changes required in setting the"
echo "system name you must also serialize the system so"
echo "the kernel can relink."
echo "Setting the system name without serializing"
echo "the system will leave the system name in an"
echo "intermediate state until serialization and relink"
echo "have taken place."
getyn "Do you wish to set the system name at this time ? " || exit $STOP

# set node name with uname -S, and /etc/systemid

NODENAME=`uname -n`
SAVENAME=$NODENAME

while :
do
	echo "\nThe current system node name is: $NODENAME"
	echo " "
	echo "This name identifies the target system to the"
	echo "rest of the world, and is stored in /etc/systemid"
	echo "and other files throughout the machine.  This"
	echo "name is an alphanumeric string that does not"
	echo "contain spaces or special characters, and that"
	echo "is 8 characters or less in length."
	echo " "
	echo "Enter new system node name: \c"
	read NODENAME
	uname -S $NODENAME && break
done

#name dependency action 1
/etc/conf/bin/idtune -f NODE "\"$NODENAME\""

#name dependency action 2
echo $NODENAME > /etc/systemid
chmod 644 /etc/systemid

#name dependency action 3
uname -S $NODENAME
echo " "

#name dependency action 4
#fix /etc/hosts so netbios will come up
if grep $SAVENAME /etc/hosts > /dev/null 2>&1
then
	echo "Updating /etc/hosts with new system name."
	sed 's/'"${SAVENAME}"'/'"${NODENAME}"'/g' /etc/hosts > $TMP2
	copy -om $TMP2 /etc/hosts
	rm $TMP2
	echo
fi

#name dependency action 5
rm -f /usr/spool/rwho/whod.${SAVENAME}
if [ -r "/usr/spool/rwho/whod.*" ]
then
	echo "Moving old network status"
	echo "/usr/spool/rwho/whod files to /tmp"
	echo " "
	copy -om /usr/spool/rwho/whod.* /tmp
	rm -f /usr/spool/rwho/whod.* 
fi

#name dependency action 6
#fix that default nbconf file
if [ -r "$NBFILE" ]; then
	echo "Networking system present."
	echo "MIT cannot configure a network.  When MIT"
	echo "completes, go to single user mode and then"
	echo "configure your network as needed."
	echo " "
	if grep NB_HOST $NBFILE > /dev/null 2>&1 &
	then
		echo "Updating $NBFILE with the new system name."
		sed 's/NB_HOST=.*/NB_HOST='"$NODENAME"'/g' $NBFILE > $TMP
		copy -om  $TMP $NBFILE
		rm $TMP
	fi
fi

#name dependency action 7
#set nodename if we have mmdf
[ -d /usr/mmdf ] && {
	echo "Updating MMDF mailer with the new system name."
	setmmdf
	cleanup $OK 
}
echo "The MMDF package is missing."
echo "No MMDF initialization occurred."

cleanup $OK
