#!/bin/ksh
#
# Copyright (c) 2004 by Sun Microsystems, Inc.
# All rights reserved
#
# "@(#)prepatch	1.1  04/03/24 SMI"
#
# Prepatch script to check for CE driver dependencies. Lagger requires
# CE driver patch.
#
# Patch and OS supported
CE_PATCH="112817-15"
PATCH_OS="5.9"

GREP="/usr/bin/grep"
SED="/usr/bin/sed"
SHOWREV="/usr/bin/showrev"

# check if running under 64 bit mode
ISA=$([ -f /usr/bin/isainfo ] && /usr/bin/isainfo || echo "sparc")
if [ "$ISA" = "sparcv9 sparc" ]
then
    # 64-bit OS running:
    IS_64_BIT="yes"
else
    IS_64_BIT="no"
fi

# check OS version 
OSVER=$(uname -r)

if [ ! $OSVER = $PATCH_OS ] ; then
   echo "Invalid OS for patch installation."
   exit 1
fi


# check if SUNWced has been installed

# check for 64-bit kernel
if [ $IS_64_BIT = "yes" ] ; then
   PKGTOCHK="SUNWcedx"
else
   PKGTOCHK="SUNWced"
fi

if pkginfo $PKGTOCHK >/dev/null 2>&1 ; then
    # see if patch is installed.. per OS
    echo "Checking for CE driver dependencies...\n"
    # check if patch installed
    if ! $SHOWREV -p | \
    	$GREP "^Patch: ${CE_PATCH%-*}-[0-9][0-9]*" >/dev/null 2>&1 
    then # req'd patch not installed.
	echo "GigaSwift Ethernet driver (CE driver) patch is not installed. Patch $CE_PATCH "
	echo "must be installed before this patch can be installed.\n" 
        echo "Aborting patch installation." 
        exit 1
    else # make sure its not an older version of the patch
         CURRPATCHVER=$($SHOWREV -p | \
          $SED -n "s/^Patch: \(${CE_PATCH%-*}-[0-9][0-9]*\).*/\1/p" | \
          sort -n | \
          tail -1)

         if [ "${CURRPATCHVER##*-}" -lt "${CE_PATCH##*-}" ]
             then
		echo "GigaSwift Ethernet driver (CE driver) patch $CURRPATCH needs to be updated"
	        echo "to $CE_PATCH.\n"
		echo "Aborting patch installation."
		exit 1
         fi
     fi
fi


