#!/bin/sh
#
# StarOffice patch checking script
# (c) 2000, Sun Microsystems Inc.

sd_inst="`dirname "$0"`"
sd_platform=`uname -s`

if [ "$sd_platform"="SunOS" ]; then
	#
	# check required patchid
	#


    sd_hardware=`uname -p`
	sd_release=`uname -r`
    required_patch=

	case $sd_hardware in
    i386)
        case $sd_release in
            5.5.1)
	        required_patch=106530
	        required_minor=5
	        ;;
	        5.6)
            required_patch=104678
	        required_minor=5
            ;;
            5.7)
            required_patch=106328
	        required_minor=6
            ;;
            5.8)
            required_patch=
	    ;;
        esac
        ;;
    sparc)
        case $sd_release in
            5.5.1)
	        required_patch=106529
	        required_minor=5
	        ;;
	        5.6)
            required_patch=105591
	        required_minor=6
            ;;
            5.7)
            required_patch=106327
	        required_minor=5
            ;;
            5.8)
            required_patch=
	    ;;
        esac
    esac

	#
    # if no patch is required we are done
    #


	if [ "$required_patch" = "" ]; then
		exit 0
	fi

	#
	# check prerequesites
	#

	if [ ! -x /usr/bin/awk ]; then
		exit 0
	fi

	#
	# check installed patches
	#

    patch_installed=`"$sd_inst"/sorev -l SUNWlibC | /usr/bin/awk \
		'{ \
			if ($1 == "Patch:") { \
				split($2, inst_patch, "-"); \
				if (inst_patch[1] == required_patch) { \
					if ((inst_patch[2]+1) >= (1+required_minor)){ \
						print "done"; exit 0; \
					} \
				} \
		 	} \
			if ($3 == "Obsoletes:") { \
				split($4, inst_patch, "-"); \
				if (inst_patch[1] == required_patch) { \
					if ((inst_patch[2]+1) >= (1+required_minor)){ \
						print "done"; exit 0; \
					} \
				} \
		 	} \
		}' required_patch=$required_patch required_minor=$required_minor `

	if [ "$patch_installed" = "done" ]; then
		exit 0
	else
		echo "Please install the patch 'Shared library patch for C++ (Version 5)' or contact your system administrator"
		exit 1
	fi
fi

exit 0
