#ident	"@(#)xl:ID/Remove	1.1"
#
#	Archive XL Floppy Tape Remove Package
#
BLD=$1
TMP=/tmp/ftapedrv.err1
CONFDIR=/etc/conf/cf.d
ERROR1="An an error was encountered removing the Archive XL Floppy Tape Driver.\
  The file $TMP contains errors reported by the system."
ERROR2="The kernel rebuild failed.  However all software dealing with the \
streaming tape has been removed.  The Archive XL Floppy Tape Unit - Version \
1.0 will still appear in the Show Installed Software / Remove Installed \
Software menus because the kernel still has the tape driver in it.  \
Please correct the problem and remove the software again.  The file \
$TMP contains error reported by the system."

rm -f $TMP > /dev/null 2>&1
if [ $# != 1 ]
then echo "\n\n\n\n\n\nRemoving Archive XL Floppy Tape Utilities - Version 1.0 ...\n\n"
fi

if [ -x /etc/conf/bin/idcheck -a -x /etc/conf/bin/idbuild -a -x /etc/conf/bin/idinstall ]
then 
	:
else 
	message "The Installable Driver feature has been removed.  The Archive XL Floppy Tape Driver cannot be removed."
	exit 1
fi

echo "Removing the XL floppy tape driver...\n"
/etc/conf/bin/idcheck -p xl 2>/dev/null
if [ $? = 0 ]
then
	exit 0
fi

if [ $# = 0 ]
then
/etc/conf/bin/idinstall -d xl 2>> $TMP
if [ $? != 0 ]
then
	message $ERROR1
	exit 1
fi
else
	/etc/conf/bin/idinstall -e -d xl > /dev/null 2>&1
fi

echo "Restoring the floppy disk driver...\n"
if [ -f ${CONFDIR}/mdevice ]
then
	ed - "${CONFDIR}"/medevice <<- ! >/dev/null 2>&1
		/fd/s/D.*//g
		w
		q
	!
fi
mv /etc/conf/pack.d/fd/Driver.o.orig /etc/conf/pack.d/fd/Driver.o

echo "Removing floppy tape utility...\n"
rm -f /usr/include/sys/ftape.h

if [ -d /dev/rmt ]
then
	rm -f /dev/rmt/f1q80 /dev/rmt/f1q80n /dev/rmt/f1q80r /dev/rmt/f1q80nr
	if [ 3 -eq `expr \`ls -al /dev/rmt | wc -l\`` ]
	then
		rm -rf /dev/rmt
	fi
fi

if [ -d /usr/lib/tape ]
then
	rm -rf /usr/lib/tape/node.d
	mv /usr/lib/tape/ftapecntl /usr/tmp/tape1$$ > /dev/null 2>&1
	rm -f /usr/tmp/tape1$$ > /dev/null 2>&1
	sync; sync
	if [ 3 -eq `expr \`ls -al /usr/lib/tape | wc -l\`` ]
	then
		rm -rf /usr/lib/tape
	fi
fi

#####
# Remove the tape control funcions to the user interface if
# FACE is already installed.

FACEDIR="/usr/vmsys/OBJECTS"
if [ -d "$FACEDIR" ]
then
	FTAPE="${FACEDIR}"/ftape
	if [  -d  "$FTAPE" ]
	then
		rm -rf "$FTAPE"
	fi

	if [ -f "${FACEDIR}/Menu.admin" ]
	then
		ed - "${FACEDIR}"/Menu.admin <<- !
			g/^name=Floppy Tape Operations/d
			g/^action=.*tape.Menu.ftape.*$/.,+1d
			w
			q
		!
	fi
fi
############

echo "Rebuilding UNIX kernel...\n\n\n"
if [ "$BLD" != NOBUILD ]
then
	/etc/conf/bin/idbuild 2>> $TMP
	if [ $? != 0 ]
	then
		message $ERROR2
		exit 1
	fi
fi
rm -f $TMP
exit 0
