#!/bin/ksh
#
#Copyright (C) 2010, Oracle and/or its affiliates.
#All rights reserved.
#
#
# Prepatch script to check for Trunking driver dependencies. CE driver requires
# the Trunking Utility patch.
#
# Patch and OS supported
TRUNKING_PATCH="121182-01"
PATCH_OS="5.10"

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

if [ !  $ROOTDIR = "/" ] ; then
   OPT="-R $ROOTDIR"
else
   OPT=""
fi

# check if SUNWtrku has been installed

PKGTOCHK="SUNWtrku"

if pkginfo $OPT $PKGTOCHK >/dev/null 2>&1 ; then
    # see if patch is installed.. per OS
    echo "\nChecking for Trunking dependencies..."
    # check if patch installed
    if ! $SHOWREV -p $OPT | \
    	$GREP "^Patch: ${TRUNKING_PATCH%-*}-[0-9][0-9]*" >/dev/null 2>&1 
    then # req'd patch not installed.
	echo "***************************************************************************"
	echo "If trunking support is required for the CE driver, the latest Trunking patch"
        echo "$TRUNKING_PATCH should now be installed prior to rebooting or loading the " 
	echo "newly installed CE driver."
	echo "***************************************************************************"
	echo
        sleep 10
        exit 0
    else # make sure its not an older version of the patch
         CURRPATCHVER=$($SHOWREV -p $OPT | \
          $SED -n "s/^Patch: \(${TRUNKING_PATCH%-*}-[0-9][0-9]*\).*/\1/p" | \
          sort -n | \
          tail -1)

         if [ "${CURRPATCHVER##*-}" -lt "${TRUNKING_PATCH##*-}" ]
             then
		echo "***************************************************************************"
		echo "If trunking support is required for the CE driver, the latest Trunking patch"
        	echo "$TRUNKING_PATCH should now be installed prior to rebooting or loading the " 
		echo "newly installed CE driver."
		echo "***************************************************************************"
		echo
        	sleep 10
         fi
     fi
fi

exit 0
