#! /sbin/sh
########
#  Product: InternetSrvcs
#  Fileset: INETSVCS-BOOT
#  configure
#  @(#) $Revision: 1.2.212.1 $
########
#
#  (c) Copyright Hewlett-Packard Company  1993, 1994
#
#######
#
# Standard initialization
#

exitval=0				# Anticipate success


UTILS="/usr/lbin/sw/control_utils"
if [[ ! -f $UTILS ]]
then
       echo "ERROR:   Cannot find $UTILS"
       exit 1
fi
. $UTILS

#
#
#######
#
# Start of INETSVCS-BOOT configure process
#


get_auth()
{
    DESDELAY=`/usr/examples/xntp/authspeed /usr/newconfig/etc/ntp.keys | grep CPU | awk '{print $6}'`
    MD5DELAY=`/usr/examples/xntp/authspeed -m /usr/newconfig/etc/ntp.keys | grep CPU | awk '{print $6}'`
    sed -e"s/#AUTHDELAY/#DESDELAY=$DESDELAY; MD5DELAY=$MD5DELAY/" < /usr/newconfig/etc/ntp.conf > /etc/ntp.conf
}

ntp_notice()
{
    echo "NOTE:    The file /etc/ntp.conf has been modified since the last"
    echo "         update/install. The file /usr/newconfig/etc/ntp.conf"
    echo "         was not copied over this modified file. Please compare"
    echo "         these files and update /etc/ntp.conf." 
}

#
#        Files created by this INETSVCS-BOOT postcustomize script
#

newfiles="/etc/ntp.conf /etc/ntp.keys /etc/bootptab /etc/boottab"

#
#        Update configuration files in /etc from /usr/newconfig
#        only if the scripts do not contain user modifications.
#

#
# NOTE: boottab for rbootd, bootptab for bootp
#
for file in \
	/etc/ntp.keys	\
	/etc/bootptab	\
	/etc/boottab
do
	newconfig_cp $file
	case  $? in
	  100)
		#       Original not present, but working copy is present
                newconfig_msgs 100
            ;;
          103)
                #       Original is present and differs from working copy and
                #       from the new file
		newconfig_msgs 103
	    ;;
	esac
done


if [ -f /etc/ntp.conf ]; then
  rm -f /tmp/configure.ntp
  diff /etc/ntp.conf /usr/old/usr/newconfig/etc/ntp.conf | grep "^<" > /tmp/configure.ntp
  if [ `wc -l /tmp/configure.ntp | awk '{print $1}'` -eq 1 ]; then
	CHANGE=`grep "DESDELAY.*MD5DELAY" /tmp/configure.ntp`
	if [ "X$CHANGE" = "X" ]; then
	    ntp_notice
	else
	    cp /usr/newconfig/etc/ntp.conf /etc/ntp.conf
	    get_auth
	fi
  else
	ntp_notice
  fi

  rm -f /tmp/configure.ntp

else
	get_auth
fi


# create default NTP directory
#
if [ ! -d /var/tmp/ntp ]; then
    mkdir -p /var/tmp/ntp
    chmog 555 bin bin /var/tmp/ntp
fi

# create rbootd directory
#
if [ ! -d /var/rbootd ]; then
    mkdir -p /var/rbootd
    chmog 777 bin bin /var/rbootd
fi

#
#######
# Update the live_files for INETSVCS-BOOT
#
#   Add new files to the list.
#

#NOTYET for file in $newfiles
#NOTYET do
#NOTYET		swmodify add $file
#NOTYET done


exit $exitval
