#!/bin/csh -f
# @(#)4410_install	30.1 3/13/91 AppEng/SCCS Interphase
#
#
# Interphase Corporation Northern CA. Standards for Coding based on
# DOD-STD-2167A ( Draft )
#
# ABSTRACT :  4410_install
#	C shell script that installs Interphase device driver support
#	for Sun OS3.4, OS3.5 , OS3.2, OS4.0, OS4.0.1, OS4.0.3, & OS4.1

# KEYWORDS : 4410_install
#

# CONTENTS 
#
#                  Ident        Date            Author
# -------------------------------------------------------------------------
# Designed By :    X01.00	2-Feb-89	Robert Hogue from the IPLOAD
#						program by Dan Nindorf and
#						William Perry
# Coded By  : Robert Hogue (rogue)
# Tested By : rogue (Sun3 OS3.5 and 4.0 and Sun4 OS4.0 only)
#             modifications for Sun OS3.2 done without testing locally

# Revision History :
#
# Rev#  Date     Author   Change
#--------------------------------------------------------------------------
# 30.1  03/13/91 rbrant   New development/distribution format.

# Examples of Usage : 4410_install
#

# Parameter Description : no parameters passed in the command line.  Program
#	queries for system parameters.

# Special Design Considerations : requires 'plain vanilla' system with local
#	disk drive.  Local disk must have 'kernel build' files in the
#	appropriate Sun directories.

# External Units Accessed :  ( Called, Imported, Copied, WITHed, referenced )
#
#   System Files modified :
#
#	$SYSDIR/sun/conf.c
#	$CONF/devices (devices.sunX)
#	$CONF/files (files.sunX)
#	/etc/fstab (emulation mode installation only)
#
#     Unit Name                        Purpose
#-------------------------------------------------------------------------
#
#  MAKEDEV.src		source of MAKEDEV.4410 file (the /dev creation utility)
#  REMOVEDEV		the /dev entry removal utility
#  awkfiles/		all units this directory (awk files for "fix..")
#  closingnotes.$NAME  	text file is output upon completion of 4410_install
#  config.appendum.$NAME text file appended to the configuration file
#  cycle		log file
#  drivers/		all units this directory (device driver sources)
#  fix/			all units this directory (input files for "fix..")
#  fixdevices		fixes the devices.(sun3/sun4) file
#  fixfstab		fixes the 'fstab' file when using XY emulation
#  fixswap		fixes the swapgeneric.c file
#  warning		log file

# Exceptions and the Conditions which will raise them :
#     exceptions (warnings) are logged to the 'warning' file
#
#     non-existent system directories cause fatal errors and immediate exit
#     failed compilations cause exceptions
#

# Input / Output : ( Files, Keyboards, Consoles, printers, modems, etc. )
#
#     Device name    Access type      Purpose      Summary
#------------------------------------------------------------------------
#

# Machine Dependencies : ( registers, storage, ports, machine code, etc. )
#
# Access type      Purpose                        Justification
#-----------------------------------------------------------------------

# Program Notes :
#
# For the purposes of this shell script the terms :
# 	non-bootable and non-bootable kernel mean a kernel which recognizes
#		the Interphase controller at their standard addresses
#               and any Xylogics controllers at the standard Sun addresses.
#	bootable and bootable kernel mean a kernel which recognizes the
#		Interphase 4200 & 4201 controllers at address 0xee00
#              	and any Xylogics controllers at alternate 0x70?? addresses.
#            OR Interphase 4410 controller at 0x8800 emulating si0 with
#               all Sun SCSI support commented out.
#            OR Interphase 4410 controller at 0x8800 emulating xy0 and si0 with
#               all Sun SCSI support and Sun 'xy0' support commented out.
#       emulation means that you are booted off an Interphase controller that
#               is currently emulating a Sun supplied boot device.  Selecting
#               EMULATION support will modify the /etc/fstab file and cause
#               IPinstall to create a bootable kernel.
#
# Installation #1 :
#     Where the Interphase Controller is the only bootable device
#                   (1) enable any boot hardware on the board (4400, 4410)
#		    (2) install Interphase board at 0x8800 (4410)
#                   (3) install the drive
#		    (4) install the Sun software (format, suninstall)
#		    (5) install this software and select emulation mode support
#
# Installation #2 :
#     Where the System is bootable without the Interphase controller (easiest)
#		    (1) install the Interphase board at the default address 
#                       (see closingnotes for default addresses)
#		    (2) install the Interphase software
#		    (3) build both kernels and boot the non-bootable (IP) kernel
#                       Do not select Emulation mode support (changes fstab).
#		    (4) run interphase "ipdiag" program to format, partition...
#		    (4) run interphase "vjutil" program to format, partition...
#		    (5) use the newfilesystemIP utility to create filesystems
#		    (6) use the dumpIP utility to dump the system disk to the 
#			    interphase (ip or vj) disk.
#		    (7) use the bootcopyIP utility to install the boot blocks
#		    (8) reinstall the Interphase board as bootable controller
#		    (9) readdress any Sun SCSI boards out of the address space
#			200000 through 2001ff (4410)
#		    (10) boot the Interphase disk:
#				>b xy()vmunix.BIP

#
# Assumptions :
#   * controllers are either bootable or non-bootable ("add-in")
#   * bootable controllers emulate Sun devices "si" or "xy" or both.
#   * bootable controllers need a iphase bootable kernel.
#   * bootable kernel for the 4410 needs all other SCSI device support
#       removed.
#   * boot support is always added to OS4 swapgeneric.c file.
#   * emulation support changes /etc/fstab (slightly dangerous).
#   * emulation support creates only a bootable kernel.
#   * major difference between a bootable and non-bootable kernel is
#       the bootable kernel removes support for certain Sun supplied
#       devices.  Bootable kernel for 4410 has Interphase card at
#       0x8800 (emulates 0xee40 through 0xee47) and all Sun SCSI cards removed.
#       4410 used in emulation mode requires 'xy0' be readdressed
#   * emulation support is only selected if you are CURRENTLY running
#        in emulation mode.  Selecting emulation support if your booted
#        off a Sun device is a very good way to trash the system.
#   * only one Interphase boot device is allowed per kernel.
#        

#
# Deficiencies :
#   * Xylogics emulation device must be 'xy0a'
#   * Sun SCSI emulation device must be 'sd0a'

#*****************************************************************************#
# Strings and Environment defaults                                            #
#*****************************************************************************#
set version = 'Version 30.1'
setenv NEWCONFIGFILE VJ		# the default new configuration file name
set USER_DRIVERS = sundev       # copy interphase drivers to this directory
 
set IPFILES = 'IPtypes.h vj.c vj_reg.h vj_scsi.h vj_struct.h'
 
#################### do not change these flags ################################
set NAME        = '4410'	# interphase directory name for this board
set EMULATION   = false		# flag set for emulation mode,  else clear
set DO_NON_BOOT = false		# flag set for Non-boot kernel build, else clear
set DOBOOT      = false		# flag set for boot kernel build,  else clear
set BOOT4410    = false		# flag set for bootable 4410, else clear
set BOOT441X    = false		# flag set for special bootable 4410, else clear
                                # special 4410 emulates 'xy' and 'st'
set EXCEPTIONS  = false		# flag set if certain errors,  else clear

##############################################################################

source common
 
#*****************************************************************************#
# Check for abort or fatal error retured from 'common'
#*****************************************************************************#
if ( $ABORT_SCRIPT == true ) then
    goto exitinterrupt
else if ( $FATAL_ERROR == true ) then
    goto fatal_error_exit
endif
 
#*****************************************************************************#
# Set the interrupt handler
#*****************************************************************************#
onintr exitinterrupt

#*****************************************************************************#
#                        Using Emulation Mode ?                               #
#*****************************************************************************#
# assumes emulation kernel is bootable AND that the bootable device is
# a 4410 controller.  All 44xx series controllers are
# assumed to have boot emulation HARDWARE and that that hardware is ENABLED.
# Sun 4/3xx (330,370,390) and all other Sun computers with on-board SCSI 
# require a special version of the 4410 that emulates 'xy' and 'st'.  The
# normal 4410 emulates 'si' and 'st'.  Special 4410's have different hardware
# and jumper configurations.  See Interphase Customer Support for details.

Do_emulation:

echo ""
echo "Are you CURRENTLY in Sun emulation mode?"
echo ""
echo "You are in emulation mode if you are doing a first time"
echo "installation from Sun tape AND you are CURRENTLY booted off"
echo "the Interphase disk controller.  Emulation mode support assumes"
echo "the Interphase controller will be your standard boot device."
echo ""
echo "WARNING : do not select emulation mode support if you are"
echo "currently booted off a Sun supplied device.  Selecting"
echo "emulation support will alter your 'etc/fstab' file by substituting"
echo "Interphase device names for Sun device names.  Make sure to check"
echo "'/etc/fstab' before booting any new vmunix kernel."
echo "If you intend to boot in the future build a bootable kernel"
echo "by answering the appropriate questions that follow later in this"
echo "program."
echo ""
echo "          Default : yes.. using Sun Emulation mode"
echo ""
echo -n "Currently using Sun Emulation mode (y/n) "
set ans = $<
if ( $ans =~ "no"||$ans =~ "No"||$ans =~ "NO"||$ans =~ "n"||$ans =~ "N" ) then
    echo ""
    echo "Not using Sun Emulation mode."
    set BOOT4410  = false
    set BOOT441X  = false
    set DOBOOT    = false		# no bootable kernel built
    set EMULATION = false		# no emulation modifications
else
    echo ""
    echo "Support for Sun Emulation mode selected"
    echo ""
    echo "Creating only the bootable kernel"
    set DOBOOT = true	    # bootable kernel built
    set EMULATION = true        # do emulation modifications
endif

if ( $EMULATION == true ) then

    Which_emulation:

    # initialize the flags to allow for reentry
    set BOOT4410  = false
    set BOOT441X  = false
    set EMULATION = true
    set DOBOOT    = true

    echo ""
    echo "Install Sun emulation mode support.."
    echo "    Choices :"
    echo "              1   for 4410 Jaguar SCSI Controller emulating 'si'(standard)"
    echo "              2   for 4410 Jaguar SCSI Controller emulating 'xy'(special)"
    echo "              3   Cancel Emulation support and continue the program"
    echo "              4   Return to previous question"
    echo "              5   Exit this program"
    echo ""
    echo "          Default : 1"
    echo ""
    echo -n "$prompt "
    set ans = $<
    if ( $ans =~ "" ) then
	set ans = "1"
    endif
    switch ( $ans )
        case "1"
                echo ""
                echo "Emulation for Jaguar 4410 SCSI selected"
                set BOOT4410 = true
		breaksw
        case "2"
                echo ""
                echo "Emulation for Special Jaguar 4410 SCSI selected"
                set BOOT441X = true
                breaksw
        case "3"
                echo ""
                echo "Emulation mode support cancelled"
                set EMULATION = false
                set DOBOOT = false
		breaksw
        case "4"
                goto Do_emulation
		breaksw
        case "5"
                goto Normal_exit
		breaksw
        default:
            echo ""
            echo "Sorry but this script does not support '$i'"
            echo "Enter a number between 1 and 5"
            goto Which_emulation
            breaksw
        endsw
endif  #EMULATION

#*****************************************************************************#
# Create both kernels ?                                                       #
#*****************************************************************************#
#
# ask this question only if not currently in emulation mode
 
if ( $EMULATION == false ) then

    Do_both_kernels:

    # init the flags to allow for reentry
    set DOBOOT = false
    set DO_NON_BOOT = false

    echo ""
    echo "You will need a Non-bootable kernel if you intend to use the"
    echo "Interphase controller(s) as an 'add-in' device."
    echo ""
    echo "You will need a bootable kernel if you intend to boot off the"
    echo "Interphase 4410 SCSI controller."
    echo ""
    echo "Make the following vmunix kernels.."
    echo "    Choices :"
    echo "              1   make both the Bootable and Non-bootable kernels"
    echo "              2   make the Non-bootable kernel only"
    echo "              3   make the Bootable kernel only"
    echo "              4   Return to previous question"
    echo "              5   Exit this program"
    echo ""
    echo "          Default : 1"
    echo ""
    echo -n "$prompt "
    set ans = $<
    if ( $ans =~ "" ) then
	set ans = "1"
    endif
    switch ( $ans )
        case "1"
                echo ""
                echo "Create Bootable and Non-bootable kernels"
                set DO_NON_BOOT = true
                set DOBOOT = true
		breaksw
        case "2"
                echo ""
                echo "Create Non-bootable kernel"
                set DO_NON_BOOT = true
                set DOBOOT = false
		breaksw
        case "3"
                echo ""
                echo "Create Bootable kernel"
                set DO_NON_BOOT = false
                set DOBOOT = true
		breaksw
        case "4"
                goto Do_emulation
		breaksw
        case "5"
                goto Normal_exit
		breaksw
        default:
            echo ""
            echo "Sorry but this script does not support '$i'"
            echo "Enter a value between 1 and 5"
            goto Do_both_kernels
            breaksw
    endsw
else
#    echo ""
#    echo "Create Non-bootable kernel"
    set DO_NON_BOOT = false
endif  #EMULATION == false

cd $OURDIR

#*****************************************************************************#
# If creating a bootable kernel.. boot support for which controller?          #
#*****************************************************************************#
# you only need to ask this question if emulation mode has not
# been previously selected.  If EMULATION is true a particular controller
# has already been selected for emulation.

if ( $EMULATION == false && $DOBOOT == true ) then

    Which_boot:

    # initialize the flags to allow for reentry
    set BOOT4410  = false
    set BOOT441X  = false
    set EMULATION = false
    set DOBOOT    = true

    echo ""
    echo "Install Sun boot support.."
    echo "    Choices :"
    echo "              1   for 4410 Jaguar SCSI Controller emulating 'si'(standard)"
    echo "              2   for 4410 Jaguar SCSI Controller emulating 'xy'(special)"
    echo "              3   Cancel boot support and continue the program"
    echo "              4   Return to previous question"
    echo "              5   Exit this program"
    echo ""
    echo "          Default : 1"
    echo ""
    echo -n "$prompt "
    set ans = $<
    if ( $ans =~ "" ) then
	set ans = "1"
    endif
    switch ( $ans )
        case "1"
                echo ""
                echo "Boot support for Jaguar 4410 SCSI selected"
                set BOOT4410 = true
		breaksw
        case "2"
                echo ""
                echo "Boot support for Special Jaguar 4410 SCSI selected"
                set BOOT441X = true
                breaksw
        case "3"
                echo ""
                echo "Boot support mode support cancelled"
                set DOBOOT = false
		breaksw
        case "4"
                goto Do_both_kernels
		breaksw
        case "5"
                goto Normal_exit
		breaksw
        default:
            echo ""
            echo "Sorry but this script does not support '$i'"
            echo "Enter a number between 1 and 5"
            goto Which_boot
            breaksw
    endsw
endif  #EMULATION = false && DOBOOT = true

echo "BOOT4410 = "$BOOT4410 >> $DIAGOUTPUT
echo "BOOT441X = "$BOOT441X >> $DIAGOUTPUT
echo "EMULATION = "$EMULATION >> $DIAGOUTPUT
echo "DOBOOT = "$DOBOOT >> $DIAGOUTPUT
echo "DO_NON_BOOT = "$DO_NON_BOOT >> $DIAGOUTPUT

cd $OURDIR

#*****************************************************************************#
# Backing up the user's conf.c file                                           #
#*****************************************************************************#

if ! ( -e $SYSDIR/sun/conf.c.before.IP ) then
    echo ""
    echo "Backing up $SYSDIR/sun/conf.c as $SYSDIR/sun/conf.c.before.IP"
    /bin/cp $SYSDIR/sun/conf.c $SYSDIR/sun/conf.c.before.IP 
endif

#*****************************************************************************#
# Copy the conf.c file to our directory and modify it                         #
#*****************************************************************************#

/bin/cp $SYSDIR/sun/conf.c conf.c
echo ""
echo "Updating the conf.c file for : $NAME "
/bin/chmod u+w conf.c
echo "Start conf.c file updates" >> $DIAGOUTPUT
 
#
# test to see if an entry ( vj ) is present in the cdev table.
# you may not have a block device but you should always have a raw
# device, ie. cdev table(array) entry.
 
set tst = `awk -f $AWKFILES/vjcn.awk conf.c`
 
#
# This path is taken if an entry ( vj ) is present in the cdev
# table.  Otherwise add a new entry to both tables as applicable.
if ( $tst == 127 ) then
 
    #
    # Parse the conf.c file to find out where to add the new lines
    #
    echo -n 's/CLN/' > sed.in
    echo `awk -f $AWKFILES/cln.awk conf.c`/g >> sed.in
    echo -n 's/BLN/' >> sed.in
    echo `awk -f $AWKFILES/bln.awk conf.c`/g >> sed.in
    echo -n 's/HLN/' >> sed.in
    echo `awk -f $AWKFILES/hln.awk conf.c`/g >> sed.in
 
    #
    # add the new lines to the edit input file
    #
    sed -f sed.in $FIXFILES/exconf.vj.$OS > edin.vj
    echo "sed -f sed.in $FIXFILES/exconf.vj.$OS > edin.vj" >> $DIAGOUTPUT
    echo "sed.in follows.." >> $DIAGOUTPUT
    cat sed.in >> $DIAGOUTPUT
    echo "sed.in ends.." >> $DIAGOUTPUT
     
    #
    #  Now actually make the edits to the conf.c file
    #
    echo "ed conf.c < edin.vj" >> $DIAGOUTPUT
    ed conf.c < edin.vj >>& $DIAGOUTPUT
    echo "edin.vj follows.." >> $DIAGOUTPUT
    cat edin.vj >> $DIAGOUTPUT
    echo "edin.vj ends.." >> $DIAGOUTPUT
     
    #
    #  Flush the edit input file
    #
    /bin/rm -f edin.vj
    /bin/rm -f sed.in
 
    # make a 'sed' edit file
    # to correct the 'cdev' and 'bdev' array numbers
    #   example : /*VJCN*/ becomes /*43*/ etc.
    #
    echo -n "" >med.in
    echo -n 's/VJCN/' >> med.in
    echo `awk -f $AWKFILES/vjcn.awk conf.c`/g >> med.in
    echo -n 's/VJBN/' >> med.in
    echo `awk -f $AWKFILES/vjbn.awk conf.c`/g >> med.in
 
    #
    # actually make the 'array number' mods to the file
    #
    /bin/cp conf.c tempfile
    set flag=`cat med.in | wc -l`
    if ( $flag != '0') then
        echo "sed -f med.in tempfile > conf.c" >> $DIAGOUTPUT
        sed -f med.in tempfile > conf.c
        echo "med.in follows.." >> $DIAGOUTPUT
        cat med.in >> $DIAGOUTPUT
        echo "med.in ends.." >> $DIAGOUTPUT
    else
        echo ""
        echo "Edits to conf.c failed"
        echo "Edits to conf.c failed" >> $OURDIR/warning
        echo "Edits to conf.c failed" >> $DIAGOUTPUT
    endif
 
    #
    # Flush the edit files
 
    #
    /bin/rm -f tempfile
    /bin/rm -f med.in
endif

#*****************************************************************************#
# Compare conf.c file before and after mods and set exception if mods failed  #
#*****************************************************************************#

cmp -s conf.c $SYSDIR/sun/conf.c.before.IP
if ! ( $status ) then
    echo ""
    echo "Update of the conf.c file failed"
    echo "Update of the conf.c file failed" >> $OURDIR/warning
    echo "Update of the conf.c file failed" >> $DIAGOUTPUT
    set EXCEPTIONS = true
endif

#*****************************************************************************#
# Now put the new conf.c file back where it belongs                           #
#*****************************************************************************#

/bin/cp conf.c $SYSDIR/sun/conf.c
echo "/bin/cp conf.c $SYSDIR/sun/conf.c" >> $DIAGOUTPUT

#*****************************************************************************#
# Fix devices.sunX (os3.5) or 'devices' (os3.2,4.x)
#*****************************************************************************#

echo "Fix devices start" >> $DIAGOUTPUT

if ( $OS3_2FLAG == true || $OS =~ "os4" ) then
    if ! ( -e $CONF/devices.before.IP ) then
        echo ""
        echo "Backing up $CONF/devices as $CONF/devices.before.IP"
        /bin/cp $CONF/devices $CONF/devices.before.IP
    endif
 
    echo ""
    echo "Updating $CONF/devices"
 
    # add the block major numbers to the 'devices' file.
    # conf.c is scanned for this information.
    #
    fixdevices.4410 $CONF/devices
 
    # make sure the mods to 'devices' worked and set exception if not
    #
    cmp -s $CONF/devices $CONF/devices.before.IP
    if ! ( $status ) then
        echo ""
        echo "Update of the 'devices' file failed"
        echo "Update of the 'devices' file failed" >> $OURDIR/warning
        echo "Update of the 'devices' file failed" >> $DIAGOUTPUT
        set EXCEPTIONS = true
    endif
else
    if ! ( -e $CONF/devices.$SYSTYPE.before.IP ) then
        echo ""
        echo "Backing up $CONF/devices.$SYSTYPE as $CONF/devices.$SYSTYPE.before.IP"
        /bin/cp $CONF/devices.$SYSTYPE $CONF/devices.$SYSTYPE.before.IP
    endif
 
    echo ""
    echo "Updating $CONF/devices.$SYSTYPE"
 
    # add the block major numbers to the 'devices' file.
    # conf.c is scanned for this information.
    #
    fixdevices.4410 $CONF/devices.$SYSTYPE
 
    # make sure the mods to 'devices.sunX' worked and set exception if not
    #
    cmp -s $CONF/devices.$SYSTYPE $CONF/devices.$SYSTYPE.before.IP
    if ! ( $status ) then
        echo ""
        echo "Update of the 'devices.$SYSTYPE' file failed"
        echo "Update of the 'devices.$SYSTYPE' file failed" >> $OURDIR/warning
        echo "Update of the 'devices.$SYSTYPE' file failed" >> $DIAGOUTPUT
        set EXCEPTIONS = true
    endif
 
endif   #os3.2

echo "Done with mods to devices" >> $DIAGOUTPUT

#*****************************************************************************#
# Backup and modify the os4 user's client devices files
#*****************************************************************************#
#  No error checking done during this routine
 
if ( $OS =~ "os4" && $DO_CLIENTS == true ) then
    if ( -d $CLIENTSUN4 && $SYSTYPE !~ "sun4" ) then
        if ! ( -e $CLIENTSUN4/devices.before.IP ) then
            echo ""
            echo "Backing up and Updating $CLIENTSUN4/devices"
            /bin/cp $CLIENTSUN4/devices $CLIENTSUN4/devices.before.IP
        endif
        fixdevices.4410 $CLIENTSUN4/devices
    endif   #CLIENTSUN4
 
    if ( -d $CLIENTSUN3 && $SYSTYPE !~ "sun3" ) then
        if ! ( -e $CLIENTSUN3/devices.before.IP ) then
            echo ""
            echo "Backing up and Updating $CLIENTSUN3/devices"
            /bin/cp $CLIENTSUN3/devices $CLIENTSUN3/devices.before.IP
        endif
        fixdevices.4410 $CLIENTSUN3/devices
    endif   #CLIENTSUN3
 
    if ( -d $CLIENTSUN2 && $SYSTYPE !~ "sun2" ) then
        if ! ( -e $CLIENTSUN2/devices.before.IP ) then
            echo ""
            echo "Backing up and Updating $CLIENTSUN2/devices"
            /bin/cp $CLIENTSUN2/devices $CLIENTSUN2/devices.before.IP
        endif
        fixdevices.4410 $CLIENTSUN2/devices
    endif   #CLIENTSUN2
    echo "Done with client mods to devices" >> $DIAGOUTPUT
endif   #os4.0
 
#*****************************************************************************#
# Now create the Interphase version of the MAKEDEV file  (MAKEDEV.4410)
#*****************************************************************************#

echo ""
echo "Updating the MAKEDEV file for $NAME"
echo "Updating the MAKEDEV file for $NAME" >> $DIAGOUTPUT
echo -n "" >med.in

#
# scan the 'conf.c' file for the position in the 'bdev' and 'cdev' arrays.
# do this procedure for all passed parameters (drivers)
#
echo -n 's/VJCN/' >> med.in
echo `awk -f $AWKFILES/vjcn.awk conf.c`/g >> med.in
echo -n 's/VJBN/' >> med.in
echo `awk -f $AWKFILES/vjbn.awk conf.c`/g >> med.in

#
# edit/create the new MAKEDEV.$NAME file by using the 'awk' file output (med.in)
#
set flag=`cat med.in | wc -l`
if ( $flag != '0') then
    sed -f med.in MAKEDEV.src > MAKEDEV.$NAME
else
    echo ""
    echo "Edits to MAKEDEV.$NAME failed"
    echo "Edits to MAKEDEV.$NAME failed" >> $OURDIR/warning
    echo "Edits to MAKEDEV.$NAME failed" >> $DIAGOUTPUT
endif

/bin/rm -f med.in  # flush the temporary file
 echo "Makedev creation done" >> $DIAGOUTPUT

#*****************************************************************************#
# Copy the special device scripts to /dev                                     #
#*****************************************************************************#

/bin/chmod 755 MAKEDEV.$NAME
/bin/mv MAKEDEV.$NAME /dev/MAKEDEV.$NAME
/bin/cp REMOVEDEV /dev/REMOVEDEV

#*****************************************************************************#
# Now create the vj_major.h header file (required for multi 'vj' controllers) #
#*****************************************************************************#

# create the file
echo "#define VJBLKMAJOR VJBN" > $DRIVERS/vj_major.h
echo "#define VJCHRMAJOR VJCN" >> $DRIVERS/vj_major.h

echo -n "" >med.in
echo ""
echo "Updating the vj_major.h file"
echo "Updating the vj_major.h file" >> $DIAGOUTPUT
echo -n 's/VJCN/' >> med.in
echo `awk -f $AWKFILES/vjcn.awk conf.c`/g >> med.in
echo -n 's/VJBN/' >> med.in
echo `awk -f $AWKFILES/vjbn.awk conf.c`/g >> med.in

#
# create the new vj_major.h file by using the 'awk' file output (med.in)
#
set flag=`cat med.in | wc -l`
if ( $flag != '0') then
    sed -f med.in $DRIVERS/vj_major.h > $SYSDIR/sundev/vj_major.h
else
    echo ""
    echo "Edits to vj_major.h failed"
    echo "Edits to vj_major.h failed" >> $OURDIR/warning
    echo "Edits to vj_major.h failed" >> $DIAGOUTPUT
endif
/bin/rm -f med.in  # flush the temporary file
echo "vj_major.h file creation done" >> $DIAGOUTPUT

#*****************************************************************************#
# Do the config on the new non-bootable configuration file (if necessary)     #
#*****************************************************************************#

# Take this path if the user wants the non-bootable kernel (0x8800 address)
if ( $DO_NON_BOOT == true ) then
   echo ""
   echo "Executing config on the file : $CONF/$NEWCONFIGFILE"
   echo "Executing config on the file : $CONF/$NEWCONFIGFILE" >> $DIAGOUTPUT
   echo ""
   cd $CONF

   /etc/config $NEWCONFIGFILE

   #  Make the new vmunix
   #
   echo ""
   echo "Compiling the non-bootable vmunix kernel"

   cd $UNIX/$NEWCONFIGFILE

   echo ""
   make
   sync;sync

   #**************************************************************************#
   # Copy the new UNIX to the root file system                                #
   #**************************************************************************#
   # poor way to check if the compilation of new kernel successful
     
   if ! ( -e vmunix ) then
       echo ""
       echo "Compilation of the non-bootable kernel failed"
       echo "Compilation of the non-bootable kernel failed" >> $OURDIR/warning
       echo "Compilation of the non-bootable kernel failed" >> $DIAGOUTPUT
       set EXCEPTIONS = true
   else
       echo ""
       echo "Copying Non-bootable vmunix to the root as vmunix.$NEWCONFIGFILE"
       /bin/cp vmunix /vmunix.$NEWCONFIGFILE
   endif
endif	#DO_NON_BOOT

cd $OURDIR

#*****************************************************************************#
# Create and/or Save '/dev' entries                                           #
#                                                                             #
# This routine searches for the "0" order interphase device, ie . rvj0a,      #
#*****************************************************************************#
echo "Starting /dev file mods" >> $DIAGOUTPUT

cd /dev
if ! ( -e /dev/rvj0a ) then
    REMOVEDEV vj0 vj1           #2 disks on bus 1
    REMOVEDEV vt4               #1 tapes on bus 1
    REMOVEDEV vj8 vj9           #2 disks on bus 2
    REMOVEDEV vt11              #1 tapes on bus 2
    MAKEDEV.$NAME vj0 vj1
    MAKEDEV.$NAME vt4
    MAKEDEV.$NAME vj8 vj9
    MAKEDEV.$NAME vt11
    if ( OS4.0.1FLAG == true ) then
        /bin/chgrp operator vj*
        /bin/chmod g+r vj*
    endif
else
    echo ""
    echo "Delete old Interphase '/dev' entries for : vj"
    echo ""
    echo -n "$prompt (y/n) "
    set ans = $<
    if ( $ans =~ "y"|| $ans =~ "Y" || $ans =~ "yes" || $ans =~ "YES" ) then
        REMOVEDEV vj0 vj1       #2 disks on bus 1
        REMOVEDEV vt4           #1 tapes on bus 1
        REMOVEDEV vj8 vj9       #2 disks on bus 2
        REMOVEDEV vt11          #1 tapes on bus 2
        MAKEDEV.$NAME vj0 vj1
        MAKEDEV.$NAME vt4
        MAKEDEV.$NAME vj8 vj9
        MAKEDEV.$NAME vt11
        if ( OS4.0.1FLAG == true ) then
            /bin/chgrp operator vj*
            /bin/chmod g+r vj*
        endif
    endif
endif


echo "Done with non-bootable kernel" >> $DIAGOUTPUT

#*****************************************************************************#
# Create the bootable kernel                                                  #
#*****************************************************************************#

cd $OURDIR

# skip the bootable configuration
#
if ( $DOBOOT == false ) then
    goto goodbye
endif

echo ""
echo "Creating a bootable kernel.."
echo "Creating a bootable kernel.." >> $DIAGOUTPUT

#*****************************************************************************#
# Create a new bootable configuration file                                    #
#*****************************************************************************#

echo ""
echo "Creating the configuration file : $CONF/B$NEWCONFIGFILE"
echo "Creating the configuration file : $CONF/B$NEWCONFIGFILE" >> $DIAGOUTPUT
/bin/cp $CONF/$NEWCONFIGFILE $CONF/B$NEWCONFIGFILE

#*****************************************************************************#
# Correct the configuration file                                              #
#*****************************************************************************#

echo ""
echo "Updating the configuration file : $CONF/B$NEWCONFIGFILE"

if ( $BOOT4410 == true ) then
    # remove support for all Sun SCSI devices (commented out)
    echo "ed B$NEWCONFIGFILE < $FIXFILES/fixconfig.boot.4410.in" >> $DIAGOUTPUT
    ed $CONF/B$NEWCONFIGFILE < $FIXFILES/fixconfig.boot.4410.in >>& $DIAGOUTPUT
else if ( $BOOT441X == true ) then
    # remove support for 'xy0' and all Sun SCSI devices
    echo "ed B$NEWCONFIGFILE < $FIXFILES/fixconfig.boot.441X.in" >> $DIAGOUTPUT
    ed $CONF/B$NEWCONFIGFILE < $FIXFILES/fixconfig.boot.441X.in >>& $DIAGOUTPUT
else
    # if this path is taken "DOBOOT" is true but no device is selected for
    # support.. should never happen.
    echo "Bootable kernel was to be created but no bootable device selected" >> $DIAGOUTPUT
    echo "Bootable kernel was to be created but no bootable device selected" >> $OURDIR/warning
    set EXCEPTIONS = true
    set DOBOOT = false	# reset this flag to avoid 'config'
endif

echo "End bootable configuration file modifications" >> $DIAGOUTPUT

#*****************************************************************************#
# Modify the swapgeneric.c                                                    #
#*****************************************************************************#

if ( $OS =~ "os4" ) then

    #*************************************************************************#
    # Backup the user's swapgeneric.c file                                    #
    #*************************************************************************#

    if ! ( -e $SYSDIR/sun/swapgeneric.c.before.IP ) then
        echo ""
        echo "Backing up $SYSDIR/sun/swapgeneric.c as $SYSDIR/sun/swapgeneric.c.before.IP"
        /bin/cp $SYSDIR/sun/swapgeneric.c $SYSDIR/sun/swapgeneric.c.before.IP 
    endif

    #*************************************************************************#
    # Correct the swapgeneric.c file                                          #
    #*************************************************************************#
    # mods to the os4 swapgeneric are required for boot purposes
    # in OS4.0.3 the Sun IPI becomes a problem so.. fixswap will set the
    # Sun IPI "number of drives label" (NIPI) to zero

    echo ""
    echo "Updating $SYSDIR/sun/swapgeneric.c"
    /bin/cp $SYSDIR/sun/swapgeneric.c tempfile
    fixswap tempfile $SYSDIR/sun/swapgeneric.c 
    /bin/rm -f tempfile

    #*************************************************************************#
    # Compare swapgeneric before and after to make sure modifications worked  #
    #*************************************************************************#

    cmp -s $SYSDIR/sun/swapgeneric.c $SYSDIR/sun/swapgeneric.c.before.IP
    if ! ( $status ) then
        echo ""
        echo "Update of the 'swapgeneric.c' file failed"
        echo "Update of the 'swapgeneric.c' file failed" >> $OURDIR/warning
        echo "Update of the 'swapgeneric.c' file failed" >> $DIAGOUTPUT
        set EXCEPTIONS = true
    endif
endif

#*****************************************************************************#
# Do config on the bootable configuration file                                #
#*****************************************************************************#

if ( $DOBOOT == false ) then
    goto goodbye	# if this path is taken must be a problem
endif

cd $CONF
echo ""
echo "Executing config on the file : $CONF/B$NEWCONFIGFILE"
echo "Executing config on the file : $CONF/B$NEWCONFIGFILE" >> $DIAGOUTPUT
echo ""
/etc/config B$NEWCONFIGFILE

#*****************************************************************************#
# Make the new vmunix                                                         #
#*****************************************************************************#

echo ""
echo "Compiling the bootable vmunix kernel"
echo "Compiling the bootable vmunix kernel" >> $DIAGOUTPUT
cd $UNIX/B$NEWCONFIGFILE
echo ""
make
sync;sync

#*****************************************************************************#
# Copy the new bootable UNIX to the root file system                          #
#*****************************************************************************#

if ! ( -e vmunix ) then
    echo ""
    echo "Compilation of the bootable kernel failed"
    echo "Compilation of the bootable kernel failed" >> $OURDIR/warning
    echo "Compilation of the bootable kernel failed" >> $DIAGOUTPUT
    set EXCEPTIONS = true
else
    if ( $EMULATION == false ) then	#do this if not in emulation mode
        echo ""
        echo "Copying bootable vmunix to root as vmunix.B$NEWCONFIGFILE"
        /bin/cp vmunix /vmunix.B$NEWCONFIGFILE
    else
        # backup any vmunix.original kernel
        if ! ( -e /vmunix.original ) then
            echo ""
            echo "Backing up the GENERIC kernel as 'vmunix.original'"
           /bin/mv /vmunix /vmunix.original
           echo ""
           echo "Copy the new bootable /vmunix to root(/) as /vmunix (y/n) ?"
           echo ""
           echo -n $prompt
           set ans = $<
           if ( $ans =~ "y" ) then
               echo ""
               echo "Copying bootable vmunix to root as vmunix"
               /bin/cp vmunix /vmunix
           endif		#ans=yes
        else
           echo ""
           echo "Unable to back up /vmunix, file /vmunix.original already exists"
           echo "Unable to back up /vmunix, file /vmunix.original already exists" >> $OURDIR/warning
           echo "Unable to back up /vmunix, file /vmunix.original already exists"  >> $DIAGOUTPUT
           set EXCEPTIONS = true        # set exceptions; the backup failed
           echo ""
           echo "Copy the new bootable /vmunix to root(/) as /vmunix (y/n) ?"
           echo ""
           echo -n $prompt
           set ans = $<
           if ( $ans =~ "y" ) then
               echo ""
               echo "Copying bootable vmunix to root as vmunix"
               /bin/cp vmunix /vmunix
           endif		#ans=yes
        endif			#if vmunix.original exists?
    endif			#if emulation
endif				#compilation is ok

#*****************************************************************************#
# Fix  /etc/fstab for for Emulation                                           #
#*****************************************************************************#
# a line in fstab like: "/dev/sd0a..."  becomes  "/dev/ip0a..." etc.

cd $OURDIR
if ( $EMULATION == true ) then
    if ! ( -e /etc/fstab.before.IP ) then
        echo ""
        echo "Backing up /etc/fstab as /etc/fstab.before.IP"
        /bin/cp /etc/fstab /etc/fstab.before.IP
    endif

    echo ""
    echo "Updating /etc/fstab for Emulation Mode"
    echo "Updating /etc/fstab for Emulation Mode" >> $DIAGOUTPUT
    fixfstab /etc/fstab sd0a vj0a
endif

#*****************************************************************************#
# Normal '4410_install' Exit Routine
#*****************************************************************************#
goodbye:
    onintr					#allow untrapped interrupts
    if ( $EMULATION == true ) then
        echo "***********************************************************"
        echo "*                                                         *"
        echo "*                                                         *"
        echo "*         CHECK '/etc/fstab' before booting the           *"
        echo "*             new Interphase vmunix kernel                *"
        echo "*                                                         *"
        echo "*                                                         *"
        echo "***********************************************************"
        echo " "
        echo -n "Hit <RETURN> to continue.."
        set ans = $<
    endif
    if ( $EXCEPTIONS == true ) then
        cat $OURDIR/warning $OURDIR/closingnotes.$NAME |more
    else
        cat $OURDIR/closingnotes.$NAME|more
    endif					#exception
Normal_exit:
    exit

#*****************************************************************************#
# End Installation                                                            #
#*****************************************************************************#

#*****************************************************************************#
# Interrupt Service Routine                                                   #
#*****************************************************************************#
exitinterrupt:

cd $OURDIR
echo ""
echo "You have interrupted the installation process"
echo ""
echo "Do you want to undo the installation (y/n) ?"
echo -n $prompt
set ans = $<
if ( $ans =~ "yes"||$ans =~ "Yes"||$ans =~ "YES"||$ans =~ "y"||$ans =~ "Y" ) then
   /bin/rm -f $CONF/$NEWCONFIGFILE
   /bin/rm -f $CONF/B$NEWCONFIGFILE

   if ( $OS3_2FLAG == true || $OS =~ "os4" ) then
       /bin/cp $CONF/devices.before.IP $CONF/devices
       /bin/cp $CONF/files.before.IP $CONF/files
       /bin/cp $SYSDIR/sun/swapgeneric.c.before.IP $SYSDIR/sun/swapgeneric.c
   else
       /bin/cp $CONF/devices.$SYSTYPE.before.IP $CONF/devices.$SYSTYPE
       /bin/cp $CONF/files.$SYSTYPE.before.IP $CONF/files.$SYSTYPE
   endif

   /bin/cp $SYSDIR/sun/conf.c.before.IP $SYSDIR/sun/conf.c
   /bin/cp /etc/fstab.before.IP /etc/fstab
   /bin/rm -f MAKEDEV.$NAME
   cd $UNIX
   /bin/rm -fr $NEWCONFIGFILE
   /bin/rm -fr B$NEWCONFIGFILE
   /bin/rm -i /vmunix.$NEWCONFIGFILE
   /bin/rm -i /vmunix.B$NEWCONFIGFILE
else
   echo ""
   echo "No removals made" 
endif
goto Normal_exit

#*****************************************************************************#
# Fatal Error Exit Routine                                                    #
#*****************************************************************************#
fatal_error_exit:
    echo ""
    echo "A fatal error was encountered"
exit

#*****************************************************************************#
# End 4410_install script
#*****************************************************************************#
