#sccs	"@(#)combobrd:Remove	1.8"
#
#***************************************************************************
#
#	Remove script for RS-232 Expansion board.
#	6/85 -  C. Liu
#
#***************************************************************************
#
echo
echo '          Removing RS-232 expansion software'
echo

cp /etc/inittab /tmp/oldinittab
LIST="001 002 003 004 005 006"
for TTY in $LIST
do
	setgetty $TTY 0
	sleep 2
done

echo '          Unloading the driver from the system ...'
echo

/etc/lddrv/lddrv -s|grep cmb>/dev/null
if [ "$?" = "0" ]
then
	/etc/lddrv/lddrv -d cmb
	if [ "$?" != "0" ]
	then
	clear
	message -iu "Expansion ports are in use, please ask the users to logoff before removing the software. \n\nPress Enter to continue."
	mv /tmp/oldinittab /etc/inittab
	exit 64
	fi
fi

cp /etc/inittab /tmp/initcmb
for i in $LIST
do
	grep -v  "$i:.*getty" /tmp/initcmb > /tmp/initcmb$i
	mv /tmp/initcmb$i /tmp/initcmb
done
mv /tmp/initcmb /etc/inittab
telinit q
sleep 5

echo '          Deleting support files ...'
echo
rm -f /etc/.rs232_00*

# disable Hardware Flow Control and delete init files
for TTY in $LIST
do
	rm -f /etc/daemons/tty$TTY.init 
	/etc/hfc_ctl -/dev/tty$TTY >/dev/null 2>&1
done
rmdir /etc/daemons >/dev/null 2>&1

#
# remove possible printers that are connected to the expansion ports
#
echo '          Removing printers ...'
echo '          The lp scheduler will be temporarily shutdown!'
echo 
CLASS="Serial1 Serial2 Serial3 Serial4 Serial5 Serial6"
/usr/lib/lpshut 2>&1 > /dev/null
sleep 3

# Remove all jobs attached to the expansion-ports-printers. This is 
# necessary in order for the disabled printers to be removed by lpadmin.

for i in $CLASS
do
	if [ -s /usr/spool/lp/class/$i ]
	then
		CLASSPTR=`cat /usr/spool/lp/class/$i`
		cancel `lpstat -o"$i $CLASSPTR" | cut -f1 -d" "` 2>&1 > /dev/null
	fi
done

# if the default printer is attached  to an expansion port, remove it.
if [ -s /usr/spool/lp/default ]
then
	DEFAULT=`cat /usr/spool/lp/default`
	for i in $CLASS
	do
		if [ -s /usr/spool/lp/class/$i ]
		then
			CLASSPTR=`cat /usr/spool/lp/class/$i`
			if [ "$DEFAULT" = "$CLASSPTR" ]
			then
				/usr/lib/lpadmin -d  2>&1 > /dev/null
			fi
		fi
	done
fi

			
# remove the printers that are in the expansion ports.
for i in $CLASS
do
	if [ -s /usr/spool/lp/class/$i ]
	then
		CLASSPTR=`cat /usr/spool/lp/class/$i`
		/usr/lib/lpadmin -x$CLASSPTR 2>&1 > /dev/null
	fi
done
/usr/lib/lpsched

#
# signal phmgr that combo card is being removed.
#
/etc/lddrv/cmbupd
rm -f /etc/lddrv/*cmb /etc/lddrv/cmb*
rm -f /usr/bin/CMB232.sh /usr/lib/ua/CMB232.menu


echo '          Updating system files ...'
echo
uaupd -r "RS232 Expansion Setup" Hardware
masterupd -d cmb
fgrep -v cmb /etc/lddrv/drivers > /tmp/temp
mv /tmp/temp /etc/lddrv/drivers

fgrep -v "RS232 Expansion" /etc/lddrv/InstDrv >/tmp/temp
fgrep -v cmb /tmp/temp >/tmp/temp2
mv /tmp/temp2 /etc/lddrv/InstDrv
rm -f /tmp/temp

#
# Remove the device entries
#
echo '          Deleting device files of the new ports ...'
echo
rm -f /dev/tty001 /dev/tty002 /dev/tty003 /dev/tty004 /dev/tty005 /dev/tty006
echo '          Removal of RS-232 expansion software Complete'
echo
