:
#
# @(#) mfgremove.sh 1.8 93/02/26 
#
# Copyright (C) 1992 The Santa Cruz Operation, Inc.
#
# The information in this file is provided for the exclusive use of the
# licensees of The Santa Cruz Operation, Inc.  Such users have the right 
# to use, modify, and incorporate this code into other products for 
# purposes authorized by the license agreement provided they include
# this notice and the associated copyright notice with any such 
# product.  The information in this file is provided "AS IS" without 
# warranty.
#
# Invoked by /usr/lib/custom/xsrvr.rmv
# 

: ${OK=0} ${FAIL=1} ${STOP=10} ${HALT=11} ${EXIT=3} ${DUP=2}

##### PATHS #####

CONFDIR=/etc/conf
CONFBIN=${CONFDIR}/bin

#**** Prompt for yes or no answer - returns non-zero for no. ****

getyn() {
	while	echo "\n$* (y/n) \c">&2
	do	read yn rest
		case $yn in
		[yY])	return ${OK} 			;;
		[nN])	return ${FAIL}			;;
		*)	echo "Please answer y or n" >&2	;;
		esac
	done
}

#**** Ask/Re-build the kernel now ****

dolink()  {
	getyn "
You must create a new kernel to remove the video drivers.
Do you want to create a new kernel now?"  ||  { echo "

To create a new kernel execute /etc/conf/cf.d/link_unix. Then you
must reboot your system by executing  /etc/shutdown -i0  before the 
new driver you have installed will be available.\n"
		return ${OK}
	}

	klink || {
		unset_trap
		exit ${FAIL}
	}
	return ${OK}
}


#**** Re-link new kernel ****

klink() {
	cd /etc/conf/cf.d
	./link_unix || { 
		error "Kernel link failed."
		return ${FAIL}
	}
	return ${OK}
}

RELINK="NO"

/etc/conf/bin/idcheck -p mfg 2> /dev/null
if [ $? != 0 ]
then
    /etc/conf/bin/idinstall -d mfg
    # idinstall -d doesn't pull mfg from sdevice
    sed -e "/mfg/d" < $CONFDIR/cf.d/sdevice > $CONFDIR/cf.d/sdevice.new
    mv $CONFDIR/cf.d/sdevice.new $CONFDIR/cf.d/sdevice
    rm -rf /etc/conf/node.d/mfg /etc/conf/sdevice.d/mfg /etc/conf/pack.d/mfg /dev/mfg
    RELINK="YES"
fi

/etc/conf/bin/idcheck -p mgx 2> /dev/null
if [ $? != 0 ]
then
    /etc/conf/bin/idinstall -d mgx
    # idinstall -d doesn't pull mgx from sdevice
    sed -e "/mgx/d" < $CONFDIR/cf.d/sdevice > $CONFDIR/cf.d/sdevice.new
    mv $CONFDIR/cf.d/sdevice.new $CONFDIR/cf.d/sdevice
    rm -rf /etc/conf/node.d/mgx /etc/conf/sdevice.d/mgx /etc/conf/pack.d/mgx /dev/mgx
    RELINK="YES"
fi

if [ $RELINK = "YES" ]
then
    dolink
fi

exit 0
