#!/bin/sh

# @(#)preremove	1.3 01/04/28 Sun Microsystems
# SUNWensqr preremove script
# Copyright (c) 1997-2001 by Sun Microsystems, Inc.
# All rights reserved.
#

#
#	Defining convenient variables for later
#
iroot=${PKG_INSTALL_ROOT:-$BASEDIR}
REM_DRV=rem_drv
DRV1=audioens
DFILE=${iroot}/etc/devlink.tab
TFILE=${iroot}/etc/devlink.tab.tmp
#
# Select the correct rem_drv options to execute.
# Only attempt to unload the driver on a running system
#
if [ "${iroot}" != "/" ]; then
	#
	# On a client,
	# modify the system files and touch /reconfigure ??
	# for reconfigure reboot ??
	#
	REM_DRV="${REM_DRV} -b ${iroot}"
fi


#
#	(Rudimentary) Test to see if rem_drv has already been run before:
#   o	If found *exactly* 3 aliases, rem_drv hasn't been run before, so run it.
#   o	Else, rem_drv has run once already, so don't run it again.
#

if [ `egrep -c "^(${DRV1}) " ${iroot}/etc/name_to_major` -eq 1 ]; then

#
#	Must remove drivers in reverse order of installation
#

#	Remove ensoniq audio driver
	${REM_DRV} ${DRV1} || {
		echo "\n${PKGINST}: Failed ${REM_DRV} ${DRV1}\n" >&2
		exit 1
	}

fi

exit 0
