#!/bin/sh
# prepatch script
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# set -x
# 
PKG_INST1=SUNWdcar
PKG_VER_SUPPORTED1="1.1.0,REV=2002.05.29.15.02"

PKG_INST2=SUNWcrypr
PKG_VER_SUPPORTED2="1.1.0,REV=2002.05.29.15.00"

PRODUCT_NAME="Sun Accelerator 1000, Version 1.1"

echo 
echo "---------------------------------------------------------------------"
echo "This is the prepatch script for patch 114790-01. This prepatch script"
echo "will to check for the following dependencies:"
echo 
echo "  If deimos driver (dca) package (SUNWdcar) is installed, kcl" 
echo "  (SUNWcrypr) is installed." 
echo
echo "  If system runs Solaris 9 4/03 and patch 112233-05 is also required."
echo "---------------------------------------------------------------------"
echo

# Deimos driver check, SUNWdcar with driver name "sparcv9/dca"
# check to see if SUNWdcar is present with specific VERSION.

# Get latest package instance.  
LATEST_INST1=`pkginfo -R ${ROOTDIR:=/} | awk "/$PKG_INST1 /"' {print $2}' | sort -rn | head -1`

echo "Checking for presents of package $PKG_INST1.."
echo
if [ "$LATEST_INST1" = "" ] ; then
    echo "    $PRODUCT_NAME (package $PKG_INST1), is NOT installed"
    echo "    on this system. "
    echo
    ABORTFLG=1
fi


# Crypto Kernel Components package check, SUNWcrypr 
# check to see if SUNWcrypr is present with specific VERSION.

# Get latest package instance.  
LATEST_INST2=`pkginfo -R ${ROOTDIR:=/} | awk "/$PKG_INST2 /"' {print $2}' | sort -rn | head -1`

echo "Checking for presents of package $PKG_INST2.."
echo
if [ "$LATEST_INST2" = "" ] ; then
    echo "    $PRODUCT_NAME (package $PKG_INST2), is NOT installed"
    echo "    on this system. "
    echo
    ABORTFLG=1
fi

if [ "$ABORTFLG" = "1" ]; then
    echo "Patch Aborting..."
    echo
    exit 1
fi

CUR_PKG_VERSION1=`pkgparam -R $ROOTDIR $LATEST_INST1 VERSION`
CUR_PKG_VERSION2=`pkgparam -R $ROOTDIR $LATEST_INST2 VERSION`

# check to veryify that the current package is supported, if not
# abort patch installation.

echo "Checking for correct version for package $PKG_INST1.."
echo

if [ ! "$CUR_PKG_VERSION1" = "$PKG_VER_SUPPORTED1" ] ; then
    echo "    $LATEST_INST1, $CUR_PKG_VERSION1, is NOT supported by this patch."
    echo
    ABORTFLG=1
else
    echo "    Version OK"
    echo
fi

echo "Checking for correct version for package $PKG_INST2.."
echo

if [ ! "$CUR_PKG_VERSION2" = "$PKG_VER_SUPPORTED2" ] ; then
    echo "    $LATEST_INST2, $CUR_PKG_VERSION2, is NOT supported by this patch."
    echo
    ABORTFLG=1
else
    echo "    Version OK"
    echo
fi

# Check for supported OS only work on Solaris 9 4/03 and later

OSVERSION=`egrep 's9s_u[3-9]' $ROOT_DIR/etc/release`

echo "Checking for OS release version ..."
echo 
if [ "$OSVERSION" = "" ]; then 
    echo "      This patch is only supported on Solaris 9 4/03 and "
    echo "      subsequent compatible releases!"
    echo
    ABORTFLG=1
fi


if [ "$ABORTFLG" = "1" ]; then
    echo "Patch Aborting..."
    echo
    exit 1
fi


echo "Patch dependencies satisfied, continuing with patch installation."
echo

exit 0
