#!/sbin/sh

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

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

FILESET=HPXT-ISOFONTS
umask 022

# 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

case "$OS" in
  hp)
    TOOL=/usr/bin/X11/700X
    MKFONTDIR=$TOOL/xtmkfontdir
    ;;
  hp10)
    TOOL=${INSTALLDIR}/bin
    MKFONTDIR=$TOOL/xtmkfontdir
    ;;
esac

FONT75=$XTHOME/fonts/iso_8859.1/75dpi
FONT100=$XTHOME/fonts/iso_8859.1/100dpi

if [ "$OS" = "hp" ]
then
  ARCH=$1
  ARCHEXT=""
  case $ARCH in
    HP-MC68*)
	if [ ! hp9000s300 ]
	then
	    ARCHEXT="+/$ARCH"
	fi
	;;
  esac
fi

if [ -d "$FONT75" ]
then
    if [ ! -f "$MKFONTDIR" ]
    then
        echo "ERROR:   Required font utility $MKFONTDIR not found." >&2
        echo "         Install fileset HPXT-UTILS first." >&2
    else
          # 
           # Only do the mkfontdir if transition links are installed
           # as it seems that mkfontdir depends on them
           #
           if [ -d /bin ]
           then
             $MKFONTDIR $FONT75
             xtutil_add-file $FONT75/fonts.dir
           fi
    fi
    if [ -f "$FONT75/fonts.alias" ]
    then
      cmp -s $FONT75/fonts.alias $FONT75/fonts.newalias > /dev/null
      if [ $? -ne 0 ]
      then
	mv $FONT75/fonts.alias $FONT75/fonts.oldalias.$$ 2>/dev/null
      fi
    fi
    mv $FONT75/fonts.newalias $FONT75/fonts.alias 2>/dev/null
    xtutil_add-file $FONT75/fonts.alias
    xtutil_rm-file $FONT75/fonts.newalias
else
    echo "ERROR:   Could not find directory $FONT75." >&2
    exit 1
fi

if [ -d "$FONT100" ]
then
    if [ ! -f "$MKFONTDIR" ]
    then
        echo "ERROR:   Required font utility $MKFONTDIR not found." >&2
        echo "         Install fileset HPXT-UTILS first." >&2
    else
          # 
           # Only do the mkfontdir if transition links are installed
           # as it seems that mkfontdir depends on them
           #
           if [ -d /bin ]
           then
             $MKFONTDIR $FONT100
             xtutil_add-file $FONT100/fonts.dir
           fi
    fi
    if [ -f "$FONT100/fonts.alias" ]
    then
      cmp -s $FONT100/fonts.alias $FONT100/fonts.newalias > /dev/null
      if [ $? -ne 0 ]
      then
        mv $FONT100/fonts.alias $FONT100/fonts.oldalias.$$ 2>/dev/null
      fi
    fi
    mv $FONT100/fonts.newalias $FONT100/fonts.alias 2>/dev/null
    xtutil_add-file $FONT100/fonts.alias
    xtutil_rm-file $FONT100/fonts.newalias
else
    echo "ERROR:   Could not find directory $FONT100." >&2
    exit 1
fi

if [ "$OS" = "hp" ]
then
  # remove old 700X fileset
  /bin/rm -rf /system${ARCHEXT}/C2300A-FNTISO 2>/dev/null
  /bin/rm -f /etc/filesets${ARCHEXT}/C2300A-FNTISO 2>/dev/null

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

exit 0
