#!/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
BOMDIR='sparc'
USRBIN_BOM='nwlp nwlpstat slist'
MAN1_BOM='nwlp.1 nwlpstat.1'
NW_BOM='ncp_engine volcheck nwfsck netware sap hybrid sconsole pserver bindfix startnw startnps stopptr stopnw stopnps rprinter'
ETC_BOM='edcfg'
BOM="$USRBIN_BOM $MAN1_BOM $NW_BOM"
export BOM USRBIN_BOM MAN_BOM NW_BOM BOMDIR

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

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 MANDIR
export MANDIR_USER
export MANDIR_GROUP
export USRBIN
export USRBIN_USER
export USRBIN_GROUP
export OBJ_DIR
export OBJUSER
export OBJGROUP
export KERNEL_DIR

# The server must be down
$USRBIN/servinfo -r
if [ $? -ge 4 ]
then
	echo "!!!ERROR: NetWare SunLink server must be down to install patch."
	exit 1
fi

#Check that all our target dirs exist
for TARGET_DIR in $NWDIR $MANDIR/man1 $USRBIN /etc/netware/sconsole
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

echo "---FCS files will be saved into $BOMDIR as filename.FCS"

#Install the /usr/bin portion
if [ -n "$USRBIN_BOM" ]
then
	echo "---Installing $USRBIN_BOM to $USRBIN"
	for USRBIN_FILE in $USRBIN_BOM
	do
		if [ -f $USRBIN/$USRBIN_FILE ]
		then
			rm -f $BOMDIR/${USRBIN_FILE}.FCS
			cp $USRBIN/$USRBIN_FILE $BOMDIR/${USRBIN_FILE}.FCS
		fi
		cp $BOMDIR/$USRBIN_FILE $USRBIN
		chmod 755 $USRBIN/$USRBIN_FILE
		chown $USRBIN_USER $USRBIN/$USRBIN_FILE
		chgrp $USRBIN_GROUP $USRBIN/$USRBIN_FILE
	done
fi

#Install the man pages portion
if [ -n "$MAN1_BOM" ]
then
	echo "---Installing $MAN1_BOM to $MANDIR/man1"
	for MAN_FILE in $MAN1_BOM
	do
		if [ -f $MANDIR/man1/$MAN_FILE ]
		then
			rm -f $BOMDIR/${MAN_FILE}.FCS
			cp $MANDIR/man1/$MAN_FILE $BOMDIR/${MAN_FILE}.FCS
		fi
		cp $BOMDIR/$MAN_FILE $MANDIR/man1/$MAN_FILE
		chmod 444 $MANDIR/man1/$MAN_FILE
		chown $MANDIR_USER $MANDIR/man1/$MAN_FILE
		chgrp $MANDIR_GROUP $MANDIR/man1/$MAN_FILE
	done
fi

#Install the nwuser admin portion
if [ -n "$NW_BOM" ]
then
	echo "---Installing $NW_BOM to $NWDIR"
	for NW_FILE in $NW_BOM
	do
		if [ -f $NWDIR/$NW_FILE ]
		then
			rm -f $BOMDIR/${NW_FILE}.FCS
			cp $NWDIR/$NW_FILE $BOMDIR/${NW_FILE}.FCS
		fi
		cp $BOMDIR/$NW_FILE $NWDIR/$NW_FILE
		chmod 4710 $NWDIR/$NW_FILE
		chown root $NWDIR/$NW_FILE
		chgrp $NWGROUP $NWDIR/$NW_FILE
	done
fi

#Install the /etc/netware portion
if [ -n "$ETC_BOM" ]
then
	echo "---Installing $ETC_BOM to /etc/netware/sconsole"
	for ETC_FILE in $ETC_BOM
	do
		if [ -f /etc/netware/sconsole/$ETC_FILE ]
		then
			rm -f $BOMDIR/${ETC_FILE}.FCS
			cp /etc/netware/sconsole/$ETC_FILE $BOMDIR/${ETC_FILE}.FCS
		fi
		cp $BOMDIR/$ETC_FILE /etc/netware/sconsole/$ETC_FILE
		chmod 744 /etc/netware/sconsole/$ETC_FILE
		chown $NWUSER /etc/netware/sconsole/$ETC_FILE
		chgrp $NWGROUP /etc/netware/sconsole/$ETC_FILE
	done
fi

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