# Copyright 09/15/98 Sun Microsystems, Inc. All Rights Reserved.
# @(#)preremove	1.4	04/03/00

PATH=/bin:/sbin:/usr/sbin

if [ -z "$PKG_INSTALL_ROOT" ]; then
  PKG_INSTALL_ROOT=""
  REM_DRV="/usr/sbin/rem_drv"
else
  REM_DRV="/usr/sbin/rem_drv -b ${PKG_INSTALL_ROOT}"
fi


set -u

#
# Uninstall the Sun Ray, utadem, utserial and utparallel pseudo drivers
#

SUNRAY="sunray"
UTADEM="utadem"
UTSERIAL="utserial"
UTPARALLEL="utparallel"
DEVTAB="$PKG_INSTALL_ROOT/etc/devlink.tab"
NEWFILE="${DEVTAB}.new"
TARGDIR="$PKG_INSTALL_ROOT/usr/kernel/drv"

# save a backup copy of the driver link table
/usr/bin/cp -f $DEVTAB $DEVTAB.bak

# remove any existing driver with this name
/bin/sed -e "/name=$SUNRAY[ 	]/d" \
	 -e "/name=$UTADEM[ 	]/d" \
	 -e "/name=$UTSERIAL[ 	]/d" \
	 -e "/name=$UTPARALLEL[ 	]"/d \
	$DEVTAB > $NEWFILE

# "Atomic update"; rename is supposed to be atomic so a crash will
# either leave the old file or the new file as $DEVTAB
/usr/bin/sync
/usr/bin/rm -f "${DEVTAB}.old"
/usr/bin/ln "${DEVTAB}" "${DEVTAB}.old"
/usr/bin/sync
/usr/bin/mv -f "${NEWFILE}" "${DEVTAB}"
/usr/bin/sync

# uninstall the drivers (if loaded)
$REM_DRV $SUNRAY
$REM_DRV $UTADEM
$REM_DRV $UTSERIAL
$REM_DRV $UTPARALLEL

echo "### successfully removed Sun Ray pseudo drivers"

exit 0
