#!/bin/sh
# @(#) 110208 prebackout 1.3 01/07/25 SMI
################################################################################
#
#	From : david.pointon@uk.sun.com
#       Shortened by: jonathan.purcell@uk.sun.com
#
################################################################################
################################################################################
#
#   Copyright (c) 1998 Sun Microsystems, Inc.
#       All Rights Reserved
#
################################################################################

SCRIPT="prebackout"
# Add variables to define the driver specific processing configuration
DRVS="lomv"

DLTAB="$ROOTDIR/etc/devlink.tab"
DLTMP=/tmp/devlink.$$

exec 1>&2
PATH=$PATH:/usr/bin:/a/usr/bin

if [ ! -f $DLTAB ]
then
	echo "$SCRIPT (ERROR): file '$DLTAB' does not exist"
	exit 1
else
	if [ ! -w $DLTAB ]
	then
		echo "$SCRIPT (ERROR): file '$DLTAB' is not writeable"
		exit 1
	fi
fi

echo "$SCRIPT (INFO): Starting"

# Select the correct rem_drv options to execute.
# Only attempt to attach the driver on a running system.
# On a client, modify the system files and touch /reconfigure
# for a reconfigure reboot.

if [ "${ROOTDIR}" = "/" ]
then
	DRVOPT=""
else
	DRVOPT="-b ${ROOTDIR}"
fi

# Attempt to remove the identified drivers

STATUS=0
for DRV in ${DRVS}
do
	echo; echo "$SCRIPT (INFO): Removing driver '$DRV'..."

	rem_drv ${DRVOPT} ${DRV}; S=$?
	if [ $S != 0 ]
	then
		echo "$SCRIPT (WARNING): Failed to remove driver, status $S"
		STATUS=1
	fi

	R=`egrep "name=(SUNW,)?${DRV}[ 	]" $DLTAB`
	if [ "$R" ]
	then
		echo "Cleaning up old devlink entry '$R'"
		egrep -v "name=(SUNW,)?${DRV}[ 	]" $DLTAB >$DLTMP
		cat $DLTMP >$DLTAB
		rm -f $DLTMP
	fi
done

echo "$SCRIPT (SUCCESS): Finished"
echo
exit 0
