#!/sbin/sh

#########################################################################
# 									
#   File:	 customize
#   @(#) customize $Revision: 1.4 $ $Date: 93/02/17 14:53:39 $
#   Description: /etc/update customization script for HPXT-VT320 fileset
# 
#########################################################################
#

umask 022
set -a
FILESET=HPXT-VT320
PATH="/bin:/usr/bin:/etc:/usr/bin/X11/700X/admin"

RELEASE=`uname -r | sed -e 's/[^0-9.]//g' -e 's/^\.//' | cut -d. -f1`


# Get environment variables as setup earlier in prerequisite fileset    
#
ENVARDIRS="/opt/hpxt/enware/lbin /usr/bin/X11/700X/admin /tmp /usr/tmp last"
for ENVARDIR in $ENVARDIRS
do
  if [ $ENVARDIR = "last" ]
  then
    echo "WARNING: cannot find suitable env.vars file"
    exit 0
  fi

  if [ -f $ENVARDIR/env.vars ]
  then
    . $ENVARDIR/env.vars
    break
  fi
done


if [ "$OS" = "hp10" ]
then
  PATH=$SW_PATH:/opt/hpxt/enware/lbin

  if [ -f /usr/bin/dcnodes -o -f /usr/sbin/dcnodes ]
  then
    dcnodes -q
    if [ $? -eq 2 ]
    then
        exit 0
    fi
  fi

fi

#
# append vt320 local client lines to modules.ld file
#
cat $NEWDIR/bin/modules.vt320 >> $NEWDIR/bin/modules.ld
xtutil_add-file $NEWDIR/bin/modules.ld
xtutil_rm-file $NEWDIR/bin/modules.vt320
rm -rf $NEWDIR/bin/modules.vt320

#
# add vt320 local client lines to sys.vuerxrc file
#

VUERXRC=$NEWDIR/vuerx/sys.vuerxrc

grep -q term5 $VUERXRC
if [ $? != 0 ]
then
    /usr/bin/awk '
/^  CONTROL         term4/ {
	print $0
	print "  CONTROL         term5"
	next
}
/^CONTROL term4/,/^}/ {
	print $0
	if ($1 == "}")
	{
		print ""
		print "CONTROL term5"
		print "{"
		print "  TYPE             button"
		print "  IMAGE            xterm"
		print "  LABEL            \"ENWARE vt320\""
		print "  PUSH_ACTION      f.exec \"hpxt.vt320\""
		print "}"
	}
	next
}
{
	print $0
}
'   < $VUERXRC > ${VUERXRC}.$$
        if [ -s "${VUERXRC}.$$" ]
        then
          cp "${VUERXRC}.$$" $VUERXRC
          rm "${VUERXRC}.$$"
        else
          echo "WARNING:  could not edit ${VUERXRC}"
        fi
fi

#
# remove VT320 filesets
#
#OFILESET=HPXT-VT320
#if [ -f $OFILESET ]
#then
#  echo "Removing old $OFILESET fileset"
#  export OFILESET
#  if [ $RELEASE -ge 9 ]
#  then
#    rmfn -l "$OFILESET"
#  else
#    ( cd /etc/filesets; sysrm "$OFILESET" )
#  fi
#fi

exit 0
