#!/bin/ksh
#
# This patch requires for Solaris 2.4 the KJP 101945-XX
#
PATID=101973
PATVER=40

#
#       There may be multiple SUNWcar packages installed (SUNWcar, SUNWcar.1,
#       and so on).  We must inspect each of them.
#
INFO="$ROOTDIR/var/sadm/pkg/SUNWcsu*/pkginfo"

complain() {
    echo
    echo "This patch may not be installed on this version of Solaris without"
    echo "first installing version $PATVER or greater of patch $PATID."
    echo
}

if [ `uname -r` != "5.4" ] ;
then
    exit 0
fi

#       Look for the patch ID in either SUNW_PATCHID or
#       SUNW_OBSOLETES (one at a time since they have
#       different content).
#
if egrep -s "SUNW_PATCHID.*$PATID" $INFO
then
        #
        #       Some version of the patch we depend on has
        #       been installed.  Extract the patch version
        #       number and see whether it's large enough.
        #
        for patch in `egrep "SUNW_PATCHID.*$PATID" $INFO |
                cut -d= -f2 | sort -u`
        do
                ver=`echo $patch | sed -e "s/.*$PATID-\([0-9]*\).*/\1/"`
                if [ $ver -ge $PATVER ]
                then
                        exit 0
                fi
        done
        #
        #       Installed version of the patch is too small
        #       to contain
        #
        complain
        exit 1
else
        #
        #       The patch version number is not guaranteed to
        #       be present in the SUNW_OBSOLETES entry.  Look
        #       only for the patch ID itself.
        #
        if egrep -s "SUNW_OBSOLETES.*$PATID" $INFO
        then
                #
                #       Patch has been obsoleted.  Its changes,
                #       including the one we care about, must
                #       have been subsumed in the new patch.
                #
                exit 0
        else
                #
                #       No patch obsoleting the one we depend
                #       on has been installed.
                #
                complain
                exit 1
        fi
fi
exit 0
