#!/bin/sh

set -a
umask 022

###################################################################
#
# Environment variable
# TOPDIR ALTLINK WANTTFTP HOSTNAME OS NL1 NL2
# been set in request script for BASE package
# Or for sun4 and sco in installscript
###################################################################

###################################################
# pull in environment variables common to
# postinstall/postremove/request/and.. scripts
###################################################

###################################################
# pull in environment variables common to
# postinstall/postremove/request/and.. scripts
###################################################

ADMINDIR=/opt/hpxt/enware2/lbin
. $ADMINDIR/env.vars


#-------------------------------------------------------
#
# Only the WS X Server should run "fbconsole".
#
# Edit openwin-sys so that X Terminals don't take away
# control of the console "accidentially".
#
#-------------------------------------------------------

if [ "$OPENWINHOME" != "" ]
then
  OW=$OPENWINHOME
else
  OW=/usr/openwin
fi

OPENWINSYS=$OW/lib/openwin-sys

if [ -f "$OPENWINSYS" ]
then
  #
  # is there an  "then" in line before fbconsole line
  #
  sed -n '1,/^fbconsole/p' $OPENWINSYS | sed '$d' | tail -1 \
        | egrep '^then' > /dev/null
  if [ $? -ne 0 ]
  then
    egrep '^fbconsole' $OPENWINSYS > /dev/null
    if [ $? -eq 0 ]
    then

     cp $OPENWINSYS $OPENWINSYS.orig.$$
     # get first part of script
     TMPOPENWINSYS=/tmp/OPENWINSYS.$$
     sed -n '1,/^fbconsole/p' $OPENWINSYS | sed '$d'         > $TMPOPENWINSYS
     echo 'if [ "$DISPLAY" = ":0" -o "$DISPLAY" = "0:0" ]'   >> $TMPOPENWINSYS
     echo 'then'                                             >> $TMPOPENWINSYS
     echo '  fbconsole &           # Start fallback console' >> $TMPOPENWINSYS
     echo 'fi'                                               >> $TMPOPENWINSYS
     sed -n '/^fbconsole/,$p' $OPENWINSYS | sed '1d'         >> $TMPOPENWINSYS
     cp $TMPOPENWINSYS $OPENWINSYS
     rm $TMPOPENWINSYS
    fi
  fi
fi


rm -f /opt/hpxt/enware2/bin/xtadm
ln -s /opt/hpxt/enware2/lbin/xtadm /opt/hpxt/enware2/bin/xtadm


if [ "$OS" != "sun5" ]
then
  while true
  do
  echo $NL1 "Enter y to run xtadm to set up an HP Netstation now [y|n] (default=y): $NL2" 

	   REPLY=`line`
	   case $REPLY in
	      y|Y|yes|YES|y*|"")
		/opt/hpxt/enware2/bin/xtadm	
		break
		;;
	      n*|N*|q*|Q*)
		break
		;;
	      *)	
		continue
	      ;;
	   esac
  done
fi

exit 0
