#!/bin/ksh
#
# This patch requires the CDE 1.0.[12] libDtSvc patches.
#
PATID=
PATVER=

cdeVersion()
{
        pkg=`grep \/usr\/dt\/bin\/dtprintinfo /var/sadm/install/contents | cut -d' ' -f10`
        pkgversion=`pkginfo -l $pkg | grep -i version |  awk '{ print $2 }' | cut -d',' -f1`
        case $pkgversion in
                1.0.1)  case `uname -p` in
                                sparc)  echo '105714-04' ;;
                                i386)   echo '105715-04' ;;
                                *)      echo unknown ;;
                        esac ;;
                1.0.2)  case `uname -p` in
                                sparc)  echo '108363-01' ;;
                                i386)   echo '108364-01' ;;
                                *)      echo unknown ;;
                        esac ;;
                *)      echo unknown ;;
        esac
}

#
#       There may be multiple SUNWcar packages installed (SUNWcar, SUNWcar.1,
#       and so on).  We must inspect each of them.
#
INFO="$ROOTDIR/var/sadm/pkg/SUNWdtbas*/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
}

PATID=
PATVER=
PATCHID=`cdeVersion`
PATID=`echo $PATCHID | cut -d'-' -f1`
PATVER=`echo $PATCHID | cut -d'-' -f2`

#       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
