#!/sbin/sh
#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident	"@(#)oamintf:devices/remove/rmdiskette.sh	1.1"

################################################################################
#	Module Name: rmdiskette
#
#	Arguments:  $1 - device alias
################################################################################

bdevice=`/usr/bin/devattr $1 bdevice` > /dev/null
cdevice=`/usr/bin/devattr $1 cdevice` > /dev/null
bino=`ls -li $bdevice | cut -f3 -d' '`
cino=`ls -li $cdevice | cut -f3 -d' '`

btmpfile=/tmp/b.$$
ctmpfile=/tmp/c.$$

ncheck -i$bino /dev/rroot | grep $bino | cut -f2 >> $btmpfile
ncheck -i$cino /dev/rroot | grep $cino | cut -f2 >> $ctmpfile

rdskpath=`grep rdsk $ctmpfile`
ifdskpath=`grep "ifdsk" $btmpfile`
dskname=`expr "${rdskpath}" : '.*/\([^/]*\).$'`
ifdskname=`expr "${ifdskpath}" : '.*/\([^/]*\).$'`

#  remove disk and partition information from device tables

/usr/bin/putdev -d $1 > /dev/null
/usr/bin/putdgrp -d diskette $1 > /dev/null

# remove vfstab entries

grep -v rdiskette /etc/vfstab > /tmp/$$.vfstab
mv /tmp/$$.vfstab /etc/vfstab

# remove device nodes

cat $btmpfile | xargs rm -f
cat $ctmpfile | xargs rm -f
rm -f /dev/dsk/${dskname}? /dev/rdsk/${dskname}? /dev/${ifdskname}? /dev/r${ifdskname}?
rm -f $btmpfile $ctmpfile
exit 0
