#ident	"@(#)qt:ID/Remove	1.2"
#
#	Streaming Tape Remove Package
#
BLD=$1
TMP=/tmp/tpdrv.err1
ERROR1="An an error was encountered removing the Streaming 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 Streaming Cartridge Tape Unit - Version \
2.2 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 Cartridge Tape Utilities - Version 2.2 ...\c"
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 Streaming Tape Driver cannot be removed."
	exit 1
fi

/etc/conf/bin/idcheck -p qt 2>/dev/null
if [ $? = 0 ]
then
	exit 0
fi

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

if [ -d /dev/rmt ]
then
	rm -f /dev/rmt/c0s0 /dev/rmt/c0s0n /dev/rmt/c0s0r /dev/rmt/c0s0nr
	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/tapecntl /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
echo ".\c"

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

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

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

echo "...Complete.\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
