#! /bin/sh
#	Copyright (c) 1996 Sun Microsystems, Inc.
#		All Rights Reserved

# ident "@(#)postremove	1.10	96/05/23 SMI"
# TADpcmci postremove script

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

EXIT=0

PCMCIA_USER_DAEMON=pcmciad

ARCH="`uname -p`"

REMDRV=/usr/sbin/rem_drv

DEVLINKTB="$BASEDIR/etc/devlink.tab"

if test ! -f ${DEVLINKTB} -o ! -w ${DEVLINKTB}; then
	echo "TADpcmci: file ${DEVLINKTB} is missing/inacessible." >&2
	exit 1
fi

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

#
# killproc - kill the named process(es)
#
killproc() {            # kill the named process(es)
	pid=`/usr/bin/ps -e |
	     /usr/bin/grep $1 |
	     /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	[ "$pid" != "" ] && kill $pid
}

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

	grep -v "^$PATTERN	$LINK$" ${DEVLINKTB} >$TMP.devlink
	mv $TMP.devlink ${DEVLINKTB}
}

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

#
# Kill the PCMCIA user daemon if we're modifying the running system
#
if [ "$BASEDIR" = "/" ] ; then
	killproc ${PCMCIA_USER_DAEMON}
fi

#
# We remove the following drivers in this order:
#
#    SPARC:
#	/kernel/drv/ts102
#
case "${ARCH}" in
	sparc)
		${REMDRV} -b ${BASEDIR} ts102
		remove_minor ts102
		;;
esac

touch ${BASEDIR}/reconfigure

exit ${EXIT}
