#!/sbin/sh
#@(#)HP X Station Admin Scripts
#
# rmxt		Remove an X station
#

set -a 

echo ""
echo ""
echo "	_________________________________________________"
echo "		HP X STATION ADMINISTRATIVE TASKS"
echo "			REMOVE AN X STATION"
echo ""

getxtname remove

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

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

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

Answering "y" will remove the X station from:

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

	2. $BOOTPTABLE

	3. $EXPORTS

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

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

echo ""
egrep "^$XTNAME" $BOOTPTABLE > /dev/null
if [ $? = 0 ]
then
  INBOOTP="YES"
  rmbootpentry $XTNAME < $BOOTPTABLE > $TMP/bootptab
  if [ $? -eq 0 ]
  then
    if [ -s $TMP/bootptab ]
    then
	cp $TMP/bootptab $BOOTPTABLE 
	rm $TMP/bootptab
	echo "$SHORTNAME removed from $BOOTPTABLE."
    else
	echo "Removal from $BOOTPTABLE failed."
    fi
  fi
else
	INBOOTP="NO"
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

    for DIR in $NFSDIRS
    do
	undonfs $DIR
    done

  fi
fi


echo ""
ls  $CONFIGDIR/$NAME.cfg > /dev/null 2>&1
if [ $? = 0 ]
then
   rm $CONFIGDIR/$NAME.cfg > /dev/null 2>&1
   if [ $? = 0 ]
   then
      echo "Configuration file $CONFIGDIR/$NAME.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 X station from the NIS+ hosts table [y|n] (y): $NL"
  SEL=`line` 
  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 "X station from the NIS hosts database? [y|n] (y): $NL"
        SEL=`line` 
        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 X station from the NIS or BIND database.                        *
***************************************************************************

EOF
      fi
    else
      echo "$SHORTNAME is not present in $HOSTTABLE."
      exit 10
    fi
  fi
fi

if [ $INBOOTP = "NO" ]
then
  echo "$SHORTNAME isn't in $BOOTPTABLE or $HOSTTABLE."
  echo "No changes were made to these files."
  echo ""
  exit 10
fi

exit 0

