#! /bin/sh

# ident	"@(#)preremove	1.12	05/06/07 SMI"
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
 
PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

EXIT=0

installed() {
	driver=$1
	grep "^${driver} " $BASEDIR/etc/name_to_major > /dev/null 2>&1

	return $?
}

#
# Remove the new framework drivers
#
remove_usba10_drivers() {
	if installed usba10_hid
	then
		rem_drv -b ${BASEDIR} usba10_hid || EXIT=1 
	fi

	if installed usba10_hubd
	then
		rem_drv -b ${BASEDIR} usba10_hubd || EXIT=1 
	fi

	if installed usba10_scsa2usb
	then
		rem_drv -b ${BASEDIR} usba10_scsa2usb || EXIT=1 
	fi

	if installed usba10_usb_mid
	then
		rem_drv -b ${BASEDIR} usba10_usb_mid || EXIT=1 
	fi

	if installed usba10_usbprn
	then
		rem_drv -b ${BASEDIR} usba10_usbprn || EXIT=1 
	fi

	if installed usba10_usb_ac
	then
		rem_drv -b ${BASEDIR} usba10_usb_ac || EXIT=1
	fi

	if installed usba10_usb_as
	then
		rem_drv -b ${BASEDIR} usba10_usb_as || EXIT=1
	fi

	if installed usba10_usbser_edge
	then
		rem_drv -b ${BASEDIR} usba10_usbser_edge || EXIT=1 
	fi
}


#
# Remove the old framework drivers
#
remove_usba00_drivers() {
	if installed hid
	then
		rem_drv -b ${BASEDIR} hid || EXIT=1
	fi

	if installed hubd
	then
		rem_drv -b ${BASEDIR} hubd || EXIT=1
	fi

	if installed usb_mid
	then
		rem_drv -b ${BASEDIR} usb_mid || EXIT=1
	fi

	if installed scsa2usb
	then
		rem_drv -b ${BASEDIR} scsa2usb || EXIT=1
	fi

	if installed usbprn
	then
		rem_drv -b ${BASEDIR} usbprn || EXIT=1
	fi

	if installed usb_ac
	then
		rem_drv -b ${BASEDIR} usb_ac || EXIT=1
	fi

	if installed usb_as
	then
		rem_drv -b ${BASEDIR} usb_as || EXIT=1
	fi

	case ${ARCH} in
		sparc)
			if installed usbser_edge
			then
				rem_drv -b ${BASEDIR} usbser_edge || EXIT=1
			fi
		;;
	esac
}


#
# Remove host controller drivers
#
remove_host_controller_drivers() {
	case ${ARCH} in
		i386)
			if installed uhci
			then
				rem_drv -b ${BASEDIR} uhci || EXIT=1
			fi

			if installed usba10_uhci
			then
				rem_drv -b ${BASEDIR} usba10_uhci || EXIT=1
			fi
		;;

		sparc)
			if installed ohci
			then
				rem_drv -b ${BASEDIR} ohci || EXIT=1
			fi
		;;
	esac

	if installed usba10_ohci
	then
		rem_drv -b ${BASEDIR} usba10_ohci || EXIT=1
	fi

	if installed usba10_ehci
	then
		rem_drv -b ${BASEDIR} usba10_ehci || EXIT=1
	fi
}


# Remove the new framework drivers
remove_usba10_drivers

# Remove the old framework drivers
remove_usba00_drivers

# Remove the host controller drivers of both frameworks
remove_host_controller_drivers

exit $EXIT
