#!/bin/sh


echo

set -a

umask 022

. /opt/hpxt/enware2/lbin/env.vars

if [ $? -ne 0 -o ! -d "$TOPDIR" ]
then
  echo "ERROR:   Could not locate installation directory of HPX2-BASE package."
  echo "ERROR:   This package must be installed before other packages"
  exit 1
fi


#################################################
#
# Check for a running xdm
#
#################################################


if [ $OS = "sun5" ]
then
  CMD="ps -ef"
  PIDFIELD="\$2"
  PPIDFIELD="\$3"
else
  CMD="ps -ax"
  PIDFIELD="\$2"
  PPIDFIELD="\$1"

fi
  
$CMD | grep -v grep | egrep 'enware2.*/xdm[ 	]' > /dev/null
if [ $? -eq 0 ]
then
  sleep 2
  cat <<EOF


         X D M    I N F O R M A T I O N  
        
  You seem to be running an existing version of xdm.
  This SW installation contains an upgraded version of xdm.
  The existing version should be taken down now before you continue.

  (all users logged on through xdm should ***LOG OFF*** first!)

  The new version of xdm will be started up later if you:
    1)  configure terminals using the "xtadm" administration script
     or 
    2) if you select <XDM Admin> from the main menu of xtadm 
       followed by <Start XDM>.
EOF
 
  while true
  do
    echo
    echo $NL1 "Take down xdm now? [y|n] (default=y): $NL2"
    REPLY=`line`
    case $REPLY in
      y|Y|yes|YES|y*|"")
 
        echo "{print $PIDFIELD}" > $TMP/awk 
        if [ $OS = "sun5" ]
        then
          P=`ps -ef | egrep '[ 	/]xdm'| fgrep -v fgrep \
		| awk "$PPIDFIELD == 1" | awk -f $TMP/awk`
        else
          P=`$PSCMD | egrep '[ 	/]xdm'| fgrep -v fgrep \
		| awk "$PPIDFIELD == 1" | awk -f $TMP/awk`
        fi

        if [ "$P" != "" ]
        then
            kill $P
            echo "xdm process $P stopped."
        fi

        break
          ;;
      n*|N*|q*|Q*)
        cat <<EOF

       At the end of the installation you will be prompted to run the 
       administration script "xtadm". If you are using the HP version of xdm
       you MUST use this utility to stop and re-start xdm before you can 
       log in from X terminals using xdm. 
       To do this select <XDM Administration> from the main menu of "xtadm"
       and then <Stop XDM> followed by <Start XDM>.

EOF
        break
        ;;
      *)
        continue
        ;;
    esac
  done
  echo
  echo $NL1 "Enter <return> to continue: $NL2"
  read REPLY
  sleep 2
fi


echo TOPDIR=/opt/hpxt >> $1

exit 0
