#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 12.4 $ generated on Mon Sep 18 21:21:50 PDT 2000
#
# (c)Copyright 1983-2000 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD postinstall script template for 11.X patches.                 #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to prepare for a kernel build when required by the     #
# install conditions.  The script can also drive events that must  #
# occur before a system reboot occurs.                             #
#------------------------------------------------------------------#

_PATCHID=PHNE_22397

UTILS="/usr/lbin/sw/control_utils"

if [ ! -f $UTILS ]; then
    echo "ERROR:   Cannot find $UTILS"
    exit 1
fi

. $UTILS
exitval=$SUCCESS

#####
##### Insert any code you may require at this point in the script.
##### Pay attention to the exitval variable and set appropriately
##### in your code.  If you are unsure as to what types of operations
##### are legal in this file and what types aren't, consult the 
##### "Guidelines for SD Control Scripts" document.
#####
##### START_CUSTOMIZATION_HERE

#
# If libipsec.a exists and contains more than one module, then
# this system  has IPSEC installed, and we leave well enough alone.
# If libipsec.a doesn't exist, or exists and contains only a
# single module, we replace it with the contents of libipsectp.a
# which always contains the current version of the ARPA Transport
# stubs.
#
function xport_ar_modules
{
  # This function returns the number of modules in an archive
  # library, or -1 if the file isn't an archive.  If the file
  # doesn't exist, a value of 0 is returned.
  typeset library=$1
  if [[ -f $library ]]; then
    if file $library | grep -e ' archive file ' >/dev/null 2>&1 ; then
      # The file has been butchered, don't know what to do.
      print -u2 "ERROR: /usr/conf/lib/$library is NOT an archive file."
      print "-1"
    else
      # Determine if the library contains stubs or not
      ar -t $library 2>/dev/null | wc -l
    fi  
  else
    print "0" 
  fi
}

typeset pwd=$(pwd)
typeset i_modules

cd /usr/conf/lib
let i_modules=`xport_ar_modules libipsec.a`
if (( i_modules < 0 )); then # Invalid file
  exitval=$FAILURE
else
  if (( i_modules > 1 )); then # We have IPSEC installed
    if [[ -f /var/adm/ipsec ]]; then
       rm -f /var/adm/ipsec
    fi
    if [[ ! -d /var/adm/ipsec ]]; then
       mkdir -p /var/adm/ipsec
       chmod 755 /var/adm/ipsec
    fi
    cp libipsectp.a /var/adm/ipsec/libipsec.a
  else # 0 means NO libipsec.a, 1 means libipsectp.a
    cp libipsectp.a libipsec.a
  fi
fi 

cd $pwd
unset -f xport_ar_modules

exit $exitval
