#
#ident  "@(#)preinstall 1.2     93/05/04 SMI"
#
# Copyright (c) 1993 by Sun Microsystems, Inc.
#
#       Patch $PATID with version $PATVER or greater is required
#       to support this patch and must be installated prior to
#       installation of this patch.  This preinstall script enforces
#       this requirement
#
#
PATID=101945
PATVER=61

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

complain(){
	echo
        echo "This patch may not be installed without first installing"
        echo "version $PATVER or greater of patch $PATID."
}
#       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
