#! /sbin/sh
########
# Product: FCMassStorage
# Fileset: FCMS-KRN
# preremove
# @(#) $Revision: 1.1.98.1 $
########
#
# (c) Copyright Hewlett-Packard Company 1995
#
########################################################################
# FUNCTIONS
########
# DeleteDriverEntry
#
#   Purpose:  To delete from the system file all the drivers that this fileset
#       has delivered.  Set the $exitval value based on the return value from
#       mod_systemfile().  If multiple deletions, ensure that a FAILURE value
#       of $exitval is not reduced by a later SUCCESS return.
#
DeleteDriverEntry()
{
    typeset retval

    for driver_name in  \
	fcgsc_fcp        \
	fcpmux

    do
	mod_systemfile ${SW_SYSTEM_FILE_PATH} -d $driver_name
	retval=$?
	if [[ $retval -ne $SUCCESS ]]
	then
	    MSG_DriverDeleteFailed
	    [[ $retval -ne $SUCCESS && $exitval -ne $FAILURE ]] && exitval=$retval
	fi
    done

} # DeleteDriverEntry()
#
########
# DeleteConfigurables
#
#   Purpose:  To delete from the system file the configurable parameters that
#       pertain only to this fileset's functionality.  Configurable parameters
#       which are common, and which were modified at installation, should not
#       be adjusted here without considering other users.
#
#       Set the $exitval value based on the return value from mod_systemfile().
#	If multiple deletions, ensure that a WARNING or FAILURE value of
#	$exitval is not reset by a later SUCCESS return.
#
#       Since an unknown configurable parameter does not cause a config(1m)
#       failure, this function only needs to return a WARNING, not an ERROR in
#       the case of failure.
#
DeleteConfigurables()
{
    typeset retval

    for parm in  \
	num_fcp_adapters    \
	max_fcp_reqs

    do
	mod_systemfile ${SW_SYSTEM_FILE_PATH} -d $parm
	retval=$?
	if [[ $retval -ne $SUCCESS ]]
	then
	    MSG_ParmDeleteFailed
	    [[ $retval -ne $SUCCESS && $exitval -ne $FAILURE ]] && exitval=$WARNING
	fi
    done

} # DeleteConfigurables()
#
########
# MSG_DriverDeleteFailed
#
#   Purpose:  To issue an ERROR message to the agent log file.  
#
MSG_DriverDeleteFailed()
{
    cat <<- !!EOF
ERROR:   The attempt to remove driver "$driver_name" from the system file
         has failed for the above reason.  You must ensure that the system
         file at "${SW_SYSTEM_FILE_PATH}" does not contain an entry for
         "$driver_name" before a kernel build is attempted.  Manually editing
         "${SW_SYSTEM_FILE_PATH}" to delete references to "$driver_name" is
         one option you have.
!!EOF
} # MSG_DriverDeleteFailed()
#
########
# MSG_ParmDeleteFailed
#
#	Purpose:  To issue a WARNING message to the agent log file.  
#
MSG_ParmDeleteFailed()
{
    cat <<- !!EOF
WARNING: The attempt to delete the configurable parameter "$parm" from the
         system file has failed for the above reason.  Leaving this parameter
	 in the system file will not cause a failure, but it should be 
	 manually deleted from ${SW_SYSTEM_FILE_PATH} as soon as practical.
!!EOF
} # MSG_ParmDeleteFailed()
#
########################################################################
# MAIN

    typeset exitval

    UTILS=/usr/lbin/sw/control_utils
    if [ -f $UTILS ]
    then
        . $UTILS
    else
        echo "ERROR:   Cannot find $UTILS"
        exit 1
    fi
    exitval=$SUCCESS

########

    if [[ ${SW_SESSION_IS_KERNEL:-FALSE} = "TRUE" ]]
    then
	DeleteDriverEntry
	DeleteConfigurables
    fi

    exit $exitval
