
# Filename: buildscan
#
# Description:
#	Build the scan driver into SCO kernel
#	and create scan device special file if necessary.
#
#        INTEL CORPORATION PROPRIETARY INFORMATION		
#							
#  This software is supplied under the terms of a license
#  agreement or nondisclosure agreement with Intel Corporation
#  and may not be copied or disclosed except in accordance
#  with the terms of that agreement.			
#
# Usage:
#	buildscan
#	
# Modification History:
#
# $Log: buildscan,v $
# Revision 1.3  1993/03/23  02:24:56  mouli
# Message output fixed.
#
# Revision 1.2  1993/03/23  02:18:11  mouli
# Fixed mknod command and initialization major device number.
#
# Revision 1.1  1993/03/23  01:11:11  mouli
# Initial revision
#
##############################################################################
#
# What string:
#
# @(#) buildscan DIAG_REL_2.0 Thu Jan  5 12:04:09 PST 1995
#
##############################################################################

# scandev 	- The device special file for accessing corelis board
# devPerm	- mode to be set for the device special file
# drvprefix	- The driver routine prefix name 
# drvroutines	- Set of driver routines to be linked into kernel
# majNum	- to be initialized at start

scandev=/dev/scan
drvprefix=scan
devPerm=u+rw
drvroutines="scaninit scanopen scanclose scanioctl"
majNum=
minNum=0
#
# TRUE should be zero and FALSE should be non-zero 
# so that we can use with return/if statements.
TRUE=0
FALSE=1
#
# IsDriverP()
#	$1 - Driver prefix
#
#	Is the Driver Present in the kernel?
#
# Returns TRUE if driver is already there
#         FALSE otherwise
IsDriverP()
{
	devdriver=$1
	( cd /etc/conf/cf.d; 
	[ "`./configure -j ${devdriver}`" = "No such device" ] && return ${FALSE}
	return ${TRUE}
	)
}
# GetMajor()
#  Get the next available major device number
#  Uses the global shell variable initialized to null
#  at start of script.
GetMajor()
{
	majNum=`cd /etc/conf/cf.d; ./configure -j NEXTMAJOR`
}
#
# ConfigDriver()
#	Configure the scan driver into the kernel
#	Uses the next available major number initialized at start
#
ConfigDriver()
{
	echo "Configuring scan driver into kernel"
	(cd /etc/conf/cf.d;
	./configure -c -m ${majNum} -v 0 -a ${drvroutines}
	)
}
#
# ConfigDev()
#	Create a device special file for scan driver if necessary
#
ConfigDev()
{
	if test -c ${scandev} ; then 
		echo "${scandev} exists"
	else
		echo "${scandev} does not exist, building into kernel"
		(cd /etc/conf/cf.d;
		/etc/mknod ${scandev} c ${majNum} ${minNum}
		chmod ${devPerm} ${scandev}
		)
	fi
}
#
# BuildKernel()
#	Relink the kernel.
#
BuildKernel()
{
	(cd /etc/conf/cf.d;
	./link_unix
	)
}
#
# BinPrompt()
#    $1 - Prompt string
#   Displays the prompt string with a ? and asks for
#   a yes/no answer. If the answer is [Yy]es it returns TRUE.
#   Otherwise, it returns FALSE.
#
BinPrompt()
{
	echo "${1}? <y/n> \c"
	read rsp
	case $rsp in
		[Yy]*)
			return ${TRUE}
			;;
		*)
			return ${FALSE}
			;;
	esac
}
Main()
{
#	Initialize the next available major number
	GetMajor
	if IsDriverP ${drvprefix}; then
		echo "Device driver for ${drvprefix} exists"
		if BinPrompt "Do you want to rebuild the kernel" ; then
			echo Rebuild kernel with scan driver 
		else
			echo Skipping kernel rebuild with scan driver
			exit
		fi
		echo "Build the driver afresh into the kernel"
	else
		echo "Device driver for ${drvprefix} does not exist"
		ConfigDriver
	fi
	ConfigDev
	BuildKernel
}
Main
