#!/sbin/sh

#########################################################################
# 									
#   File:	 customize
#   @(#) customize $Revision: 1.4 $ $Date: 93/02/17 14:52:10 $
#   Description: /etc/update customization script for HPXT2-ICA
# 
#########################################################################
#

umask 022
set -a
PATH="/bin:/usr/bin:/etc:/usr/sbin:/sbin:/usr/ucb:/usr/ccs/bin:."
FILESET=HPXT2-ICA

#
# Get environment variables as setup earlier in prerequisite fileset    
#

OS=`uname`

if [ "$OS" != "AIX" -a "$OS" != "HI-UX" ]
then
  ENVARDIRS="/opt/hpxt/enware2/lbin /opt/hpxt/enware2/bin /tmp /usr/tmp last"
  for ENVARDIR in $ENVARDIRS
  do
    if [ $ENVARDIR = "last" ]
    then
      echo "WARNING: cannot find suitable env.vars file"
    fi

    if [ -f $ENVARDIR/env.vars ]
    then
        . $ENVARDIR/env.vars
        break
    fi
  done
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


RMSCRIPT=/opt/hpxt/enware2/lbin/xtutil_rm-file
ADDSCRIPT=/opt/hpxt/enware2/lbin/xtutil_add-file

XTHOME=/opt/hpxt/enware2/xthome

#--------------------------------#
#   Update directives file
#--------------------------------#
#

if [ "x$NEWDIR" = "x" ]
then
  DIRECTIVES=${XTHOME}/bin/directives
  CFGDIR=$XTHOME/config
else
  DIRECTIVES=${NEWDIR}/bin/directives
  CFGDIR=$NEWDIR/config
fi

egrep -i 'ica.directives' ${DIRECTIVES} > /dev/null
if [ $? -ne 0 ]
then
  cp ${DIRECTIVES} ${DIRECTIVES}.orig.$$
  cat ${DIRECTIVES}.ica                 >>     ${DIRECTIVES} 
  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
   (
    set -a
    FILESET=HPXT2-BASEOS
    $ADDSCRIPT ${DIRECTIVES}.orig.$$
    $ADDSCRIPT ${DIRECTIVES} 
   )
  fi
fi

if [ $OS = "hp10" -o "$OS" = "hp" ]
then
  $RMSCRIPT ${DIRECTIVES}.ica 
fi

if [ "$OS" != "AIX" ]
then
  rm -f ${DIRECTIVES}.ica 
fi


#---------------------------------------------------------------------#
# Create default config file with ica information
# Also create a sample.cfg 
#---------------------------------------------------------------------#
#
if [ ! -f $CFGDIR/default.cfg ]
then
  cp $CFGDIR/sample.cfg $CFGDIR/default.cfg

  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
    (
      set -a
      FILESET=HPXT2-BASEOS
      $ADDSCRIPT		$CFGDIR/default.cfg
    )
  fi
fi

for FILE in $CFGDIR/default.cfg $CFGDIR/sample.cfg
do
  egrep -i bcica $FILE > /dev/null
  if [ $? -ne 0 ]
  then
    cat ${CFGDIR}/ica.appendix.cfg              >> $FILE

    if [ $OS = "hp10" -o "$OS" = "hp" ]
    then
      (
        set -a
        FILESET=HPXT2-BASEOS
        $ADDSCRIPT		$FILE
      )
    fi

  fi
done


if [ $OS = "hp10" -o "$OS" = "hp" ]
then
    $RMSCRIPT		${CFGDIR}/ica.appendix.cfg
fi

if [ "$OS" != "AIX" ]
then
  rm -f			${CFGDIR}/ica.appendix.cfg
fi



# -------------------------------#
# Update CDE action DB
# -------------------------------#
#

ACTIONDB=/etc/dt/appconfig/types/C/hpns.dt

if [ -f $ACTIONDB -a -d /usr/dt/bin ]
then

  STUB=/etc/dt/appconfig/appmanager/C/Netstations
  if [ ! -d $STUB ]
  then
    mkdir -p $STUB
  fi

  cp $STUB/HpnsAdmin $STUB/HpnsICA > /dev/null 2>&1
  touch     $STUB/HpnsICA
  chmod 555 $STUB/HpnsICA
  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
    $ADDSCRIPT $STUB/HpnsICA
  fi

fi

# --------------------------------#
# Update VUE action DB
# --------------------------------#

ACTIONDB=/opt/hpxt/enware2/usr/vue/types/hpns.vf

if [ -f $ACTIONDB -a -d /usr/vue/bin ]
then

  STUB=/opt/hpxt/enware2/usr/vue/config/types/tools/Netstations
  if [ -d $STUB ]
  then
    if [ ! -f $STUB/HpnsICA ]
    then
      cp $STUB/HpnsAdmin $STUB/HpnsICA > /dev/null 2>&1
      touch     $STUB/HpnsICA
      chmod 555 $STUB/HpnsICA
    fi
  fi
fi


exit 0
