#! /bin/sh
#
#	@(#)make_kernel	1.3 93/01/19 Copyright (C) 1992  Sun Microsystems, Inc
#
#	Copyright (c) 1990 by Sun Microsystems, Inc.
#
# All rights reserved.
#
# make_kernel
#
# This script is used to config a kernel during software installation
#
if [ ! -z "$PROTO" ]
then
	sys=${PROTO}/sys
else
	sys=/sys
fi
umask 22
host=`hostname`
myexecname=`basename $0`
KNAME=/usr/tmp/unbundled/SNC/kernelName.ne


#
# doexec function
#
# inputs:
#	exec=		string to execute
#
# outputs:
#	execstatus=	return value from the eval'ing ${exec}
#
# Execute the "exec" string, echo'ing the string 
#
doexec() {
	echo "${exec}"
	eval "${exec}"
	execstatus=$?
	if [ ${execstatus} -ne 0 ]
	then
		echo -n "${myexecname}:  unexpected return code ${execstatus}"
		echo " trying to execute:"
		echo "${exec}"
		exit 11
	fi
}	# End of doexec()

#
# getsysname
#
getsysname() {

	# Use the name saved by edit_config.sh
	if [ -f $KNAME ] ; then
		sysname=`cat $KNAME`
		return
	else
		echo "Installation error.  Couldn't locate $KNAME."
		exit 12
	fi
}	# End of getsysname()


#
# Start of make_kernel main()
#
arch=`arch -k`
confdir=${sys}/${arch}/conf
#
# Get config file name this system
getsysname

echo ""
echo "We will now make a new kernel for your system,"
echo "using the config file $sysname."
echo ""
file="${confdir}/${sysname}"

echo ""
echo "-> Config'ing ${confdir}/${sysname} <-"
echo ""
exec="(cd ${confdir}; config ${sysname})"
doexec

echo ""
echo "-> Making ${sys}/${arch}/${sysname} kernel <-"
echo ""
exec="(cd ${sys}/${arch}/${sysname}; make)"
doexec

# Deal with case like GENERIC_SMALL where vmunix is named vmunix_small
#
vmname=`grep "^config" ${confdir}/${sysname} | awk '{print $2}'`

# Move new kernel to root
#
if [ -h /vmunix ] ; then
	MV_LINE="rm /vmunix      # OK because /vmunix is a symbolic link"
else 
        MV_LINE="mv /vmunix /vmunix.presnc"
fi
if [ $NNCS -gt 1 ] ; then
	S=s
else 
	S=''
fi

source=${sys}/${arch}/${sysname}/${vmname}
target=/vmunix.${sysname}
echo ""
echo "Your new kernel has been successfully loaded."
if [ -f ${target} ]
then
	echo "	${target} already exists, will not automatically overwrite this file"
	MV_LINE0="mv $source $target"
	echo ""
else
	MV_LINE0=
	exec="cp ${source} ${target}"
	doexec
	if [ ${execstatus} -eq 0 ]
	then
		echo "Your kernel has been installed as /vmunix.${sysname}"
		echo ""
	fi
fi
more << EOF
  

You will need to symlink it to /vmunix and reboot.  I.e., do
	$MV_LINE0
	$MV_LINE
	ln -s /vmunix.${sysname} /vmunix
	/usr/etc/shutdown -fh +5 to install $sysname kernel
	Shut off the server.
	Install the Network CoProcessor hardware [if not already installed].
	Connect Ethernet cable$S to the Network CoProcessor$S.
	Restart the server.

EOF
echo ""
echo "Kernel configuration complete."
exit 0
