#!/bin/sh
#
# FOR MIPS SYSTEMS ONLY !!!
#
# Change the system name.
#
# Sets the hostname and restarts the network with this new name
#
#set -x

if test -s BITPATH
then
  CURPATH=`cat BITPATH`
else
  CURPATH=`pwd`
fi

SYSNAME=`cat $CURPATH/SYSNAME 2> /dev/null`
TYPE=`uname -t`

if [ "$SYSNAME" = "" ]
then
	SYSNAME=`head -1 /etc/local_hostname 2> /dev/null`
fi

if [ $# -ge 1 ]
then
	NEWNAME=$1
else
	echo ""
	/bin/echo "Enter new host name ($SYSNAME) \c"
	read NEWNAME
	if [ "$NEWNAME" = "" ] 
	then
		NEWNAME="$SYSNAME"
	fi
fi

echo "Changing system name from $SYSNAME to $NEWNAME."

echo "$NEWNAME" > $CURPATH/SYSNAME

/usr/ucb/hostname $NEWNAME 1> /dev/null 2>&1

echo "   hostname updated"

sed "s/`head -1 /etc/local_hostname 2> /dev/null`/$NEWNAME/" /etc/local_hostname \
	> /usr/tmp/local_hostname.new
cp -p /etc/local_hostname /usr/tmp/local_hostname.old
cp -p /usr/tmp/local_hostname.new /etc/local_hostname

/etc/init.d/tcp start 1> /dev/null 2>&1

echo "   network restarted"

uname -A

echo ""
