#!/sbin/sh
###############
# Product: OS-Core
# Fileset: CORE2-KRN
# postinstall (SuperIO IDE)
################
#
# (c) Copyright Hewlett-Packard Company, 1998,1999
#############################################################
# 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_24282

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

SED=sed
MV="mv -f"
RM="rm -f"

system_1100="no"
upgrade="no"
driver_added="no"
subfunction="SuperIO IDE"
sio_master=$SW_ROOT_DIRECTORY/usr/conf/master.d/superio
sio_prodfs="OS-Core.CORE2-KRN"
driver="side"
device="side"

########
# FUNCTIONS
########
# AddDriverEntry
#
#   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
   else
       driver_added="yes"
   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.
#########################################################################

if [[ -x /sbin/ioscan ]] && ( /sbin/ioscan -f | grep -q $device)
then
    AddDriverEntry $driver
fi   #if ioscan

#########################################################################
# This part of the script is intended to warn the customer if he is only
# installing part of the software needed to use this subfunction.
# 
# If 11.00 ACE is installed and the superio master file is not on the
# system, or if we are upgrading from 10.20 Delta to 11.00 ACE and 
# the fileset containing superio is not selected and the superio master
# file is not on the system, the user needs to be warned.

# Determine if the 11.00 version of the SW is installed
grep PATCH_11 $sio_master > /dev/null 2>&1
sio11_installed=$?

# Determine if the SW fileset is selected for install
is_software_selected $sio_prodfs > /dev/null 2>&1
fs_selected=$?

# Check if this is an 11.00 system and superio is already installed.
if [ $sio11_installed -eq 0 ]
then
    system_1100="yes"

# Otherwise, this is an update from 10.20 Delta to 11.00 ACE.
# If superio exists on the system, OS-Core.CORE2-KRN will get 
# installed unless options that should not be changed are.  
# Just check that OS-Core.CORE2-KRN is selected for install
# and superio (10.20) already exists on the system.
elif [ $fs_selected -eq 0 -a -f sio_master ]
then 
    upgrade="yes"
fi

# Warn the user if only part of the functionality is installed
if [ $driver_added = "yes" ] && [ $system_1100 = "no" ] && [ $upgrade = "no" ]
then
    # The superio base patch is not installed.
    print "NOTE:    The $subfunction will not function until the base"
    print "         SuperIO patch is also installed.  The first released"
    print "         SuperIO base patch is PHKL_20152, but this patch may"
    print "         be superseded."
fi 

exit $exitval

