:
#
# @(#) mgxupdate.sh 1.5 93/02/07 
#
# 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.
#
#
#	Driver configuration script to be run after installing the
#	Microfield Graphics Server Supplement for ODT
#
#	Copyright (c) 1992  Microfield Graphics, Inc.
#	Copyright (c) 1992  Santa Cruz Operation
#	All Rights Reserved
#
# 	Derived from /usr/lib/custom/tcprt.rmv
#


##### ENVIRONMENT DEFINITIONS #####

PATH=/bin:/usr/bin:/etc
LANG=english_us.ascii	# Used when scripts are internationalized.
export PATH LANG

ERRFILE=/tmp/mgx.err
DRIVER=$1

##### RETURN VALUES #####

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


##### PATHS #####

CONFDIR=/etc/conf
CONFBIN=${CONFDIR}/bin
TEMPLATE=/usr/lib/vidconf/ihv/microfield/kernelconf


##### MESSAGES #####

DNAME="Microfield Graphics X8 Driver"
ERRORLOG="\nErrors have been written to the file $ERRFILE."
ABORTING="Aborting the installation.\n\tThe driver has not been installed.\n"
NOTOOLS="The Installable Driver utilities are not installed.\n\tThe driver cannot be installed without them.\n"
NODRIVER="The /dev/${DRIVER} installation files are not in \n\t${TEMPLATE}.\n\tThe driver cannot be installed/updated without them.\n"


##### FUNCTION DEFINITIONS #####

#**** Traps for critical and non critical code. ****

set_trap()  {	
	trap 'echo "\nInterrupted! Exiting ..."; exit ${FAIL}' 1 2 3 15
}

unset_trap()  {
	trap '' 1 2 3 15
}

clearscr() {
	[ "$TERM" ] && [ -x /bin/clear ] && clear 2> /dev/null
}

 
#**** Prompt for continuation. ****
pause() {
	while	echo "\nHit [Enter] to continue\c">&2
	do	read yn rest
		case $yn in
		*)	return $OK			;;
		esac
	done
}

#**** Print an error message. ****

error() {
	echo "\nError:\t$*" >&2
}


#**** 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
}


#**** Test to see if link kit is installed ****

linkchk()  {
	[ -x ${CONFBIN}/idbuild ] && {
		[ -x ${CONFBIN}/idinstall ] && {
			return ${OK}
		}
	}
	error ${NOTOOLS}
	return ${FAIL}
}


#************************* PRIMARY FUNCTION ******************************

mgxupd () 
{

linkchk || return ${FAIL}

if [ ! -d ${TEMPLATE}/${DRIVER} ]
then
	error ${NODRIVER}
	return ${FAIL}
fi

if [ ! -d /tmp/driver.${DRIVER}tmp ]
then
	mkdir /tmp/driver.${DRIVER}tmp
fi

cd ${TEMPLATE}/${DRIVER}
cp Driver.o /tmp/driver.${DRIVER}tmp
cp Space.c /tmp/driver.${DRIVER}tmp
cp Node /tmp/driver.${DRIVER}tmp
cp System /tmp/driver.${DRIVER}tmp
cp Master /tmp/driver.${DRIVER}tmp
cd /tmp/driver.${DRIVER}tmp

#**** Install Driver ****

${CONFBIN}/idcheck -p ${DRIVER} 2>> $ERRFILE
if [ $? = 0 ]
then
	${CONFBIN}/idinstall -a ${DRIVER} 2>> $ERRFILE
	IDSTATUS=$?
	rm -f /etc/conf/pack.d/${DRIVER}/${DRIVER}.h
	cp ${TEMPLATE}/${DRIVER}/${DRIVER}.h /etc/conf/pack.d/${DRIVER}
else
	${CONFBIN}/idinstall -u ${DRIVER} 2>> $ERRFILE
	IDSTATUS=$?
fi

cd /tmp			# get out of /tmp/driver.mgxtmp so it can be deleted

if [ $IDSTATUS != 0 ]
then
       	message "The installation cannot be completed due to an error \
in the driver installation. $ERRORLOG"
	rm -rf /tmp/driver.${DRIVER}tmp
	return $FAIL
fi

rm -rf /tmp/driver.${DRIVER}tmp

return $OK

}


#########################
# main()

set_trap

rm -f $ERRFILE > /dev/null 2>&1

mgxupd || {
	cd /tmp
	unset_trap
	exit $FAIL
}

cd /tmp
rm -f $ERRFILE > /dev/null 2>&1

unset_trap

exit $OK

