#!/bin/ksh
#
# checkpatches.sh
#
# Simple script to check for Mozilla Recommended Patches
#
# (c) Copyright 2002 Sun Microsystems, Inc.
#
#

JREPATCHPULLDATE="May 16, 2003"

# 
# Check for recommended patches
#
MISSINGPATCHES=0
S7_SPARC="107544-03 106950-18 106327-15 106300-16 108376-38 107656-10 107702-09 108374-07 107226-18 107081-50 107636-09 107834-03 106541-22 106980-19"
S7_INTEL="107545-03 106542-21 106981-19 106951-18 106328-14 108377-34 107657-08 107703-09 108375-07 107227-18 107082-50 107637-09"

S8_SPARC="108652-66 108921-16 112003-03 108773-18 111310-01 112472-01 108714-07 111111-03 112396-02 108940-54 108987-13 108528-22 108989-02 110380-04 110934-10 109147-24 111308-03 1122438-01 110386-03 111023-02 108993-22"

S8_INTEL="108653-55 108922-16 108774-18 111307-04 111311-01 112473-01 112439-01 108715-07 111112-03 112397-02 108941-54 108988-13 108529-22 108990-02 110403-04 110935-10 109148-24 111309-03 110400-01 111024-02 108994-22"

S7_SPARC_FONTPATCH="107153-01"
S7_INTEL_FONTPATCH="107152-01"

S7_SPARC_L10NPATCH1="109108-02"
S7_SPARC_L10NPATCH2="109110-02"

if [ `uname -p` = "sparc" ]
then
	if [ `uname -r` = "5.7" ]
	then
		PATCH_LIST=$S7_SPARC
		#
		# See if we need the patch for chinese fonts
		#
		/bin/pkginfo -q SUNWgttf
		FOUNDPKG=$?
		if [ $FOUNDPKG -eq 0 ]
		then
			PATCH_LIST="$S7_SPARC $S7_SPARC_FONTPATCH"
		fi
	
		                #
		# See if we need the patch for (Simplified Chinese) zh.GBK
		#
		/bin/pkginfo -q SUNWgxplt
		FOUNDPKG=$?
		if [ $FOUNDPKG -eq 0 ]
		then
			PATCH_LIST="$S7_SPARC $S7_SPARC_L10NPATCH1"
		fi

		#
		# See if we need the patch for Traditional Chinese BIG5 (zh_TW.BIG5)
		#
		/bin/pkginfo -q SUNW5xplt
		FOUNDPKG=$?
		if [ $FOUNDPKG -eq 0 ]
		then
			PATCH_LIST="$S7_SPARC $S7_SPARC_L10NPATCH2"
		fi


	elif [ `uname -r` = "5.8" ]
	then
		PATCH_LIST=$S8_SPARC
	fi
elif [ `uname -p` = "i386" ]
then
	if [ `uname -r` = "5.7" ]
	then 
		PATCH_LIST=$S7_INTEL
		#
		# See if we need the patch for chinese fonts
		#
		/bin/pkginfo -q SUNWgttf
		FOUNDPKG=$?
		if [ $FOUNDPKG -eq 0 ]
		then
			PATCH_LIST="$S7_INTEL $S7_INTEL_FONTPATCH"
		fi

	elif [ `uname -r` = "5.8" ]
	then
		PATCH_LIST=$S8_INTEL
	fi
fi

echo ""
echo "Checking for recommended patches "$PATCH_LIST"..."
echo ""

for patch in $PATCH_LIST
do 
	prefix=`echo $patch | nawk -F- '{ print $1 }'`
	version=`echo $patch | nawk -F- '{ print $2 }'`

	installed_patch_list=`showrev -p | nawk '{ print $2 }' | grep $prefix`
	FOUNDPATCH=0	
	for tmp in $installed_patch_list
	do
		tmp_prefix=`echo $tmp | nawk -F- '{ print $1 }'`
		if [ $tmp_prefix = $prefix ]
		then
			tmp_version=`echo $tmp | nawk -F- '{ print $2 }'`
			if [ $tmp_version -ge $version ]
			then
				FOUNDPATCH=1
			fi
		fi
	done

	if [ $FOUNDPATCH = 0 ]
	then
	 	MISSINGPATCHLIST="$patch or higher \n $MISSINGPATCHLIST"
		MISSINGPATCHES=1
	fi
done

if [ $MISSINGPATCHES = 1 ]
then

	echo "The following patches were not detected on this system:"
	echo " $MISSINGPATCHLIST"
	echo "You may need to install the missing patch(es) on this system."
	echo ""
	echo "NOTE: The patch list above was created on $JREPATCHPULLDATE and a full patch "
	echo "bundle is available on the Mozilla 1.2.1 for the Solaris OS download site."
	echo "Certain patches may have been updated since that date. For best "
	echo "performance, we recommend that you use the patch bundle available with the "
	echo "product download, rather than pulling those patches (or patch updates) "
	echo "individually from sunsolve.sun.com."
	echo ""
	echo "Please refer to the Mozilla 1.2.1 for the Solaris OS installation "
	echo "documentation for more information. The document is available at:"
	echo "http://www.sun.com/software/solaris/browser"
	echo ""
        exit 1
fi
