#! /bin/sh
#set -x
#
# Copyright (c) 1987 by Sun Microsystems, Inc.
# @(#)ipc_configure	195.1 - 90/01/11
#
# Name: ipc_configure
#
# Description: 
# The ipc product needs some additional installation support to
# get itself into the system.  This includes changing the kernel,
# making pc[0123], changing /etc/inetd.conf,
# /etc/services, /etc/rpc
#
# servers to be installed:
#	pcserver
#	pcnfsd
# 
# USAGE:
#       ipc_configure
#
# The environment variable PCTOOLDIR is used as the top directory of the
# pctool hierarchy.  See below for more environment variables that are
# imported.
#
#
#####################################################
#####  Static Variables (Do not change these) #######
#####################################################
# Install directory and Log file for installation
PATH=/usr/ucb:/bin:/usr/bin:/etc:/usr/etc
export PATH
WORK_DIR="/usr/tmp/unbundled"
SH_NAME=`basename ${0}`
LOGFILE="$WORK_DIR/$SH_NAME.log"
umask 0

# Required login for installation 
#	none = doesn't matter who it is, otherwise put login name here
REQ_LOGIN="${REQ_LOGIN:-root}"

# login of installer
INSTALLER=`whoami`

#####################################################
#####  installation location variables ##############
#####################################################

#
# all external files are accessed via these definitions.
# if you have a non-standard system, you can control what files
# get accessed here...
#

#
# MAIN -- the directly addressable directory (/usr/pctool).
# 	it contains links to all the other directories, and is the only
#	path that the pctool program knows about.  This directory contains
#	nothing but links.  The pctool program uses $PCTOOLDIR to override
#	its default of "/usr/pctool".
#
#	MAIN is architecture specific, but cpu independent (read only)
#
# VAR -- cpu specific files: contains those files that need to be written
#	by the pctool program
#
# SHARE -- architecture and cpu independent files that are read only and
#	shareable among all IPC users.
#
# USRBIN -- the directory that is in user's search paths
#

MAIN="${PCTOOLDIR:-/usr/pctool}"
SHARE="${PCTOOLSHARE:-/usr/share/pctool}"
VAR="${PCTOOLVAR:-/var/pctool}"
USRBIN="/usr/bin"

#
# you probably don't want to touch these
#

#ETC="${ETC:-/etc}"
#DEV="${DEV:-/dev}"
ETC="/etc"
DEV="/dev"


#
# you almost certainly don't want to touch these
#

ARCH=`arch`
ARCH_K=`arch -k`
INETDCONF="${ETC}/inetd.conf"
SERVICES="${ETC}/services"
RPC="${ETC}/rpc"
RCLOCAL="${ETC}/rc.local"
#
# we set MAIN_ETC after we set MAIN
#MAIN_ETC="${MAIN}/etc"
#PCSERVER="${MAIN_ETC}/pcserver"
#PCNFSD="${MAIN_ETC}/rpc.pcnfsd"

CEXT="PreIPC"
DEFAULTSYS="/usr/share/sys"

#
# set TEST to "echo" when experimenting with changes; this avoids
# most "dangerous" actions
#

DEBUG="${DEBUG:+debug}"
if [ "$DEBUG" ]
then
    TEST="echo  'running'"
    INPUTFROM="; sed 's/^/  <<- /'"
else
    TEST=""
    INPUTFROM=""
fi

#################################################################
# These variables control what will be installed.  Set them to
# to avoid being questioned about them
#################################################################

#
# the numbers of the ipc board(s).  comes from the set { 0 1 2 3 }
#
NUMIPC=""

#
# do you want the pc-nfs configured in [yes|no]?
#
USEPCNFS=""

#
# do you want the remote server for pctool (pcserver) installed [yes|no]?
#
USESERVER=""

#
# We decide if you are running the yellow pages by running domainname.
# If it returns "noname" then your are not running it; anything else
# means you are.  Set USINGYP to yes or no if this doesn't work on
# your system.
#
USINGYP=""

#
# should the kernel be changed?  If so, set INSTALLKERNEL to yes.
# SYS is the name of the top of the kernel heirarchy [$DEFAULTSYS].
# KERNEL is the name of the base kernel config file that will will
# modify [GENERIC is a good choice, or the one specific to your hardware].
# NEWKERNEL is name of the new kernel, after modification [${KERNEL}_IPC].
# OVERWRITEKERNEL is used to decide whether it is OK to overwrite NEWKERNEL
# if it already exists [yes|no].
#
INSTALLKERNEL=""
SYS=""
KERNEL=""
NEWKERNEL=""
OVERWRITEKERNEL=""




###################################
# Function for getting user input #
###################################

# read a line from the user.  $1 should be a shell variable name
stdin_log () {
    read $1

    if [ "$LOGFILE" -a -f "$LOGFILE" ]
    then
	eval echo "\$$1" >> "$LOGFILE"
    fi
}

# return "yes" or "no" into shell variable named $1.  $2 is the user prompt.
get_yesno () {
    yesno=""
    while [ ! "$yesno" ]
    do
	echo ""
	echo -n "$2 [yes|no]? "
	stdin_log yesno
	case "$yesno" in
	[yY]*)	yesno=yes ;;
	[nN]*)	yesno=no ;;
	*)	echo "" ; echo 'Please enter "yes" or "no".' ; yesno="" ;;
	esac
    done
    eval $1="$yesno"
}

# return "yes" or "no" into shell variable named $1.  $2 is the user prompt.
# $3 is the default answer to use
get_yesno_def () {
    yesno=""
    while [ ! "$yesno" ]
    do
	echo ""
	echo -n "$2 [yes|no]($3)? "
	stdin_log yesno
	case "$yesno" in
	[yY]*)	yesno=yes ;;
	[nN]*)	yesno=no ;;
	"")	yesno="$3" ;;
	*)	echo "" ; echo 'Please enter "yes" or "no".' ; yesno="" ;;
	esac
    done
    eval $1="$yesno"
}

# return new path name in shell variable named $1. $2 is the prompt.
# blank line means don't change $1.
get_path () {
    eval newpath="\$$1"
    echo ""
    echo -n "$2 ($newpath): "
    stdin_log newpath
    if [ "$newpath" ]
    then
	eval $1="$newpath"
    fi
}


#
# for debugging support: appendto <file> <text>
#
appendto () {
    if [ "$DEBUG" ]
    then
	echo appendto ">>" "$1" "$2"
    else
	echo >> "$1" "$2"
    fi
}

#
# for debugging support: redir <file>
#
redir () {
    if [ "$DEBUG" ]
    then
	sed "s,^,<appending to $1>:, "
    else
	cat >> "$1"
    fi
}

##############################################
# THIS IS THE START OF THE INSTALLATION CODE #
##############################################

#
#check for correct login for installation
#
case "$REQ_LOGIN" in
    "$INSTALLER" | none)
	;;
    *)  echo
        echo \
	 "$SH_NAME : Incorrect login for installation, you must be $REQ_LOGIN"
        exit 1
        ;;
esac

##########################################
# check to make sure that SHARE is there #
##########################################

while [ ! -d "$SHARE" ]
do
    echo ""
    echo "$SH_NAME: can't find your SunIPC shared data directory (current"
    echo "path name: $SHARE).  This directory is required"
    echo "to complete the configuration of the SunIPC."
    echo ""
    echo "The shared data directory holds the information that was read"
    echo "in from the release tape."

    get_yesno answer "Would you like to change to a different directory"
    if [ "$answer" = "no" ]
    then
	echo "$SH_NAME: exiting because shared data directory not found..."
	exit 1
    fi

    get_path SHARE "Enter the new SunIPC shared data directory"
done

echo "Using \"$SHARE\" as the SunIPC shared data directory..."


###################################
# Now deal with the VAR directory #
###################################

answer="$PCTOOLVAR"
while [ ! "$answer" -o ! -d "$VAR" ] 
do
    echo ""
    echo "The current cpu specific data directory is \"$VAR\"."
    echo "This directory holds those data files that are unique"
    echo "to your SunIPC boards."

    get_yesno_def answer "Would you like to change this path" no

    if [ "$answer" = yes ]
    then
	get_path VAR "Enter the new SunIPC cpu specific directory"
    fi

    if [ ! -d "$VAR" ]
    then
	echo ""
	echo "The directory \"$VAR\" does not exist."
	get_yesno_def answer "Would you like to create \"$VAR\"" yes

	if [ "$answer" = yes ]
	then
	    ${TEST} mkdir -p "$VAR"
	    if [ "$?" -ne 0 ]
	    then
		echo ""
		echo "$SH_NAME: error creating directory \"$VAR\""
		exit 1
	    fi
	fi
    fi
done

echo "Using \"$VAR\" as the SunIPC cpu specific data directory..."

################
# Now for MAIN #
################

answer="$PCTOOLDIR"
while [ ! "$answer" -o ! -d "$MAIN" ] 
do
    echo ""
    echo "The current main pctool directory is \"$MAIN\"."
    echo "This directory is the top level directory used by pctool."

    get_yesno_def answer "Would you like to change this path" no

    if [ "$answer" = yes ]
    then
	get_path MAIN "Enter the new SunIPC main directory"
    fi

    if [ ! -d "$MAIN" ]
    then
	echo ""
	echo "The directory \"$MAIN\" does not exist."
	get_yesno_def answer "Would you like to create \"$MAIN\"" yes

	if [ "$answer" = yes ]
	then
	    ${TEST} mkdir -p "$MAIN"
	    if [ "$?" -ne 0 ]
	    then
		echo ""
		echo "$SH_NAME: error creating directory \"$MAIN\""
		exit 1
	    fi
	fi
    fi
done

echo "Using \"$MAIN\" as the SunIPC main directory..."

#
# go set the MAIN relative variables
#
MAIN_ETC="${MAIN}/etc"
PCSERVER="${MAIN_ETC}/pcserver"
PCNFSD="${MAIN_ETC}/rpc.pcnfsd"

#########################################
# figure out how many ipc boards he has #
#########################################

#
# ZZZ: change loop to enforce only 0-3 (right now we only check the first char)
#

#   This one will loop until a correct device is chosen.
while [ "$NUMIPC" = "" ] 
do
    echo ""
    echo -n \
	"Enter ipc board number(s) to install [0 | 1 | 2 | 3 | ALL | NONE]: "
    stdin_log answer

    badanswer=""

    if [ "$answer" = all -o "$answer" = ALL ]
    then
	NUMIPC="0 1 2 3"
    elif [ "$answer" = none -o "$answer" = NONE ]
    then
	NUMIPC="none"
    else
	# make sure the ipc numbers are legal
	for i in $answer
	do
	    case "$i" in
	    0|1|2|3)	NUMIPC="$NUMIPC $i" ;;
	    *)		badanswer="${badanswer:-$i}" ;;
	    esac
	done
    fi

    # if it was illegal, make the user try again
    if [ "$badanswer" ]
    then
	echo "'$badanswer' is not a legal SunIPC number"
	echo "Please enter a legal number (0 through 3 or ALL)"
	NUMIPC=""
    fi
done

# handle the "none" placeholder
if [ "$NUMIPC" = none ]
then
    NUMIPC=""
fi

#
# figure out if he wants to use PCNFS
#
# if the nfs directory does not exists, assume that he
# does not want it configured
#

if [ -d "${MAIN}/nfs" -o -h "${MAIN}/nfs" -o -d "${SHARE}/nfs" ]
then
    if [ ! "$USEPCNFS" ]
    then
	get_yesno_def USEPCNFS \
	    "Do you want to configure the PC-NFS software" yes
    fi
fi


#
# figure out if he wants to use the server software
#

#   This one will loop until a correct device is chosen.
if [ ! "$USESERVER" ] 
then
    get_yesno_def USESERVER \
	"Do you want to install the server to allow remote IPC access" yes
fi

#
# ask him where his kernel is, and whether he wants us to install
# our stuff in it
#

if [ "$INSTALLKERNEL" = "" ] 
then
    get_yesno INSTALLKERNEL "Do you want the IPC kernel files installed"
fi

if [ "$INSTALLKERNEL" = "yes" ]
then
    if [ ! "$SYS" ]
    then
	echo ""
	echo "You will be asked for the top level directory of your kernel"
	echo "build tree.  This directory needs to contain all the normal"
	echo "kernel subdirectories (such as sun, sundev, net, $ARCH_K, etc)."
	echo ""
	echo "Do NOT enter the path to your 'conf' sub-directory, or to"
	echo "a pre-build kernel object directory!"
    fi

    while [ ! "$SYS" ]
    do
	SYS="$DEFAULTSYS"
	get_path SYS "What is the directory where your kernel lives"
	
	if [ ! -d "$SYS/" ]
	then
	    echo ""
	    echo "Can't find directory $SYS.  Please retry"
	    SYS=""
	else
	    if [ ! -d "$SYS/$ARCH_K/conf" ]
	    then
		echo ""
		echo "Can't find $SYS/$ARCH_K/conf.  Is $SYS the top"
		echo "of a kernel directory tree?"
		echo ""
		echo "Please enter another directory"

		SYS=""
	    fi
	fi
    done

    while [ "$KERNEL" = "" ]
    do
	echo ""
	# this makes some assumptions about what's a kernel...
	echo "You have the following kernel configurations available:"
	( cd "$SYS/$ARCH_K/conf" ; grep -l "^machine" * )
	echo ""
	echo -n "What is the name of the base kernel to add the IPC to? "
	stdin_log KERNEL

	if [ ! -f $SYS/$ARCH_K/conf/$KERNEL ]
	then
	    echo "I can't find the configuration file $SYS/$ARCH_K/conf/$KERNEL"
	    echo "please try again."
	    KERNEL=""
	fi
    done

    if [ ! "$NEWKERNEL" ]
    then
	NEWKERNEL="${KERNEL}_IPC"
    fi

    while [ -f "$SYS/$ARCH_K/conf/$NEWKERNEL" -a "$OVERWRITEKERNEL" != "yes" ] 
    do
	echo "The kernel configuration file $NEWKERNEL already exists."
	get_yesno_def OVERWRITEKERNEL "Is it OK to overwrite it" yes

	if [ "$OVERWRITEKERNEL" = no ]
	then
	    # try and find a new kernel name
	    NEWKERNEL="IPC.$$"
	    get_path NEWKERNEL "Please enter the new kernel name to use"
	fi
    done

    echo "The kernel with the IPC configured in will be called $NEWKERNEL..."

fi


######################################################################
#
# we are done asking questions. on with the show
#
######################################################################



# now make the proper entries from MAIN to SHARE
for file in files msdos sysex pcfont.b.14 pcfont.r.14 rom_bios.pc
do
    # link it in if its in share
    if [ ! -f ${MAIN}/$file -a ! -h ${MAIN}/$file -a ! -d ${MAIN}/$file ]
    then
	# don't create a link unless the target is there
	if [ -d ${SHARE}/$file -o -f ${SHARE}/$file -o -h ${SHARE}/$file ]
	then
	    echo "creating a link for ${MAIN}/$file..."
	    ${TEST} ln -s "${SHARE}/$file" "${MAIN}/$file"
	fi
    else
	echo "${MAIN}/$file already exists..."
    fi
done


# do the architecture dependent ones
for file in etc bin
do
    # link it in if its in share
    if [ ! -d ${MAIN}/$file -a ! -h ${MAIN}/$file ]
    then
	# don't create a link unless the target is there
	if [ -d ${SHARE}/${ARCH}/$file -o -h ${SHARE}/${ARCH}/$file ]
	then
	    echo "creating a link for ${MAIN}/$file..."
	    ${TEST} ln -s "${SHARE}/${ARCH}/$file" "${MAIN}/$file"
	fi
    else
	echo "${MAIN}/$file already exists..."
    fi
done

# set up the links from /usr/bin
for file in pctool psfx80 dos2unix unix2dos
do
    if [ ! -h ${USRBIN}/$file -a ! -f ${USRBIN}/$file ]
    then
	# don't create a link unless the target is there
	if [ -f ${MAIN}/bin/$file -o -h ${MAIN}/bin/$file ]
	then
	    echo "creating a link for ${USRBIN}/$file..."
	    ${TEST} ln -s ${MAIN}/bin/$file ${USRBIN}/$file
	fi
    else
	echo "${USRBIN}/$file already exists..."
    fi
done


#
# clone the cmos_ram, setup, and drive_c files.
#

for unit in $NUMIPC ;
do
    for file in cmos_ram.pc drive_C.pc config.pc ;
    do
	# see if we need to create the file
	if [ -f ${VAR}/$file$unit ]
	then
	    echo "${VAR}/$file$unit already exists..."
	else
	    echo "creating the file  ${VAR}/$file$unit..."
	    ${TEST} cp ${MAIN}/files/$file ${VAR}/$file$unit
	    ${TEST} chmod 666 ${VAR}/$file$unit
	fi

	# see if we need to create a link also
	if [ ! -h ${MAIN}/$file$unit -a ! -f ${MAIN}/$file$unit ]
	then
	    echo "creating a link for ${MAIN}/$file$unit..."
	    ${TEST} ln -s ${VAR}/$file$unit ${MAIN}/$file$unit
	fi
    done
done



#
# figure out if we are running YP
#

DOMAINNAME=`domainname`
domainstat="$?"
if [ ! "$USINGYP" ]
then
    if [ "$domainstat" -ne 0 -o ! "$DOMAINNAME" -o "$DOMAINNAME" = "noname" ]
    then
	USINGYP="no"
	echo "You are not running the yellow pages..."
    else
	USINGYP="yes"
	echo "You are in the yellow pages domain <$DOMAINNAME>..."
    fi
fi


#
# make pc[0-3]
#

echo ""
for ipcnum in $NUMIPC ;
do
    if [ -f "$DEV/pc$ipcnum" ]
    then
	echo "pc$ipcnum already exists..."
    else
	echo "making $DEV/pc$ipcnum..."
	( cd $DEV ; ${TEST} ./MAKEDEV pc$ipcnum )
    fi
done

#
# update /etc/inetd.conf: we're looking for pcserver and pcnfsd
#

if [ "$USESERVER" = yes ]
then
    # first add it to the inetd.conf file
    echo ""
    result=`grep "^pcserver[ 	]" $INETDCONF`
    if [ "$result" ]
    then
	echo "pcserver is already in your $INETDCONF file..."
    else
	echo "adding pcserver to your $INETDCONF..."
	appendto "$INETDCONF" \
	    "# program to allow remote access to the IPC board"
	appendto "$INETDCONF" \
	    "pcserver stream tcp nowait root $PCSERVER pcserver"
    fi

    # now update /etc/services. be carefull about the yellow pages
    if [ "$USINGYP" = "yes" ]
    then
	# see if it is already registered
	result=`ypcat services | grep "^pcserver\>"`
	if [ "$result" ]
	then
	    echo "pcserver is already registered with your yp server..."
	else
	    echo
echo "WARNING: The pcserver protocol (600/tcp) is NOT registered with your"
echo "WARNING: Yellow Pages directory.  Before you can use the remote access"
echo "WARNING: feature of the pctool program, you MUST register the pcserver."
	    echo
	fi
    else
	# see if it is in /etc/services
	result=`grep "^pcserver\>" $SERVICES`
	if [ "$result" ]
	then
	    echo "pcserver is already in your /etc/services file..."
	else
	    echo "adding pcserver to your $SERVICES file..."
	    appendto "$SERVICES" \
		"pcserver	600/tcp		# IPC remote server program"
	fi
    fi
fi

echo ""
if [ "$USEPCNFS" = yes ]
then
    echo "Installing all the PC-NFS stuff in your system..."
    echo ""

    if [ -d ${SHARE}/nfs/ ]
    then
	if [ ! -d ${MAIN}/nfs/ ]
	then
	    echo "creating the ${MAIN}/nfs directory..."
	    ${TEST} mkdir ${MAIN}/nfs
	    if [ "$?" -ne 0 ]
	    then
		echo ""
		echo "$SH_NAME: error creating directory \"$VAR\""
		exit 1
	    fi
	fi

	# now create all the entries in nfs.  we have to do through this
	# garbage because some of the files in nfs must be writable, so we
	# can't just link into the SHARE directory

	for file in ${SHARE}/nfs/*
	do
	    base=`basename $file`

	    if [ ! -h ${MAIN}/nfs/$base -a ! -f ${MAIN}/nfs/$base ]
	    then
		# we must create the link: test for the writable files
		case $base in
		drives.bat|ethers|hosts|netgroup|\
		networks|passwd|protos|\
		rpc|services|respool.db)
		    # create the var directory if needed
		    if [ ! -d ${VAR}/nfs ]
		    then
			echo "creating the ${VAR}/nfs directory..."
			${TEST} mkdir ${VAR}/nfs
			if [ "$?" -ne 0 ]
			then
			    echo ""
			    echo "$SH_NAME: error creating directory \"$VAR\""
			    exit 1
			fi
		    fi
		    # link the file into the share directory
		    echo "creating a link for ${MAIN}/nfs/$base..."
		    ${TEST} ln -s ${VAR}/nfs/$base ${MAIN}/nfs/$base
		    echo "initializing ${VAR}/nfs/$base..."
		    ${TEST} cp ${SHARE}/nfs/$base ${VAR}/nfs/$base
		    ;;

		network.bat)

		    echo "creating a link for ${MAIN}/nfs/$base..."
		    ${TEST} ln -s ${VAR}/nfs/$base ${MAIN}/nfs/$base

		    if [ "$USINGYP" = "yes" ]
		    then
			echo "initializing your $MAIN/nfs/network.bat..."

			YPDOMAIN=`domainname`
			SUBNET=`${MAIN_ETC}/mynetmask | sed "s/ .*//"`
			sed -e "s/your-domainname-here/$YPDOMAIN/" \
			    -e "s/your-subnet-here/$SUBNET/" \
			    "${SHARE}/nfs/network.bat" | \
			    redir "${VAR}/nfs/network.bat"
		    else
			echo ""
	echo "You are not using the yellow pages.  You must configure"
	echo "The $MAIN/nfs/network.bat file by hand.  See the PC-NFS"
	echo "manual for more instructions"
			echo ""

			${TEST} cp ${SHARE}/nfs/$base ${VAR}/nfs/$base
		    fi

		    ;;


		*)
		    # link the file into the share directory
		    echo "creating a link for ${MAIN}/nfs/$base..."
		    ${TEST} ln -s ${SHARE}/nfs/$base ${MAIN}/nfs/$base
		    ;;
		esac
	    fi
	done
    fi

    pcnfsd=`grep "^pcnfsd/1" $INETDCONF`
    pcnumber=`grep "^150001/1" $INETDCONF`
    if [ "$pcnfsd" -o "$pcnumber" ]
    then
	echo "pcnfsd is already in your $INETDCONF file..."
    else
	usenum="no"
	if [ "$USINGYP" = yes ]
	then
	    # see if pcnfsd is in the rpc yp map
	    ypnum=`ypcat rpc.bynumber | grep "^pcnfsd\>" `
	    if [ ! "$ypnum" ]
	    then
		echo ""
		usenum=yes
		echo "You do not have pcnfsd in your YP RPC database."
		echo "You should get your yp administrator to add the"
		echo "following line to the rpc.bynumber yp database:"
		echo ""
		echo "pcnfsd	150001"
		echo ""
	    fi
	else
	    # see if pcnfsd is in his /etc/rpc
	    if grep -s -w "pcnfsd" $RPC
	    then
		echo "pcnfsd is already in your $RPC file..."
	    else
		echo "adding pcnfsd to $RPC..."
		appendto $RCP "pcnfsd	150001"
	    fi
	fi
	if [ "$usenum" = no ]
	then
	    # he has pcnfsd in the rpc data base
	    echo "adding pcnfsd to $INETDCONF..."
	    appendto "$INETDCONF" \
		"# program to allow PC-NFS authentication and print spooling"
	    appendto "$INETDCONF" \
		"pcnfsd/1 dgram rpc/udp wait root $PCNFSD rpc.pcnfsd"
	else
	    # he doesn't have pcnfsd in the rpc data base
	    echo "adding pcnfsd as 150001 to $INETDCONF..."
	    appendto "$INETDCONF" \
		"#"
	    appendto "$INETDCONF" \
		"# pcnfsd was not in the rpc database.  Once it is"
	    appendto "$INETDCONF" \
		"# added, uncomment the "pcnfsd" line, and remove"
	    appendto "$INETDCONF" \
		"# the line that starts with "150001"."
	    appendto "$INETDCONF" \
		"#"
	    appendto "$INETDCONF" \
		"#pcnfsd/1 dgram rpc/udp wait root $PCNFSD rpc.pcnfsd"
	    appendto "$INETDCONF" \
		"150001/1 dgram rpc/udp wait root $PCNFSD rpc.pcnfsd"
	fi
    fi

    #
    # change startup sequence to init pcnfs
    #

    for unit in $NUMIPC ;
    do
	if grep -s "ifconfig pc$unit" $RCLOCAL ;
	then
	    echo "IPC $unit already installed in $RCLOCAL..."
	else
	    # ZZZ: can't use ${TEST} here... sigh.
	    echo "installing pc$unit in $RCLOCAL..."
	    appendto $RCLOCAL ""
	    appendto $RCLOCAL "if [ -c /dev/pc$unit ]; then"
	    appendto $RCLOCAL \
    "	ifconfig pc$unit `hostname` `hostname`-ipc$unit netmask + private"
	    appendto $RCLOCAL \
		"	arp -s `hostname`-ipc$unit `$MAIN_ETC/myeaddr` pub"
	    appendto $RCLOCAL \
		"	(echo 'ipc unit $unit initialized') > /dev/console"
	    appendto $RCLOCAL "fi"
	fi
    done

    echo ""

fi


#
# POST_NFS
#

#
# now deal with the kernel
#

if [ "$INSTALLKERNEL" = "yes" ]
then
    #
    # we need to copy the files into the kernel area
    #

    echo ""
    echo "installing your the ipc drivers into your kernel (at $SYS)..."

    if [ -d $SYS/$ARCH_K/OBJ ]
    then
	for file in if_me.o pc.o pc_conf.o ;
	do
	    if [ -f $SYS/$ARCH_K/OBJ/$file ]
	    then
		echo "$SYS/$ARCH_K/OBJ/$file already exists..."
	    else
		echo "installing $file in $SYS/$ARCH_K/OBJ..."
		${TEST} cp ${MAIN_ETC}/$file $SYS/$ARCH_K/OBJ/$file
	    fi
	done
	objs_ok=yes
    else
	echo
	echo "WARNING: YOU DON'T HAVE A $SYS/$ARCH_K/OBJ DIRECTORY!"
	echo "WARNING: can't install your kernel object files"
	echo
	objs_ok=no
    fi

    #
    # we need to update his config file
    #

    if [ "$objs_ok" = yes ]
    then
	echo "making $SYS/$ARCH_K/conf/$NEWKERNEL..."
	${TEST} cp "$SYS/$ARCH_K/conf/$KERNEL" "$SYS/$ARCH_K/conf/$NEWKERNEL"
	${TEST} chmod +w "$SYS/$ARCH_K/conf/$NEWKERNEL"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "#"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "# automatically added config lines for Sun Integrated PC (IPC)"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "#"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "device pc0 at vme24d16 ? csr 0x380000 priority 2 vector pcintr 0xa4"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "device pc1 at vme24d16 ? csr 0x3a0000 priority 2 vector pcintr 0xa5"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "device pc2 at vme24d16 ? csr 0x3c0000 priority 2 vector pcintr 0xa6"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  "device pc3 at vme24d16 ? csr 0x3e0000 priority 2 vector pcintr 0xa7"
	appendto "$SYS/$ARCH_K/conf/$NEWKERNEL" \
	  ""

	#
	# we need to run config on it
	#

	echo "running config on $NEWKERNEL (this takes a few minutes)..."
	( cd "$SYS/$ARCH_K/conf" ; ${TEST} config "$NEWKERNEL" )

	#
	# make the kernel
	#

	echo "making your kernel (this takes a few minutes too)..."
	( cd "$SYS/$ARCH_K/$NEWKERNEL" ; ${TEST} make )

	#
	# tell him to backup the old kernel, copy the new one in, and reboot
	#

	echo ""
	echo "You should back up your original kernel (/vmunix), copy your"
	echo "new kernel ($SYS/$ARCH_K/$NEWKERNEL/vmunix) to the root,"
	echo "and reboot your machine"
	echo
    fi
fi


