#
#	@(#)Remove	1.5 11/4/94
#	Copyright (c) Digiboard, Inc.
#
#	EPCA Driver Remove Script
#
#	Operating Systems:	HP-UX 10.x, 11.x
#
NAME="epca"
Ittyname="tty"
Ottyname="cu"
Prname="pr"
ids=`cat /etc/conf/digi/epca/epcadrvids`
#ids="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoO"
OSVER=`uname -r`
BDNAME="Digi AccelePort EPC/X, C/X, Xem, and Xr"
FULLNAME="Digi AccelePort EPCA Driver Package"
TMP=/tmp/$NAME.err
ERROR=" An error was encountered removing the $FULLNAME.
	The file $TMP contains errors reported by the system."
#
#	Yes or No
#
getyn='( while	read yn
	do	case "$yn" in
			[yY])	exit 0
				;;
			[nN])	exit 1
				;;
			*)	echo "	Please answer y or n : \c" >&2
				;;
		esac
	done)'


clear

#
# Check to see if this is called from the CONFIG script
#
if [ $# -eq 1 ]
then
	if [ $1 = "install" ]
	then
		install=""
	fi
else
	install=TRUE
fi

echo "Removing driver references from configuration files"

# Remove driver info from OS config files
#if [ -f /etc/conf/digi/epca/hprm ]
#then
#	/etc/conf/digi/epca/hprm
#fi
rm -f /usr/conf/master.d/emux
/usr/lbin/sysadm/system_prep -s /stand/build/system
awk '$1 != "emux" { print $0 }' < /stand/build/system > /tmp/digi_tmp_system
if [ -f /tmp/digi_tmp_system ]
then
	mv /tmp/digi_tmp_system /stand/build/system
fi

#
# Remove driver downloader
#
if [ -f /sbin/init.d/digiepca ]
then
	rm -f /etc/rc.config.d/digiepca
	rm -f /sbin/init.d/digiepca
	rm -f /sbin/rc3.d/S100digiepca
	rm -f /sbin/rc2.d/K900digiepca
	rm -f /etc/conf/digi/epca/mktty.sh
fi

#
# Remove the support files created by the configure utility
#
if [ -f /usr/conf/digi/Space.c ]
then
	rm -f /usr/conf/digi/Space.c
	rm -f /usr/conf/digi/space.o
fi
if [ -f /usr/conf/lib/libdigi.a ]
then
	rm -f /usr/conf/lib/libdigi.a
fi
if [ -f /etc/conf/digi/${NAME}/${NAME}ttyname ]
then
	rm -f /etc/conf/digi/${NAME}/${NAME}ttyname
	rm -f /etc/conf/digi/${NAME}/${NAME}ottyname
	rm -f /etc/conf/digi/${NAME}/${NAME}prname
fi


echo "Removing $FULLNAME ..."

echo "Removing device files and references ...\c"

for currid in ${ids}
do
	echo " ${currid}\c"

	#
	# Remove references from the /etc/ttytype file
	#
	if grep -s "${Ittyname}" /etc/ttytype > /dev/null
	then
		mv /etc/ttytype /etc/ttytype.digi
		sed -e '
/'"${Ittyname}"'['"${currid}"'][0-9][0-9]/ d
' /etc/ttytype.digi > /etc/ttytype
	fi

	#
	# Remove references from the /etc/inittab file
	#
	if grep -s "${Ittyname}" /etc/inittab > /dev/null
	then
		mv /etc/inittab /etc/inittab.digi
		sed -e '
/'"${Ittyname}"'['"${currid}"'][0-9][0-9]/ d
' /etc/inittab.digi > /etc/inittab
		chmod 444 /etc/inittab
		chown bin /etc/inittab
		chgrp bin /etc/inittab
	fi

	#
	# Removing the old devices
	#
	rm -f /dev/${Ittyname}[${currid}][0-9][0-9]
	rm -f /dev/${Prname}[${currid}][0-9][0-9]
done
echo ""

#
# Removing the download device
#
echo "Removing the download device ..."
rm -f /dev/dl

#
# Relink the kernel
#
# check a commandline arg to see if this is being called
# from the install script: 
# if (install) no_prompt
# else yes_prompt
#
if [ ${install} ]
then
	echo "Do you wish to relink the kernel (y or n)? \c"

	if eval "${getyn}" 
	then
		# do the relink
		cd /stand/build
		/usr/sbin/config -s system
		make -f config.mk 2>$TMP

		# check for successful link
		if [ $? != 0 ]
		then
			message $ERROR
			exit 1
		else
			# if successful link, make backup then install it
			if [ -f /stand/vmunix ]
			then
				echo "Making backup copy of the kernel to /stand/vmunix.bak"
				mv /stand/vmunix /stand/vmunix.bak
			fi

			if [ -f /stand/build/vmunix_test ]
			then
				echo "Installing the new kernel\n"
				mv /stand/build/system /stand/system
				mv /stand/build/vmunix_test /stand/vmunix
			fi
		fi
	fi
fi

#
# All done, remove the error file and leave
#
rm -f $TMP

echo "Removal of $NAME was successful\n"

exit 0
