#!/bin/sh
#@(#)HP Netstation Admin Scripts
#
# rmhostsentry	Remove the netstation specified in $1 from /etc/hosts
#

if [ $1 ]
then
	XTNAME=$1
else
	echo "ERROR: no netstation name supplied for command $0."
	exit 1
fi

if [ ! -f $HOSTTABLE ]
then
	echo "ERROR: $HOSTTABLE doesn't exist."
	exit 2
elif
	[ ! -r $HOSTTABLE ]
   then
	echo "No read permission for file $HOSTTABLE."
	exit 3
elif
	[ ! -w $HOSTTABLE ]
   then
	echo "No write permission for file $HOSTTABLE."
	exit 4
fi

awk "\$2 != \"$XTNAME\"" < $HOSTTABLE > $TMP/hosts
diff $TMP/hosts $HOSTTABLE > /dev/null 2>&1

if [ $? -ne 0 ]
then
  cp $TMP/hosts $HOSTTABLE 
  rm $TMP/hosts 
  exit 0
else
  awk "\$3 != \"$XTNAME\"" < $HOSTTABLE > $TMP/hosts
  diff $TMP/hosts $HOSTTABLE > /dev/null 2>&1
  if [ $? -ne 0 ]
  then
	cp $TMP/hosts $HOSTTABLE 
	rm $TMP/hosts 
	exit 0
  fi
  rm $TMP/hosts
  exit 5
fi

exit 0
