#!/bin/ksh
#
# Copyright (c) 2005 by Sun Microsystems, Inc.
# All rights reserved
#
# "@(#)prepatch	1.2  05/12/13 SMI"
#
# Prepatch script to check for CE driver dependencies. Lagger requires
# CE driver patch.
#
# Patch and OS supported
CE_PATCH="118778-04"
PATCH_OS="5.10"

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

# 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

PKGTOCHK="SUNWced"

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


