#!/sbin/sh
###############
# Product: PHKL_25769
# Fileset: PHKL_25769
# postinstall
# @(#) postinstall  $Revision: AUTO-GENERATED PATCH_11.00 (PHKL_25769)
#------------------------------------------------------------------#
# (c)Copyright 1983-2001 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=PHKL_25769

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
#%# CONTENT generated automatically:

_BASE_PATCHID=PHKL_18543

# _OVERLAP_FILES contains all files that are in both the incremental
# patch and the base patch, with the exception of the object files, as
# these are not tracked in the IPD.
#
# Each line contains a fileset name followed by overlap files in this
# fileset. There may be more than one line per fileset. Each line must
# be shorter (in characters) than the OS MAX_LINE limit.
#
# Each line looks like:
#   Fileset file1 file2 file3...
#
# When we install/remove an incremental patch, the IPD for the
# overlapping files in the basepatch is incorrect. This can cause
# swverify errors.  To avoid the unpleasant swverify errors, we fix
# the IPD for the overlapped files.
#
_OVERLAP_FILES="C-INC /usr/include/sys/mtio.h
CORE-KRN /usr/conf/h/mtio.h
KERN2-RUN /usr/conf/master.d/scsi-tune /usr/conf/master.d/scsi-tune /usr/conf/space.h.d/scsi-tune.h /usr/conf/space.h.d/scsi-tune.h"


echo "$_OVERLAP_FILES" |
 while read Fset FilesInFset ; do
  # Fset is the fileset for this line of $_OVERLAP_FILES

  # FilesInFset is a space delimited list of overlapped files in
  # the fileset we are processing.

  PFset=$_BASE_PATCHID.$Fset

  # First we check if this fileset is currently installed in the
  # system. If it is not, we don't have to do anything for any of it's
  # files.
  pstate=$(get_install_state $PFset)
  if [[ "$pstate" = configured ||"$pstate" = installed ]]
  then
    swmodify -x files="$FilesInFset" $PFset
    if [[ $? -ne 0 ]] ; then
        # swmodify has failed. Let's try the list of files one by one
        # to isolate the failure (slow, but at least we might reduce
        # the problems for the users.)
        FailedFiles=""
        for _File in $FilesInFset ; do
            swmodify -x files="${_File}" $PFset
            if [[ $? -ne 0 ]]; then
                FailedFiles="${_File} ${FailedFiles}"
            fi
        done
        if [[ -n "$FailedFiles" ]]; then
            print -u2 "WARNING: Failed to update IPD for the files:"
            print -u2 "         ${FailedFiles}"
            print -u2 "         This will cause swverify errors on patch fileset:"
            print -u2 "         $PFset"
            print -u2 "         To fix these errors, please run the following command:"
            print -u2 "         swmodify -x files="${FailedFiles}" $PFset"
            FailedFiles="";
            exitval=2
        fi
    fi
  fi

done


 
##### END_OF_CUSTOMIZATION
exit $exitval