#! /bin/sh
# 
#  Remove entry from etc/devlink.tab.
#  rem_drv random driver if driver is no longer on the system.
#  These changes are based on the postremove script.
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

REMDRV=${ROOTDIR}/usr/sbin/rem_drv
REMDRV_SERVER=/usr/sbin/rem_drv
DEVLINKTB="${ROOTDIR}/etc/devlink.tab"

trap "rm -f /tmp/$$.*;exit" 0 1 2 3 13 15
TMP=/tmp/$$

#
# rem_devlink - removes an entry from ${DEVLINKTB}
#
rem_devlink()
{
	PATTERN="$1"
	LINK="$2"

	if [ -w ${DEVLINKTB} ]; then
	  grep -v "^$PATTERN[	 ]*$LINK$" ${DEVLINKTB} >$TMP.devlink
	  mv $TMP.devlink ${DEVLINKTB}
	fi
}

#
# remove_minor - removes minor node in /dev for passed driver
#
#    Usage:	remove_minor {driver_name}
#
remove_minor()
{
	DRIVER="$1"
	DEVNODE="${ROOTDIR}/dev/${DRIVER}"
	rm -f $DEVNODE
}

if [ -d ${ROOTDIR}/kernel/drv ]; then
  if [ ! -f ${ROOTDIR}/kernel/drv/random ]; then
	if [ -x ${REMDRV} ]; then
		${REMDRV} -b ${ROOTDIR} random
	else
		${REMDRV_SERVER} -b ${ROOTDIR} random
	fi

	rem_devlink 'type=ddi_pseudo;name=random' '\\M0'
	remove_minor random
	remove_minor urandom
  fi
fi

touch ${ROOTDIR}/reconfigure

exit 0
