#
# ident "@(#)preremove.src	1.2 04/01/21 SMI"
#
# Copyright 1998,2004 Sun Microsystems, Inc.  All rights reserved.
#

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

if [ -z "$PKG_INSTALL_ROOT" ]; then PKG_INSTALL_ROOT=""; fi

set -u

if [ -z "$PKG_INSTALL_ROOT" ]; then
  REM_DRV="rem_drv"
else
  REM_DRV="rem_drv -b $PKG_INSTALL_ROOT"
fi

#
# 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
cp -f $DEVTAB $DEVTAB.bak

# remove any existing driver with this name
#
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
sync
rm -f $DEVTAB.old
ln $DEVTAB $DEVTAB.old
sync
mv -f $NEWFILE $DEVTAB
sync

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

echo "### removed Sun Ray pseudo drivers"

exit 0
