#!/bin/sh
# *************************************************************************
#
# Copyright 1993, Sun Microsystems, Inc.  All Rights Reserved.
#
# (c) Copyright 1993, Sun Microsystems, Inc.  All Rights Reserved.
# Derived from UNIX(R) and Berkeley 4.3 BSD licensed from UNIX System
# Laboratories, Inc. and the Regents of the University of California,
# respectively. Sun considers its source code as an unpublished, proprietary
# trade secret, and it is available only under strict license provisions.
# This copyright notice is placed here only to protect Sun in the event the
# source is deemed a published work.  Disassembly, decompilation, or other
# means of reducing the object code to human readable form is prohibited by
# the license agreement under which this code is provided to the user or
# company in possession of this copy.
#
# RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
# Government is subject to restrictions as set forth in subparagraph
# (c)(1)(ii) of the Rights in Technical Data and Computer Software
# Clause at DFARS 252.227-7013 (Oct. 1988) and FAR 52.227-19 (c)
# (June 1987). Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain
# View, California 94043
#
# **************************************************************************


#Set up local variables
DRIVER_BOM='nvt.o ipx.o nspx.o'
BOM="$DRIVER_BOM"
BOMDIR=`arch -k`
export BOM DRIVER_BOM PUBLIC_BOM

echo "Installing NetWare SunLink Jumbo Patch 6 - Part 2"

echo "---Preinstallation checking"

# We must be root
if [ `whoami` != root ]
then
	echo "!!!ERROR: must be root to continue to install patch!"
	exit 1
fi

# Read in all the config parameters
if [ ! -f /etc/netware/Parameters ]
then
	echo "!!!ERROR: must have a /etc/netware/Parameters file to continue to install patch!"
	exit 1
fi
. /etc/netware/Parameters
export RELEASE
export NWDIR
export NWUSER
export NWGROUP
export OBJ_DIR
export OBJUSER
export OBJGROUP
export KERNEL_DIR
export NEW_CONFIG
export BACKUP_SUBDIR
export SYSVOL_DIR

#Check that all our target dirs exist
for TARGET_DIR in $OBJ_DIR $KERNEL_DIR/$NEW_CONFIG /usr/tmp
do
	if [ ! -d $TARGET_DIR ]
	then
		echo "!!!ERROR: cannot complete patch installation - $TARGET_DIR directory does not exist."
		exit 1
	fi
done

#Check that all distribution files are here
for BOM_FILE in $BOM
do
	if [ ! -f $BOMDIR/$BOM_FILE ]
	then
		echo "!!!ERROR: patch contents not complete - $BOMDIR/$BOM_FILE file does not exist."
		exit 1
	fi
done
if [ ! -f dos/nvt.exe ]
then
	echo "!!!ERROR: patch contents not complete - dos/nvt.exe file does not exist."
	exit 1
fi

echo "---FCS $SYSVOL_DIR/public/nvt.exe file will be saved into dos/nvt.exe.FCS"

#Install the nvt.exe file
echo "---Installing nvt.exe to $SYSVOL_DIR/public"
if [ -f $SYSVOL_DIR/public/nvt.exe ]
then
		rm -f dos/nvt.exe.FCS
		cp $SYSVOL_DIR/public/nvt.exe dos/nvt.exe.FCS
fi
cp dos/nvt.exe $SYSVOL_DIR/public
chmod 444 $SYSVOL_DIR/public/nvt.exe
chown $NWUSER $SYSVOL_DIR/public/nvt.exe
chgrp $NWGROUP $SYSVOL_DIR/public/nvt.exe

echo "---FCS drivers will be saved into $BOMDIR as drivername.FCS"

#Install the drivers
if [ -n "$DRIVER_BOM" ]
then
	echo "---Installing $DRIVER_BOM to $OBJ_DIR"
	for DRIVER_FILE in $DRIVER_BOM
	do
		if [ -f $OBJ_DIR/$DRIVER_FILE ]
		then
			rm -f $BOMDIR/${DRIVER_FILE}.FCS
			cp $OBJ_DIR/$DRIVER_FILE $BOMDIR/${DRIVER_FILE}.FCS
		fi
		cp $BOMDIR/$DRIVER_FILE $OBJ_DIR
		chmod 444 $OBJ_DIR/$DRIVER_FILE
		chown $OBJUSER $OBJ_DIR/$DRIVER_FILE
		chgrp $OBJGROUP $OBJ_DIR/$DRIVER_FILE
	done
fi

#Rebuild the kernel
echo "---Rebuilding kernel with new driver(s)"
echo " "
cd $KERNEL_DIR/$NEW_CONFIG
make
if [ $? -ne 0 ]
then
		echo " "
		echo "!!!ERROR: could not rebuild kernel successfully"
		exit 1
fi
echo " "

rm -f /usr/tmp/vmunix
rm -f /usr/tmp/vmunix.old
ln -s $KERNEL_DIR/$NEW_CONFIG/vmunix  /usr/tmp/vmunix
ln -s $BACKUP_SUBDIR/vmunix /usr/tmp/vmunix.old

echo "Installation of NetWare SunLink Jumbo Patch 6 - Complete"
