#! /sbin/sh

# $Source: /usr/local/kcs/sys.DAVIS_800/filesets.info/LVM/RCS/preremove,v $
# $Revision: 1.2.98.2 $	$Author: bracken $
# $State: Exp $   	$Locker:  $
# $Date: 96/02/06 19:12:03 $

########
# Product: LVM
# Fileset: LVM-KRN
# preremove
# @(#) $Revision: 1.2.98.2 $
########
#
# (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  \
	lv \
	lvm
    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()
#
########
# 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()
#
########################################################################
# 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
    fi

    exit $exitval
