#!/sbin/sh
###############
# Product: OS-Core
# Fileset: PHKL_18543
# postremove
# @(#) postremove $Date: 1999/05/28 14:24:15 $Revision: r11ros/cup_ros_ep3_pb/3 PATCH_11.00 (PHKL_18543)
################
#
# (c) Copyright Hewlett-Packard Company, 1998,1999
#

_PATCHID=PHKL_18543

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

#########################################################################
# This script part is to replace the whole custom part of the script with
# another patch if needed.  At initial patch release time there is no 
# basepatch_utils file
#

BASEPATCH_UTILS="$SW_ROOT_DIRECTORY/usr/lbin/patch/basepatch_utils"

if [ -f $BASEPATCH_UTILS ] 
then
    # replace with a fixed version if needed
    print -u2 "NOTE:    $BASEPATCH_UTILS installed."
    print -u2 "         Using control script functions from this file."
    . $BASEPATCH_UTILS
    postremove_cntl || exitval=$? # retain a non-zero return value
    exit $exitval
fi # [ -f $BASEPATCH_UTILS ]

########
#
# The driver references should only be removed when it is clear that they
# cannot be useful.  This includes all of the Boot drivers potentially added 
# by this patch. 
#     saga driver for Vclass 
#     sba,lba and sapic drivers for Prelude 
# To work for the future, we need to wait until the postremove time to check
# if the definitions of the drivers are gone.
#
########

########
# FUNCTIONS
########
# DeleteDriverEntry
#
# input: $1 - (string) the driver
#
# Purpose: To delete from the system file the driver that
#          this fileset has delivered and which are no longer defined. 
#

DeleteDriverEntry()
{
    driver=$1
    grep -q "$driver " $master 2>/dev/null
    if [[ $? -eq 1 ]]
      # if there is no definition for this driver in the core-hpux file that
      # will be left around, then remove it from the system file.
      then
        mod_systemfile ${SW_SYSTEM_FILE_PATH} -d $driver
        if [[ $? -ne $SUCCESS ]]
          then
            print "WARNING: The attempt to remove driver \"$driver\" from the system file has"
            print "         failed for the above reason.  This will cause a WARNING during"
            print "         kernel build."
            exitval=$WARNING
        else
            print "NOTE:    Removed \"$driver\" from ${SW_SYSTEM_FILE_PATH}."
        fi
    fi #grep  it's OK if these drivers don't get removed
} # DeleteDriverEntry()

###########################################################################
# MAIN
#

master=$SW_ROOT_DIRECTORY/usr/conf/master.d/core-hpux

for func in diag1 saga sba lba sapic
  do
    DeleteDriverEntry $func
done

grep -q "diag1 " $master 2>/dev/null
if [[ $? -eq 1 ]]
  # if there is no definition for this driver in the core-hpux file that
  # will be left around, then remove special device file
  then
    rm -rf /dev/diag/diag1 > /dev/null 2>&1
fi

exit $exitval
