#!/sbin/sh


#########################################################################
# 									
#   File:	 customize
#   @(#) customize $Revision: 1.8 $ $Date: 93/02/23 12:09:14 $
#   Description: /etc/update customization script for HPXT2-CCLIENTS fileset
# 
#########################################################################
#

umask 022
set -a
PATH="/bin:/usr/bin:/etc"
FILESET=HPXT2-CCLIENTS

#
# Get environment variables as setup earlier in prerequisite fileset	
#
DIR_ENWARE2=/opt/hpxt/enware2
ENVARDIRS="$DIR_ENWARE2/lbin /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
    CONTROL_UTILS=/usr/lbin/sw/control_utils
    if [ ! -f $CONTROL_UTILS ]
    then
	echo "ERROR:   Cannot find $UTILS"
	exit 1
    fi
    set +u
    . $CONTROL_UTILS
    set -u
    PATH=$PATH:/opt/hpxt/enware2/lbin
fi


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

fi

#
#   forced_cpset --	utility function
#   	copy $4 to $5, preserving $5 if it already exists and is different.
#	Make sure the permissions are  $1, owner $2, group $3.
#
forced_cpset()
{
    /bin/cmp -s $4 $5
    if [ $? -ne 0 -a -f $5 ]; then
	/bin/cp $5 $5.old
	cat <<EOF
NOTE:    A new version of "$5"
         has been installed.
         The previous version has been saved as
         "$5.old".
EOF
    fi
    /bin/cp $4 $5
    /bin/chgrp $3 $5
    /bin/chown $2 $5
    /bin/chmod $1 $5
}

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

#
# Update "directives" with clients from this fileset
#
PARTS="cclients"
for PART in $PARTS
do
  THISDIRECTIVE=$NEWDIR/bin/directives.$PART
  cat $NEWDIR/bin/directives | egrep -i directive | egrep -i "$PART" > /dev/null
  if [ $? -ne 0 ]
  then
    if [ -f $THISDIRECTIVE ]
    then
      cat $THISDIRECTIVE >> $NEWDIR/bin/directives
    else
      echo "WARNING: could not find $THISDIRECTIVE"
    fi
  fi
  rm  $THISDIRECTIVE
  /opt/hpxt/enware2/lbin/xtutil_rm-file $THISDIRECTIVE
done



#---------------------------------------------#
# Make some links for 10.0 style locale names
#
#---------------------------------------------#

LINK_SCRIPT="/opt/hpxt/enware2/lbin/xtutil_nls_links"
if [ -x "$LINK_SCRIPT" ]
then
  $LINK_SCRIPT ADD
fi


#
##
##   Do some xflash.pkg upkeep
##
#if [ "$OS" = "hp10" ]
#then
#    SRCFLASH=/opt/hpxt/enware2/newconfig/xflash.pkg
#    DSTFLASH=/opt/hpxt/enware2/xthome/config/xflash.pkg
#
#    if [ -f $DSTFLASH ]
#    then
#	cmp -s $SRCFLASH $DSTFLASH
#	if [ $? -ne 0 ]
#	then
#	    cp $DSTFLASH $DSTFLASH.old.$$
#	    xtutil_add-file $DSTFLASH.old.$$
#	fi
#    fi
#
#    grep '/opt/hpxt/enware2' $SRCFLASH > /dev/null
#    if [ $? -eq 0 ]
#    then
#	FLASHTMP="$SRCFLASH.tmp.$$"
#	sed "s!/opt/hpxt/enware2!/opt/hpxt/enware2/xthome!g" $SRCFLASH > $FLASHTMP
#	if [ -s $FLASHTMP ]
#	then
#	    cp $FLASHTMP $SRCFLASH
#	else
#	    echo "WARNING: edit of $SRCFLASH failed"
#	fi
#	rm -f $FLASHTMP
#    fi 
#
#    if [ ! -f $DSTFLASH ]
#    then
#	cp $SRCFLASH $DSTFLASH
#	xtutil_add-file $DSTFLASH
#    else
#	cmp -s $SRCFLASH $DSTFLASH
#	if [ $? -ne 0 ]
#	then
#	    cp $SRCFLASH $DSTFLASH
#	fi
#    fi
#fi

#
#------------------------------------------------------------------------#
# Create sym links for VUE
#------------------------------------------------------------------------#
#
if [ "$OS" = "hp" ]
then
    DTOOLDIR=/usr/vue/config/types/tools
else
    DTOOLDIR=/etc/vue/config/types/tools
fi

if [ -d ${DTOOLDIR} ]
then

  rm -rf ${DTOOLDIR}/Netstations > /dev/null 2>&1
  ln -s ${DIR_ENWARE2}/usr/vue/config/types/tools/Netstations ${DTOOLDIR}/Netstations

  DIALOGDIR=/usr/vue/dialogs
  if [ -d $DIALOGDIR ]
  then
    rm -f /usr/vue/dialogs/hpxt.ddf
    ln -s ${DIR_ENWARE2}/usr/vue/dialogs/hpxt.ddf /usr/vue/dialogs/hpxt.ddf

    rm -f /usr/vue/dialogs/MPower.ddf
    ln -s ${DIR_ENWARE2}/usr/vue/dialogs/MPower.ddf /usr/vue/dialogs/MPower.ddf
  fi


  TYPESDIR=/usr/vue/config/types
  if [ ! -d "$TYPESDIR" ]
  then
    TYPESDIR=/usr/vue/types
  fi

  if [ -d "$TYPESDIR" ]
  then
    rm -f $TYPESDIR/hpns.vf
    ln -s ${DIR_ENWARE2}/usr/vue/types/hpns.vf $TYPESDIR/hpns.vf 

    rm -f $TYPESDIR/MPower.vf
    ln -s ${DIR_ENWARE2}/usr/vue/types/MPower.vf $TYPESDIR/MPower.vf
  fi


  ICONDIR=/usr/vue/icons

  ICONS="frontEnd.l.pm frontEnd.s.pm frontEnd.pm"
  for i in $ICONS
  do
    THISDIR=${ICONDIR}/Vuewm
    if [ -d "$THISDIR" ]
    then
      rm -f ${THISDIR}/$i
      ln -s ${DIR_ENWARE2}${THISDIR}/$i ${THISDIR}/$i
    fi
    THISDIR=${ICONDIR}/Vuewm/Color
    if [ -d "$THISDIR" ]
    then
      rm -f ${THISDIR}/$i
      ln -s ${DIR_ENWARE2}${THISDIR}/$i ${THISDIR}/$i
    fi
  done

  ICONS="enware.t.bm enware.s.bm enware.m.bm enware.l.bm"
  for i in $ICONS
  do
    if [ -d "$ICONDIR" ]
    then
      rm -f ${ICONDIR}/$i
      ln -s ${DIR_ENWARE2}${ICONDIR}/$i ${ICONDIR}/$i
    fi
  done

  ICONS="enware.t.pm enware.s.pm enware.m.pm enware.l.pm"
  for i in $ICONS
  do
    THISDIR=${ICONDIR}/Color
    if [ -d "$THISDIR" ]
    then
      rm -f ${THISDIR}/$i
      ln -s ${DIR_ENWARE2}${THISDIR}/$i ${THISDIR}/$i
    fi
  done

  ICONS="enware.i.bm"
  for i in $ICONS
  do
    THISDIR=${ICONDIR}/Vuewm
    if [ -d "$THISDIR" ]
    then
      rm -f ${THISDIR}/$i
      ln -s ${DIR_ENWARE2}${THISDIR}/$i ${THISDIR}/$i
    fi
  done
fi

#
#
##
##-----------------------------------------------------------------------#
## If CDE seems to be installed then add local clients to CDE actions  
##-----------------------------------------------------------------------#

CDEHOME=/usr/dt
AC_INSTALLSCRIPT="${ADMINDIR}/xtutil_add_lc_cde"
ACTIONDB="$ADMINDIR/hpns.dt"

if [ -d "$CDEHOME" -a -x "$AC_INSTALLSCRIPT" ]
then
  $AC_INSTALLSCRIPT $ACTIONDB
fi


#--------------------------------------------------
# If Navio and/or 3270 is installed
# fix stuff that might have been overwritten
# when UPGRADING from 8.0 to 9.0
#--------------------------------------------------
#
$ADMINDIR/xtutil_fix_3270_navio_stuff



exit 0
