#!/bin/sh
#@(#)HP Netstation Admin Scripts
#
# rmxt		Remove a netstation
#

set -a 

echo ""
echo ""
echo "	_________________________________________________"
echo "		HP NETSTATION ADMINISTRATIVE TASKS"
echo "			REMOVE A NETSTATION"
echo ""

getxtname remove

if [ $? -ne 0 ]
then
	exit 100
else
	XTNAME=`cat $TMP/XTNAME`
	rm $TMP/XTNAME
	SHORTNAME=`cat $TMP/NAME`
	rm $TMP/NAME
fi

while [ 0 ]
do
	echo ""
	$ECHO "Remove netstation $XTNAME? [y|n|?] (y): $NL"
	read SEL

	case $SEL in
	  y|Y|yes|YES|Yes|"")
		break
		;;
	     \?)
		cat <<EOF

Answering "y" will remove the netstation from:

	1. $HOSTTABLE    [and NIS(+) if appropiate]

	2. $BOOTPTABLE

	3. $EXPORTS

Answering "n" will:
	Return to the previous menu without removing the netstation.

EOF
		continue
		;;
	      *)
		exit 100
		;;
	esac
done

echo ""
rmbootpentry $XTNAME > $TMP/bootptab
if [ $? = 0 ]
then
  echo "$SHORTNAME removed from $BOOTPTABLE."
else
  echo "$SHORTNAME isn't in $BOOTPTABLE."
  echo "No change made to this file."
  echo ""
fi

if [ -s $TMP/bootptab ]
then
  cp $TMP/bootptab $BOOTPTABLE 
  rm $TMP/bootptab
fi

# nfsd running?
# if yes, remove terminal if it's in  /etc/exports 
#

if [ $OS != "sun4" -a $OS != "sun5" ]
then
  $PSCMD | fgrep -v "fgrep" | fgrep "nfsd" > /dev/null 2>&1
  if [ $? -eq 0 ]
  then

    if [ -f /opt/hpxt/enware2 -o -d /opt/hpxt/enware2 ]
    then
      NFSDIRS="/opt/hpxt/enware2/xthome/fonts /opt/hpxt/enware2/xthome/bin /opt/hpxt/enware2/xthome/config"
    fi
    if [ -f /usr/lib/X11/700X -o -d /usr/lib/X11/700X ]
    then
      NFSDIRS="$NFSDIRS /usr/lib/X11/700X/fonts /usr/lib/X11/700X/bin"
    fi

    for DIR in $NFSDIRS
    do
	undonfs $DIR
    done

  fi
fi


if [ -r /usr/lib/X11/700X/config/$SHORTNAME.cfg ]
then
   rm /usr/lib/X11/700X/config/$SHORTNAME.cfg > /dev/null 2>&1
   if [ $? = 0 ]
   then
      echo "Configuration file /usr/lib/X11/700X/config/$SHORTNAME.cfg removed."
   fi
fi

if [ -r /opt/hpxt/enware2/xthome/config/$SHORTNAME.cfg ]
then
   rm /opt/hpxt/enware2/xthome/config/$SHORTNAME.cfg > /dev/null 2>&1
   if [ $? = 0 ]
   then
      echo "Configuration file /opt/hpxt/enware2/xthome/config/$SHORTNAME.cfg removed."
   fi
fi

if [ $NISPLUSH = "true" ]
then
  echo ""
  CMD="nistbladm -r name=$XTNAME hosts.org_dir"
  echo "Execute the command \"$CMD\""
  $ECHO "to remove netstation from the NIS+ hosts table [y|n] (y): $NL"
  read SEL
  case $SEL in
    y|Y|YES|yes|"")
      echo $CMD | $SHE
      echo ""
       ;;
    *)
      :
      ;;
  esac
else
  echo ""
  fgrep "$XTNAME" $HOSTTABLE > /dev/null
  if [ $? = 0 ]
  then
    rmhostsentry $XTNAME
    if [ $? -eq 0 ]
    then
      echo "$SHORTNAME removed from $HOSTTABLE."
      if [ $AMHMASTER = "true" ]
      then 
        echo "Execute the command \"$MAKEHCMD\" to remove the"
        $ECHO "netstation from the NIS hosts database? [y|n] (y): $NL"
        read SEL
        case $SEL in
          y|Y|YES|yes|Yes|"")
	    HERE=`pwd`
	    echo $MAKEHCMD | $SHE
	    cd $HERE
	    ;;
	  *)
	    :
	    ;;
	esac
      else
        cat <<EOF

***************************************************************************
* If you are running Network Information Services (Yellow Pages) or BIND, *
* please ask your site network administrator to remove the IP address     *
* of this netstation from the NIS or BIND database.                        *
***************************************************************************

EOF
      fi
    else
      echo "$SHORTNAME is not present in $HOSTTABLE."
      echo "No change made to this file."
      exit 10
    fi
  fi
fi


exit 0

