#!/sbin/sh

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

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

FILESET=HPXT-CLIENTS

#
# 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
    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=$SW_PATH:/opt/hpxt/enware/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 modules.ld with clients from this fileset
#
cat $NEWDIR/bin/modules.clients >> $NEWDIR/bin/modules.ld
xtutil_add-file $NEWDIR/bin/modules.ld
xtutil_rm-file $NEWDIR/bin/modules.clients
rm -f $NEWDIR/bin/modules.clients

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

    # remove old 700RX Vue actions
    /bin/rm -rf /usr/vue/config/types/tools/700RX_Admin 2>/dev/null
    /bin/rm -f /usr/vue/types/700rx.vf 2>/dev/null
fi



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

LINK_SCRIPT="${ADMINDIR}/xtutil_add_nls_links"

if [ -x "$LINK_SCRIPT" ]
then
  $LINK_SCRIPT
fi


#
#   Do some xflash.pkg upkeep
#
if [ "$OS" = "hp10" ]
then
    SRCFLASH=${INSTALLDIR}/newconfig/xflash.pkg
    DSTFLASH=${INSTALLDIR}/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 '/usr/lib/X11/700X' $SRCFLASH > /dev/null
    if [ $? -eq 0 ]
    then
	FLASHTMP="$SRCFLASH.tmp.$$"
	sed "s!/usr/lib/X11/700X!${INSTALLDIR}/xthome!g" $SRCFLASH > $FLASHTMP
	if [ -s $FLASHTMP ]
	then
	    cp $FLASHTMP $SRCFLASH
	    xtutil_add-file $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
	    xtutil_add-file $DSTFLASH
	fi
    fi
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/hpxt.dt"

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



exit 0
