#!/bin/csh -f
#pragma	ident	"@(#)patch_install 1.3     95/06/14 NPI"
# Install Patch 102227-03
#
# Usage: install_patch
#
# Note: You should change directory to the patch directory before running
#       this script.
#
# Written by:  J. Hsieh , Sun Microsystems, Education
# Modified by: Mahesh Jethanandani, Network Peripherals
#
# History:  May 10, 1993, 1.0 - Initial release.
#	    Oct. 14, 1993 updated for 100770-05 patch
#	    June 9, 1994 updated for 101776-01 patch

# Check to see if we are root.  Exit if we're not with a message.

if (`whoami` != "root") then
  echo "You need to be root to run this script.  Please become root"
  echo "and retry this script.  Thanks."
  echo " "
  exit 1
endif

# Local variables.

# The following variable needs to be set to the directory into which you have
# copied the jumbo patch raw files (usually from a patch tape, or possibly
# you have ftp'd these files from The Internet somewhere.

set patchdir = /usr/BF/102227-03

# If you have not explicity set the previous variable, or if it is set to a
# non-existent directory, this script will try to operate with the current
# working directory as the patch directory.

if (! -e $patchdir) then
  set patchdir = .
endif

# Initial message.

echo "This script will install the SunLink FDDI/S 1.0 patch 102227-03."
echo " "

# Kill smtd
/usr/etc/smtd_kill

set KARCH = `arch -k`

start:

echo -n "  Backing up old SunLink FDDI/S 1.0 files... "
setenv SUNLINKHOME /usr/BF
mv $SUNLINKHOME/usr/etc/bf.o	$SUNLINKHOME/usr/etc/bf.o_1.0
mv $SUNLINKHOME/sys/$KARCH/OBJ/if_bf.o	$SUNLINKHOME/sys/$KARCH/OBJ/if_bf.o_1.0
mv $SUNLINKHOME/usr/etc/smtd-static     $SUNLINKHOME/usr/etc/smtd-static_1.0
mv $SUNLINKHOME/usr/etc/smtd-shared     $SUNLINKHOME/usr/etc/smtd-shared_1.0
mv $SUNLINKHOME/usr/etc/smtmon          $SUNLINKHOME/usr/etc/smtmon_1.0

echo "done."

echo -n "  Copying patch files to $SUNLINKHOME... "
cd $patchdir
cp `arch`/usr/etc/$KARCH/bf.o $SUNLINKHOME/usr/etc
cp -rp `arch`/ $SUNLINKHOME
if ($status != 0) then
  echo "***************************************************************************"
  echo "***************************************************************************"
  echo "The patch file directory ($patchdir) does not contains the patch"
  echo "files.  Please re-run this script after changing into the patch directory."
  echo "***************************************************************************"
  echo "***************************************************************************"
  exit 1
endif

echo "done."

echo "  Verifying checksums of all installed patch files."

# In the following three arrays, the order is important.  The checksums and
# filenames are listed in order of the output from the "ls" command.

# The following checksums came hard-coded with the patch tape.

if ( $KARCH != "sun4c" ) then
	set verify = ( \
		09142 \
		63608 \
		47133 \
		44033 \
		09820 \
	)
else
	set verify = ( \
		49512 \
		65156 \
		47133 \
		44033 \
		09820 \
	)
endif

# The following checksums are computed from the installed files.
echo "start sum"

set sums = `/bin/sum $SUNLINKHOME/usr/etc/bf.o | awk '{print $1}'`
set sums = ($sums `/bin/sum $SUNLINKHOME/sys/$KARCH/OBJ/if_bf.o | awk '{print $1}'`)
set sums = ($sums `/bin/sum $SUNLINKHOME/usr/etc/smtd-static | awk '{print $1}'`)
set sums = ($sums `/bin/sum $SUNLINKHOME/usr/etc/smtd-shared | awk '{print $1}'`)
set sums = ($sums `/bin/sum $SUNLINKHOME/usr/etc/smtmon | awk '{print $1}'`)

# The following names correspond the to above checksums.

set filenames = ( \
  usr/etc/bf.o \
  sys/$KARCH/OBJ/if_bf.o \
  usr/etc/smtd-static \
  usr/etc/smtd-shared \
  usr/etc/smtmon \
  )
echo "start verify"
set index = 1
set err = 0
foreach check ($verify)
  echo -n "    $filenames[$index] ($sums[$index])... "
  if ($check != $sums[$index]) then
    echo " "
    echo "$SUNLINKHOME/$filenames[$index] is corrupt."
    echo "It's checksum was $sums[$index], and should have been $check"
    set err = 1
  endif
  echo "verify OK."
  @ index++
end

# Print error message and abort if any of the patch files was corrupted.

if ($err != 0) then
  echo " "
  echo "***************************************************************************"
  echo "***************************************************************************"
  echo "One or more of the installed patch files were corrupted.  See the above"
  echo "messages for details.  Please check your patch files for integrity.  You"
  echo "may need to get a new patch tape."
  echo "***************************************************************************"
  echo "***************************************************************************"
  exit 1

else

# All patch files were OK.  Installation can continue.
endif

cp $SUNLINKHOME/usr/etc/bf.o		/usr/etc/bf.o
cp $SUNLINKHOME/usr/etc/smtd-static     /usr/etc/smtd-static
cp $SUNLINKHOME/usr/etc/smtd-shared     /usr/etc/smtd-shared
cp $SUNLINKHOME/usr/etc/smtmon          /usr/etc/smtmon
 
/usr/etc/smtd


echo "Installation is complete."
echo " "
 
exit
