#!/sbin/sh

#########################################################################
# 									
#   File:	 customize
#   @(#) customize $Revision: 1.11 $ $Date: 93/05/18 12:00:31 $
#   Description: /etc/update customization script for HPXT-PRINTER fileset
# 
#########################################################################
#

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

FILESET=HPXT-PRINTER

MIXED=0
ARCHEXT=""

# 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

if [ "$OS" = "hp10" ]
then
  MODELSCRIPT=${INSTALLDIR}/hpnp/hpnp.model
  egrep 'HPNPF=/usr/lib' $MODELSCRIPT > /dev/null
  if [ $? -eq 0 ]
  then
    sed -e "s!HPNPF=/usr/lib!HPNPF=$INSTALLDIR!g" \
	$MODELSCRIPT  > $MODELSCRIPT.$$
    if [ -s $MODELSCRIPT.$$ ]
    then
      cp $MODELSCRIPT.$$ $MODELSCRIPT
      rm $MODELSCRIPT.$$ 
      xtutil_add-file $MODELSCRIPT
    else
      echo "WARNING: edit of $MODELSCRIPT failed"
    fi
  fi
  exit 0
fi


# find out which machine type we are running on
MACHINE=`uname -m`
MACHINE=`basename $MACHINE`
case $MACHINE in
   3*|4*)
	MACHINE=300
	ARCH="HP-MC68020"
	;;
6*|7*|8*)
	MACHINE=800
	ARCH="HP-PA"
	;;
      *)
	echo "ERROR:   Unknown model of computer."
	exit 1
	;;
esac

# find out which release of HP-UX we are running on
RELEASE=`uname -r | sed -e 's/[^0-9.]//g' -e 's/^\.//' | cut -d. -f1`
if [ $RELEASE -ge 8 ]
then
	OS=80
else
     if [ $RELEASE -eq 7 ]
     then
	echo "ERROR:   release $OS of operating system unsupported"
	exit 1
     else
	echo "ERROR:   Unknown release of operating system."
	exit 1
     fi
fi

OSPATH=${MACHINE}-${OS}


#   determine if the file getcontext exists and is executable

if [ -x /bin/getcontext ]
then

  #  determine if this host is a member of a HP-UX cluster
  /bin/getcontext | grep standalone > /dev/null 2>&1
  if [ $? -ne 0 ]
  then

    #  this host is a member of a HP-UX cluster.  Determine if
    #  it is the cluster server.  If it is not, then the customize script
    #  cannot proceed.

    /bin/getcontext | grep localroot > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
      #  This host is the cluster server.  If the host is not
      #  precision architecture type (series 800) then the cluster must be
      #  homogeneous with all series 300/400 devices.  Not context dependence
      #  is needed for the NPI files in this case.  If the cluster server
      #  is precision architecture, then the cluster is heterogeneous and
      #  there is a need to make some of the NPI files context dependent.

      if [ $ARCH = "HP-PA" ]
      then
        MIXED=1
        ARCHEXT="+/$ARCH"
      fi
    else
      echo "ERROR:   This host is not a cluster server"
      echo "         On clusters of HP 9000 computers sharing the HP-UX file system"
      echo "         the printer support software can only be run sucessfully on"
      echo "         the cluster server."
      exit 1
    fi
  fi
fi



###########################################################
# Boise may have been here already and we don't want to interfere
# with existing installations so
# be a little cautious before installing printer SW
###########################################################

DOPRINTER="false"
if [ ! -f /usr/lib/hpnp/hpnpf ]
then
  DOPRINTER="true"
else
  if [ -f /usr/lib/hpnp/hpnp.model -a ! -f /usr/lib/hpnp/version ]
  then
    #
    # If it seem to be Panacom SW just update it
    # (Boise has cfg dir, we don't)
    #
    if [ ! -d /usr/lib/hpnp/cfg ] 
    then 
      DOPRINTER="true"
    fi
  fi
fi

if [ "$DOPRINTER" = "false" ]
then
  echo ""
  echo "NOTE:    Printer SW already exists on this host."
  echo "         Will not install on top of an existing version."
  echo "         If you want to install it anyway, you should remove/rename"
  echo "         directory /usr/lib/hpnp and re-run installation"
  echo "         and select the $FILESET fileset."
  echo ""
  rm -rf /usr/lib/hpnp/newconfig
  rm /usr/man/man1m.Z/hpnptyd.1m.hpxt 
  rm /usr/man/man1m.Z/hpnpf.1m.hpxt 
  /bin/rm -rf /system${ARCHEXT}/HPXT-PRINTER 2>/dev/null
  /bin/rm -f /etc/filesets${ARCHEXT}/HPXT-PRINTER 2>/dev/null
  # remove old 700RX fileset
  /bin/rm -rf /system${ARCHEXT}/700RX-PRINTER 2>/dev/null
  /bin/rm -f /etc/filesets${ARCHEXT}/700RX-PRINTER 2>/dev/null
  exit 0
else
  #
  # no non-Panacom printer stuff seems installed, go ahead and do it
  #
  mv /usr/lib/hpnp/newconfig /usr/lib/hpnp.$$
  mv /usr/lib/hpnp /usr/lib/hpnp.orig.$$	 2>/dev/null
  mv /usr/lib/hpnp.$$ /usr/lib/hpnp

  #
  # If a version existed, save it as /usr/lib/hpnp.orig.$$
  #
  ls /usr/lib/hpnp.orig.$$ | grep hpnp > /dev/null
  if [ $? -ne 0 ]
  then
    rm -rf /usr/lib/hpnp.orig.$$
  else
    echo ""
    echo "NOTE: old version of printer SW saved as /usr/lib/hpnp.orig.$$"
    echo ""
  fi
  mv /usr/man/man1m.Z/hpnptyd.1m.hpxt /usr/man/man1m.Z/hpnptyd.1m
  mv /usr/man/man1m.Z/hpnpf.1m.hpxt /usr/man/man1m.Z/hpnpf.1m
fi


# now pick the appropriate binaries for this machine

mv -f /usr/lib/hpnp/hpnpf '/usr/lib/hpnp/#hpnpf' >/dev/null 2>&1
if [ "$MIXED" = "1" ]
then
	makecdf -c HP-PA -f /usr/lib/hpnp/${OSPATH}/hpnpf /usr/lib/hpnp/hpnpf
fi
mv -f /usr/lib/hpnp/${OSPATH}/hpnpf /usr/lib/hpnp/hpnpf${ARCHEXT}
rm -f '/usr/lib/hpnp/#hpnpf'

mv -f /usr/lib/hpnp/hpnptyd '/usr/lib/hpnp/#hpnptyd' >/dev/null 2>&1
if [ "$MIXED" = "1" ]
then
	makecdf -c HP-PA -f /usr/lib/hpnp/${OSPATH}/hpnptyd /usr/lib/hpnp/hpnptyd
fi
mv -f /usr/lib/hpnp/${OSPATH}/hpnptyd /usr/lib/hpnp/hpnptyd${ARCHEXT}
rm -f '/usr/lib/hpnp/#hpnptyd'

# remove unused printer code
rm -rf /usr/lib/hpnp/hp300-$OS
rm -rf /usr/lib/hpnp/hp800-$OS

# remove old 700RX fileset
/bin/rm -rf /system${ARCHEXT}/700RX-PRINTER 2>/dev/null
/bin/rm -f /etc/filesets${ARCHEXT}/700RX-PRINTER 2>/dev/null

exit 0
