#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 19.1 $ generated on Thu May 31 13:57:17 PDT 2001
#
# (c)Copyright 1983-2001 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD postremove script template for 11.X patches.                  #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to perform any necessary cleanup actions after the     #
# patch's files have been removed.                                 #
#------------------------------------------------------------------#

_PATCHID=PHKL_24268

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

_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=""


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 -o "$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


exit $exitval
