#!/sbin/sh
###############
# Product: PHKL_25100
# Fileset: PHKL_25100
# postinstall
# @(#) postinstall  $Revision: AUTO-GENERATED PATCH_11.00 (PHKL_25100)
#------------------------------------------------------------------#
# (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_25100

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/framebuf.h
CORE-KRN /usr/conf/graf/gpu_data.h /usr/conf/graf/graph3.h /usr/conf/graf/ite.h /usr/conf/graf/stirom.h /usr/conf/h/framebuf.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


#%# <static: PHKL_22976>
#%#

########
# FUNCTIONS
########
# AddDriverEntry
#
# input: $1 - (string) the driver
#
# Purpose:  To add to the system file a driver that this fileset has
#           delivered. Set the $exitval value based on the return value
#           from mod_systemfile().  If multiple additions, ensure that
#           a FAILURE # value of $exitval is not reduced by a later
#           SUCCESS return.
#
AddDriverEntry()
{
   mod_systemfile $SW_SYSTEM_FILE_PATH -a $1
   if [[ $? -ne 0 ]]
     then
       print  "ERROR:   Cannot update required $1 functionality ($FILESET)."
       exitval=$FAILURE
   fi
} #END AddDriverEntry

#########################################################################
#########################################################################
# This script part is intended to insert post 11.00 drivers that are
# needed by the kernel when new driver patches are installed and certain
# hardware is present.
#
# This addition must be done at the patch level since it is fixing a
# difficulty caused by the early truncate_sys call from the control
# scripts in the CORE-KRN fileset, but depends on matching the new
# drivers defined in master.d/core-hpux which is delivered in KERN2-RUN.
#########################################################################

graph3_legacy_devices=`ioscan -kf | grep Display \
                                  | grep -v PCI`

graph3_devices=`ioscan -kF | grep Display \
                         | awk -F: '{ print $12 }' \
                         | awk '{printf("%02x%02x\n",$1,$2)}'\
                         | grep '103c'`

gvid_devices=`ioscan -kF | grep Display \
                       | grep PCI | awk -F: '{ print $12 }' \
                       | awk '{printf("%02x%02x\n",$1,$2)}'\
                       | grep -v '103c'`

# If we have a HP legacy graphics card, then add the graph3 driver
# to the system file.

if [ -n "$graph3_legacy_devices" ]; then
    AddDriverEntry graph3
fi

# If we have a HP PCI graphics card, then add the graph3 driver
# to the system file.

if [ -n "$graph3_devices" ]; then
    AddDriverEntry graph3
fi

# If we have a gvid graphics card, then add the gvid driver
# to the system file, but only for a 64 bit kernel. The gvid master file
# is only delivered on 64 bit systems.

if [ -f $SW_ROOT_DIRECTORY/usr/conf/master.d/gvid ] && \
   [ -n "$gvid_devices" ]
 then
    AddDriverEntry gvid
fi

#%#
#%# </static: PHKL_22976>


#%# DO NOT REMOVE ANYTHING AFTER THIS LINE
#%# <PATCH CONTROL SCRIPT LOG>
#%# PHKL_22976
#%# </PATCH CONTROL SCRIPT LOG>
 
##### END_OF_CUSTOMIZATION
exit $exitval