#!/bin/sh 
#set -x
#
# Copyright 11/18/04 Sun Microsystems, Inc. All rights reserved.
#
# @(#)perftools_validate.ver.sh 1.96 04/11/18 SMI
#
# SUN PROPRIETARY/CONFIDENTIAL 
# Use is subject to license terms.
#

# This string is here for the 'version' command:
# It gets sed'ed in at build-time:
# @(#)RELEASE VERSION Sun Performance Analyzer 7.4 122141-01 2006/07/12

# Product and J2SE Validation script 
script_version=1.96

# default location check?
default_loc_warning="off"

# check for V9 patches?
V9patches="yes"

# Expected changes needed before FCS:
#  FIXUP: Will need to require latest libC patch, all platforms

# Default install locations for Java
# NOTE: THESE CHANGE WITH EACH RELEASE
solaris_java_loc="/usr/jdk/j2sdk1.4.2_06/bin/java"
linux_java_loc="/usr/java/j2sdk1.4.2_06/bin/java"
if [ "`uname`" = "Linux" ]; then
    default_java_loc="${linux_java_loc}"
else
    default_java_loc="${solaris_java_loc}"
fi
version_needed="1.4.2_02 or later"

##########################################################################
# NOTE: These are the required patches, and may not be the latest patches.
#       Sunsolve will probably not have these specific patches available for
#       download, and the newer revs (which should be fine) may require
#       additional patches that are not in this list.
#       This list of patches may not be completely contained, i.e. these
#       patches may require additional patches not in this list. This
#       should be ok, in that this is a validation and not a patch installation
#       script, in theory all we need to do is check for the patches we
#       require and we need not verify that the complete patch tree is
#       on the system.
#	If a patch we wish to install has a newer rev on the system, then
#	that patch is satisfied by this newer rev patch.
#	If a patch has been made obsolete by some other patch on the system
#	then that patch is also considered satisfied by the other patch.
##########################################################################
#
# Patches needed for 5.7, 5.8, 5.9

# Should match the patch list file for the product, e.g. for FEE:
#  http://dpweb.eng.sun.com/set/misc/docs/common/installation/j2se_patch_order.txt

# i386/5.7 ...
collect_intel_57_patches=""
collect_intel_57_patches="${collect_intel_57_patches} 106951-24" # Linker
collect_intel_57_patches="${collect_intel_57_patches} 107545-03" # fsck
collect_intel_57_patches="${collect_intel_57_patches} 106542-21" # Kernel
collect_intel_57_patches="${collect_intel_57_patches} 106981-19" # libthread
collect_intel_57_patches="${collect_intel_57_patches} 108245-04" # libaio
collect_intel_57_patches="${collect_intel_57_patches} 108163-03" # *sh
intel_57_patches="${collect_intel_57_patches}"
intel_57_patches="${intel_57_patches} 106328-14" # libC32bit
intel_57_patches="${intel_57_patches} 108377-34" # Xsun
intel_57_patches="${intel_57_patches} 107657-06" # libXt
intel_57_patches="${intel_57_patches} 107082-50" # Motif
intel_57_patches="${intel_57_patches} 107703-09" # CDE/dtsession
intel_57_patches="${intel_57_patches} 108375-07" # CDE/widget
intel_57_patches="${intel_57_patches} 107227-18" # CDE/dtwm
intel_57_patches="${intel_57_patches} 106749-04" # make/sccs
intel_57_patches="${intel_57_patches} 107637-09" # Xinput

# i386/5.8 ...
collect_intel_58_patches=""
collect_intel_58_patches="${collect_intel_58_patches} 109148-31" # Linker
collect_intel_58_patches="${collect_intel_58_patches} 108529-15" # Kernel
collect_intel_58_patches="${collect_intel_58_patches} 108828-22" # lwp/libthread
collect_intel_58_patches="${collect_intel_58_patches} 109325-02" # *sh
collect_intel_58_patches="${collect_intel_58_patches} 117558-01" # libmtsk 
intel_58_patches="${collect_intel_58_patches}"
intel_58_patches="${intel_58_patches} 108436-09" # libC32bit
intel_58_patches="${intel_58_patches} 108653-46" # Xserver
intel_58_patches="${intel_58_patches} 108922-15" # CDE/dtwm
intel_58_patches="${intel_58_patches} 108941-45" # Motif
intel_58_patches="${intel_58_patches} 108774-15" # Xinput
intel_58_patches="${intel_58_patches} 109608-02" # stdlib_iso
intel_58_patches="${intel_58_patches} 108990-02" # Accounting
intel_58_patches="${intel_58_patches} 108715-07" # libDtWidget
intel_58_patches="${intel_58_patches} 108988-09" # patchadd/rm
intel_58_patches="${intel_58_patches} 111112-03" # nawk
intel_58_patches="${intel_58_patches} 111294-03" # libdevinfo
intel_58_patches="${intel_58_patches} 111307-03" # boot
intel_58_patches="${intel_58_patches} 111311-01" # libdhcpagent
intel_58_patches="${intel_58_patches} 112397-02" # fgrep
intel_58_patches="${intel_58_patches} 112439-01" # random
intel_58_patches="${intel_58_patches} 112473-01" # font

# intel/5.9 ...
collect_intel_59_patches=""
collect_intel_59_patches="${collect_intel_59_patches} 113986-12" # Linker
collect_intel_59_patches="${collect_intel_59_patches} 112234-08" # Kernel
collect_intel_59_patches="${collect_intel_59_patches} 117559-01" # libmtsk 
intel_59_patches="${collect_intel_59_patches}"

# sparc/5.7 ...
#
#                   libC64bit assembler
collect_sparc_57_patches=""
collect_sparc_57_patches="${collect_sparc_57_patches} 106950-24" # Linker
collect_sparc_57_patches="${collect_sparc_57_patches} 107544-03" # fsck
collect_sparc_57_patches="${collect_sparc_57_patches} 106541-22" # Kernel
collect_sparc_57_patches="${collect_sparc_57_patches} 106980-19" # libthread
collect_sparc_57_patches="${collect_sparc_57_patches} 108244-04" # libaio
collect_sparc_57_patches="${collect_sparc_57_patches} 108162-03" # *sh
sparc_57v9_patches=""
sparc_57_patches="${collect_sparc_57_patches}"
sparc_57_patches="${sparc_57_patches} 106327-15" # libC32bit
sparc_57v9_patches="${sparc_57v9_patches} 106300-16" # libC64bit
sparc_57_patches="${sparc_57_patches} 108376-38" # Xsun
sparc_57_patches="${sparc_57_patches} 107656-10" # libXt
sparc_57_patches="${sparc_57_patches} 107081-50" # Motif
sparc_57_patches="${sparc_57_patches} 107636-09" # Xinput
sparc_57_patches="${sparc_57_patches} 107702-09" # CDE/dtsession
sparc_57_patches="${sparc_57_patches} 108374-07" # CDE/widget
sparc_57_patches="${sparc_57_patches} 107226-18" # CDE/dtwm
sparc_57_patches="${sparc_57_patches} 106748-04" # make/sccs

sparc_57v9_patches="${sparc_57v9_patches} 107058-01" # Assembler

# sparc/5.8 ...
collect_sparc_58_patches=""
collect_sparc_58_patches="${collect_sparc_58_patches} 109147-31" # Linker
collect_sparc_58_patches="${collect_sparc_58_patches} 108528-20" # Kernel
collect_sparc_58_patches="${collect_sparc_58_patches} 108827-26" # lwp/libthread
collect_sparc_58_patches="${collect_sparc_58_patches} 109324-02" # *sh
collect_sparc_58_patches="${collect_sparc_58_patches} 117557-01" # libmtsk 
sparc_58_patches="${collect_sparc_58_patches}"
sparc_58v9_patches=""
sparc_58_patches="${sparc_58_patches} 108434-10" # libC32bit
sparc_58v9_patches="${sparc_58v9_patches} 108435-10" # libC64bit
sparc_58_patches="${sparc_58_patches} 108652-56" # Xserver 
sparc_58_patches="${sparc_58_patches} 108921-15" # CDE/dtwm
sparc_58_patches="${sparc_58_patches} 108940-45" # Motif
sparc_58_patches="${sparc_58_patches} 108773-15" # Xinput
sparc_58_patches="${sparc_58_patches} 109607-02" # stdlib_iso
sparc_58_patches="${sparc_58_patches} 108989-02" # Accounting
sparc_58_patches="${sparc_58_patches} 108714-07" # libDtWidget
sparc_58_patches="${sparc_58_patches} 108987-09" # patchadd/rm
sparc_58_patches="${sparc_58_patches} 111111-03" # nawk
sparc_58_patches="${sparc_58_patches} 111293-04" # libdevinfo
sparc_58_patches="${sparc_58_patches} 111310-01" # libdhcpagent
sparc_58_patches="${sparc_58_patches} 112396-02" # fgrep
sparc_58_patches="${sparc_58_patches} 112472-01" # font

# sparc/5.9 ...
collect_sparc_59_patches=""
collect_sparc_59_patches="${collect_sparc_59_patches} 112963-16" # Linker
collect_sparc_59_patches="${collect_sparc_59_patches} 112233-06" # Kernel
collect_sparc_59_patches="${collect_sparc_59_patches} 117560-01" # libmtsk 
sparc_59_patches="${collect_sparc_59_patches}"
sparc_59v9_patches=""

##########################################################################

# System commands used (don't rely on search paths)
RM=/bin/rm
CAT=/bin/cat
TTY=/usr/bin/tty
XDPYINFO=/usr/openwin/bin/xdpyinfo
DTERROR=/usr/dt/bin/dterror.ds
UNAME=/bin/uname
if [ "`${UNAME}`" = "Linux" ]; then
    HOSTNAME=`/bin/hostname -s`
else
    HOSTNAME=`/bin/hostname`
fi
DTDSPMSG=/usr/dt/bin/dtdspmsg
DIRNAME=/usr/bin/dirname
CUT=/usr/bin/cut
SED=/bin/sed
SORT=/bin/sort
UNIQ=/usr/bin/uniq
EXPR=/usr/bin/expr
GREP=/bin/grep
SHOWREV=/usr/bin/showrev
TOUCH=/bin/touch
CHMOD=/bin/chmod
BASENAME=/bin/basename
ISALIST=/usr/bin/isalist
SLEEP=/usr/bin/sleep

# Name of this script (aka "perftools_validate" last time it got named)
scriptname="`${BASENAME} $0`"

# find the full path to the script

PRG=$0
while [ -h "$PRG" ]; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
    if expr "$link" : '^/' > /dev/null 2>/dev/null; then
	PRG="$link"
    else
	PRG="`dirname $PRG`/$link"
    fi
done

progdir=`dirname $PRG`

# Location of script
scriptdir1="`${DIRNAME} $0`"
scriptdir="`cd ${scriptdir1} && pwd`"
if [ -d ${scriptdir1}/../READMEs ] ; then
    readmedir="`cd ${scriptdir1}/../READMEs && pwd`"
else
    readmedir="/opt/SUNWspro/prod/READMEs"
fi

# The website to get patches/J2SE
website="http://access1.sun.com/sundev"
jwebsite="http://java.sun.com/j2se"

# Cache file
cache_file=/tmp/${scriptname}_ok.${script_version}
cache_file_collect=/tmp/${scriptname}_collect_ok.${script_version}
patch_check="yes"

# Buffering file
bufferfile=/tmp/${scriptname}_message_buffer.$$
${RM} -f ${bufferfile}

# Exit status for this script
exit_status=0  

# List of missing patches
missing_patches=""

# Obsolete list
obsolete_list=""
obsolete_base_list=""

# Java version
javaversion=""

# File that will contain showrev -p output
sys_patches=/tmp/.${scriptname}_showrev.$$

# Get OS type and version
osver=`${progdir}/perftools_whichami -o`
ostype=`${progdir}/perftools_whichami -O`


##########################################################################
#  Subroutines used
##########################################################################
Usage()
{
    echo "${scriptname}: Validates that the system/J2SE can run the Performance Tools"
    echo " " 
    echo "USAGE: ${scriptname} [-c] [-j javapath] [-H java_how] [-q] [-b] [-f] [-h] [-d] [-D] [-9]"
    echo "      -c            Collect only, also don't check default loc of J2SE"
    echo "      -j javapath   Java for Java profiling, check it"
    echo "      -H java_how   How the Java for -j or -J was picked"
    echo "      -q            Quiet mode, if system ok, say nothing"
    echo "      -p N          Pause for N seconds after issuing warnings"
    echo "      -b            Buffer up messages and send all at once"
    echo "      -f            Bypass the cache"
    echo "      -h            Print this help message"
    echo "      -d            Use dt"
    echo "      -D            Debug mode, script gets really noisy"
    echo " Exit status:"
    echo "    0 - ok"
    echo "    1 - warnings, not fatal to run J2SE"
    echo "    2 - bad J2SE, do not run"
    echo "    3 - missing patches, do not run"
    echo "    4 - internal error, contact support"
}

##########################################################################
InternalError()
{
    DumpBuffer
    echo "INTERNAL ERROR: $1"
    Usage
    exit 4
}

##########################################################################
Debugmessage()
{
    if [ "${debugmode}" = "on" ] ; then
        echo "DEBUG: $1"
    fi
}

##########################################################################
SetExitStatus()
{
    if [ ${exit_status} -eq 0 ] ; then
	exit_status=$1
    fi
}

##########################################################################
Console()
{
    message="$1"
    if [ "${use_dt}" = "no" ] ; then
	echo "${message}"
    else
	${DTERROR} "${message}" "The Performance Tools" 'Continue'
    fi
}

##########################################################################
# Dump buffer load of messages
DumpBuffer()
{
    if [ "${buffering}" = "on" ] ; then
	if [ -s ${bufferfile} ] ; then
	    Console "`${CAT} ${bufferfile}`"
	    ${RM} -f ${bufferfile}
	fi
    fi
}

##########################################################################
# GTXT -- L10N Message translation utility

GTXT()
{
    eval I18Ntxt$2="\"$1\""
}

# define all i18n messages -- used by I18Ncheck in the build

GTXT "NOTE: You can download and install the required Solaris[tm] patches from %s.\n" 1
GTXT "WARNING: The J2SE[tm] version \"%s\" found at \"%s\" (picked by %s) cannot be used by the Performance tools;\n" 2
GTXT "WARNING: No J2SE[tm] was found at %s (picked by %s).\n" 3
GTXT "WARNING: The recommended default install location for J2SE[tm] %s is %s, not %s.\n" 4
GTXT "WARNING: The following required %s patches have not been installed on system \"%s\": %s\n" 5
GTXT "NOTE: %s system \"%s\" is correctly patched and set up for use with the Performance tools.\n" 6
GTXT "WARNING: %s system \"%s\" is not supported by the Performance tools.\n" 7
GTXT "NOTE: J2SE[tm] version %s was found at %s (picked by %s).\n" 8
GTXT "NOTE: %s system \"%s\" is supported by the Performance tools.\n" 9
GTXT "NOTE: You can download and install the J2SE[tm] from %s.\n" 10
GTXT "      J2SE[tm] %s is recommended.\n" 11
GTXT "NOTE: The J2SE[tm] version %s found at %s (picked by %s) is supported by the Performance tools.\n" 12

##########################################################################
Message()
{
  # Message() - display message from ${scriptname}.cat
  #   $1 - message id

  text=I18Ntxt$1

  if [ "${buffering}" = "on" ] ; then
      if [ -x $DTDSPMSG ]; then
	  eval eval $DTDSPMSG -s 18 analyzer.cat $1 \\\"\\\${$text}\\\"  ${2:+"\\\"$2\\\""} ${3:+"\\\"$3\\\""} ${4:+"\\\"$4\\\""} >> ${bufferfile}
      else
	  eval eval printf \\\"\\\${$text}\\\" ${2:+"\\\"$2\\\""} ${3:+"\\\"$3\\\""} ${4:+"\\\"$4\\\""} >> ${bufferfile}
      fi
      if [ "${use_dt}" = "yes" ] ; then
	  printf '\\n' >> ${bufferfile}
      fi
  else
      if [ -x $DTDSPMSG ]; then
	  eval eval $DTDSPMSG -s 18 analyzer.cat $1 \\\"\\\${$text}\\\"  ${2:+"\\\"$2\\\""} ${3:+"\\\"$3\\\""} ${4:+"\\\"$4\\\""}
      else
	  eval eval printf \\\"\\\${$text}\\\" ${2:+"\\\"$2\\\""} ${3:+"\\\"$3\\\""} ${4:+"\\\"$4\\\""}
      fi
  fi
}

##########################################################################
Recommendation()
{
    Message 1 "${website}"
}

##########################################################################
JRecommendation()
{
    Message 10 "${jwebsite}"
}

##########################################################################
JNotSupported()
{
    Message 2 "${javaversion}" "${javapath}" "${java_how}"
    Message 11 "${version_needed}"
    JRecommendation
    SetExitStatus 2
}

##########################################################################
JNotRecommended()
{
    Message 8 "${javaversion}" "${javapath}" "${java_how}"
    Message 11 "${version_needed}"
    JRecommendation
    SetExitStatus 2
}

##########################################################################
JNotAvailable()
{
    Message 3 "${javapath}" "${java_how}"
    JRecommendation
    SetExitStatus 2
}

##########################################################################
JNotNormal()
{
    Message 4 "${version_needed}" "${default_java_loc}" "${javapath}"
    JRecommendation
    SetExitStatus 2
}
##########################################################################
JOK()
{
    if [ ${quietmode} = "off" ] ; then
	Message 12 "${javaversion}" "${javapath}" "${java_how}"
    fi
}

##########################################################################
MissingPatches()
{
    Message 5 "${osver}" "${HOSTNAME}" "${missing_patches}"
    Recommendation
    SetExitStatus 1
}

##########################################################################
OSUnsupported()
{
    Message 7 "${ostype}" "${HOSTNAME}" 
    SetExitStatus 1
}

##########################################################################
Validated()
{
    if [ ${quietmode} = "off" ] ; then
        if [ ${patch_check} = "no" ] ; then
            Message 9 "${ostype}" "${HOSTNAME}" 
	else
	    Message 6 "${ostype}" "${HOSTNAME}"
        fi
    fi
}

##########################################################################
# Get obsolete patch list
GetObsoleteList()
{
    Debugmessage "Looking for obsolete patches"
    raw_obsolete_list="`${GREP} 'Obsoletes:' ${sys_patches} | ${SED} 's/.*Obsoletes:\([\ \	,0-9-]*\).*/\1/' | ${SED} -e 's/,/ /g'`"
    for i in ${raw_obsolete_list} END ; do
	if [ "${i}" = "END" ] ; then
	   break;
	fi
        for x in ${obsolete_list} END ; do
	    if [ "${x}" = "${i}" ] ; then
		break;
	    fi
	done
	if [ "${x}" != "${i}" ] ; then
	    obsolete_list="${obsolete_list} $i"
	fi
    done
    if [ "${obsolete_list}" != "" ] ; then
	obsolete_base_list="`echo ${obsolete_list} | ${SED} 's/\([1-9][0-9][0-9][0-9][0-9][0-9]\)-[0-9][0-9]/\1/g'`"
        Debugmessage "Obsolete base list: ${obsolete_base_list}"
    fi
    Debugmessage "Obsolete list: ${obsolete_list}"
}

##########################################################################
# See if a specific patch is on the system
CheckPatch() 
{
    foundpatch=""
    p=$1
    
    # See if patch is in the obsolete list
    Debugmessage "Looking for patch $p"
    base="`echo $p | ${SED} 's/\([1-9][0-9][0-9][0-9][0-9][0-9]\)-[0-9][0-9]/\1/'`"
    rev="`echo $p | ${SED} 's/[1-9][0-9][0-9][0-9][0-9][0-9]-\([0-9][0-9]\)/\1/'`"
    if [ "${obsolete_base_list}" != "" ] ; then
	for obase in ${obsolete_base_list} ; do
	    if [ "${base}" = "${obase}" ] ; then
		Debugmessage "Checking base patch ${base} for obsoleteness"
		orev=`echo "${obsolete_list}" | ${SED} "s/.*${base}-\([0-9][0-9]\).*/\1/"`
		Debugmessage "rev=${rev}, orev=${orev}"
		if [ `${EXPR} ${rev} '<=' ${orev}` = '1' ] ; then
		    Debugmessage "Found patch $i to be obsolete, making $p obsolete"
		    return
		fi
	    fi
	done
    fi

    all=`${GREP} "Patch: $base" $sys_patches`
    Debugmessage "Base of patch is ${base}, rev is ${rev}"
    if [ "$all" != "" ] ; then
        revs=`echo "$all" | ${SED} 's/^Patch: [1-9][0-9][0-9][0-9][0-9][0-9]-\([0-9][0-9]\).*$/\1/' | ${SORT} | ${UNIQ}`
        Debugmessage "Found the following revs: ${revs}"
	for r in $revs ; do
	    if [ `${EXPR} $rev '<=' $r` = '1' ] ; then
		foundpatch="$base-$r"
                Debugmessage "Found patch $p in form of $base-$r"
		break
	    fi
	done
    fi
    if [ "$foundpatch" = "" ] ; then
	Debugmessage "Missing patch $p"
        missing_patches="${missing_patches} ${p}"
    fi
}

##########################################################################
# Function that checks all the patches
CheckAllPatches() # osver sparc_patches intel_patches
{
    # Get obsolete list
    GetObsoleteList

    osver="$1"
    arch="`${UNAME} -p`"
    if [ "${arch}" = sparc ] ; then
	patches="$2"
    else
	patches="$3"
    fi
    Debugmessage "Looking for ${arch} ${osver} patches ${patches}"
    for i in ${patches} ; do
	CheckPatch $i
    done
}

##########################################################################
# Get the version of java at javapath
GetJavaVersion()
{
    javaversion=`${javapath} -version 2>&1 | ${GREP} 'java version' | ${CUT} -f2 -d'"'`
    Debugmessage "Got javaversion \"${javaversion}\" from ${javapath} -version 2>&1 | ${GREP} 'java version'"
    javasversion=`echo "${javaversion}" | ${SED} s/_/./ `
    Debugmessage "sed ${javaversion} to \"${javasversion}\" from ${SED} 's/_/./'"
}

##########################################################################
##########################################################################
#  Main program starts here...
##########################################################################
##########################################################################

# l10n update this

NLSPATH="${scriptdir}/locale/%L/%N:${scriptdir}/../lib/locale/%L/LC_MESSAGES/%N:${NLSPATH}"
export NLSPATH

# Set default values
quietmode="off"
buffering="off"
use_dt="no"

# If standard input is NOT a terminal, then we assume no console? Use popup.
${TTY} -s
if [ $? -ne 0 ] ; then
    use_dt="yes"
fi

javapath=""
java_how="?"
collectmode="off"
debugmode="off"
forcemode="off"
psecs=""

#-------------------------------
# Parse the options from the command line

while getopts bcdDfhj:J:H:qp:V option
do
  case $option in
      # -c
      c) collectmode="on"; use_dt="no";cache_file=$cache_file_collect;; # disable popups and display validation
      # -d
      d) use_dt="yes";;
      # -D
      D) debugmode="on";;
      # -f
      f) forcemode="on";;
      # -j javapath
      j) javapath="$OPTARG";;
      # -J javapath
      J) javapath="$OPTARG";;
      # -H java_how
      H) java_how="$OPTARG";;
      # -p N
      p) psecs="$OPTARG";;
      # -q
      q) quietmode="on";;
      # -b
      b) buffering="on";;
      # -h
      h) Usage
	 exit 0;;
      # -V
      V)  echo `${BASENAME} $0`: "Sun Performance Analyzer 7.4 122141-01 2006/07/12"; exit 0;;
      # Unknown
      \?) InternalError "Unknown option";;
    esac
done
shift `${EXPR} $OPTIND - 1`
if [ "$*" != "" ] ; then
    InternalError "Illegal input on command line: $*"
fi

# If using popup, make sure display is valid
if [ "${use_dt}" = "yes" ] ; then
    ${XDPYINFO} > /dev/null 2>&1 
    if [ $? -ne 0 ] ; then
	use_dt="no"
    else
        buffering="on"
    fi
fi

#-------------------------------
# The collect option may change the patch list
if [ "${collectmode}" = "on" ] ; then
    default_loc_warning="off"
    # Skip java check unless -j options seen
    if [ "${javapath}" = "" ] ; then
	# Just check collector patches
	Debugmessage "Changing patch list for collect"
        intel_57_patches="${collect_intel_57_patches}"
        intel_58_patches="${collect_intel_58_patches}"
	sparc_57v9_patches=""
	sparc_58v9_patches=""
	sparc_59v9_patches=""
        sparc_57_patches="${collect_sparc_57_patches}"
        sparc_58_patches="${collect_sparc_58_patches}"
        sparc_59_patches="${collect_sparc_59_patches}"
    fi
else
    # Use default javapath  if not set
    if [ "${javapath}" = "" ] ; then
	javapath="${default_java_loc}"
    fi
fi

# If debugging mode is on, say what was requested
Debugmessage "quietmode=${quietmode}"
Debugmessage "collectmode=${collectmode}"
Debugmessage "debugmode=${debugmode}"
Debugmessage "forcemode=${forcemode}"
Debugmessage "javapath=${javapath}"

#-------------------------------
# Check system version first

if [ "${osver}" = "5.10" ] ; then
    Debugmessage "${osver} is ok"
elif [ "${osver}" = "5.9" ] ; then
    Debugmessage "${osver} is ok"
elif [ "${osver}" = "5.8" ] ; then
    Debugmessage "${osver} is ok"
elif [ "${osver}" = "JDS_2.0" ] ; then		#Sun Java Desktop 2.0
    Debugmessage "${osver} is ok"
    patch_check="no"
elif [ "${osver}" = "RH_AS_3" ] ; then		#RedHat AS 3
    Debugmessage "${osver} is ok"
    patch_check="no"
elif [ "${osver}" = "RH_ES_3" ] ; then		#RedHat ES 3
    Debugmessage "${osver} is ok"
    patch_check="no"
elif [ "${osver}" = "RH_WS_3" ] ; then		#RedHat WS 3
    Debugmessage "${osver} is ok"
    patch_check="no"
elif [ "${osver}" = "SuSE_8.1" ] ; then		#SuSE 8.1
    Debugmessage "${osver} is ok"
    patch_check="no"
else
    OSUnsupported
    patch_check="no"
fi

#-------------------------------
# Check for system patches

if [ "${patch_check}" = "yes" ] ; then
    # If cache file doesn't exist, do the checks for patches
    if [ "${forcemode}" = "on" -o ! -f ${cache_file} ] ; then

	# Remove v9 patches
	if [ "${V9patches}" = "no" -o "`${ISALIST} | ${GREP} sparcv9`" = "" ] ; then
	    sparc_57v9_patches=""
	    sparc_58v9_patches=""
	    sparc_59v9_patches=""
	fi

	# Check the Solaris patches
	${RM} -f ${sys_patches}
	if [ "${osver}" = "5.10" ] ; then
	    echo "Nothing to do yet" > /dev/null
	elif [ "${osver}" = "5.9" ] ; then
	    ${SHOWREV} -p > ${sys_patches}
	    CheckAllPatches ${osver} \
		"${sparc_59_patches} ${sparc_59v9_patches}" "${intel_59_patches}"
	elif [ "${osver}" = "5.8" ] ; then
	    ${SHOWREV} -p > ${sys_patches}
	    CheckAllPatches ${osver} \
		"${sparc_58_patches} ${sparc_58v9_patches}" "${intel_58_patches}"
	elif [ "${osver}" = "5.7" ] ; then
	    ${SHOWREV} -p > ${sys_patches}
	    CheckAllPatches ${osver} \
		"${sparc_57_patches} ${sparc_57v9_patches}" "${intel_57_patches}"
	fi
	${RM} -f ${sys_patches}
	
	# Check to see if there were missing patches
	if [ "${missing_patches}" != "" ] ; then
	    MissingPatches
	else
	    Validated
	fi

	# Touch cache file if we think it's ok
	if [ ${exit_status} = 0 ] ; then
	     ${TOUCH} -f ${cache_file}
	     ${CHMOD} a+rw ${cache_file}
	fi
    else
	Validated
    fi
else
    if [ ${exit_status} = 0 ] ; then
	Validated
    fi
fi

#-------------------------------
# Check for the right Java

# If not your normal javapath, say so
if [ "${default_loc_warning}" = "on" -a "${javapath}" != "" -a "${javapath}" != "${default_java_loc}" ] ; then
    JNotNormal
fi

# If we have a java to run, we check the java version
if [ "${javapath}" != "" ] ; then

    # Get the version of java being used
    GetJavaVersion
    Debugmessage "Found version \"${javaversion}\" from ${javapath}"

    # Check J2SE version
    if [ "${javaversion}" = "" ] ; then
	JNotAvailable
    else
	majorno="`echo ${javasversion} | cut -f1 -d'.' `"
	minorno="`echo ${javasversion} | cut -f2 -d'.' `"
	microno="`echo ${javasversion} | cut -f3 -d'.' `"	      \
	patchno="`echo ${javasversion} | cut -f4 -d'.' `"
	Debugmessage "Found that java major version is ${majorno}"
	Debugmessage "Found that java minor version is ${minorno}"
	Debugmessage "Found that java micro version is ${microno}"
	Debugmessage "Found that java patch version is ${patchno}"

	if [ ${majorno} -ne 1 ]; then
	    JNotSupported
	elif [ ${minorno} -eq 4 ] ; then
	    Debugmessage "Found java minorno = 4"
	    if [ "${collectmode}" = "on" ] ; then
	        Debugmessage "Found collect on"
		if [ "${microno}" = "" ] ; then
	            Debugmessage "Found microno NULL"
		    JNotSupported
		elif [ ${microno} -lt 2 ] ; then
	            Debugmessage "Found microno < 2"
		    JNotSupported
		elif [ ${microno} -eq 2 ] ; then
	            Debugmessage "Found microno = 2"
		    if [ "${patchno}" = "" ] ; then
	                Debugmessage "Found patchno = NULL"
			JNotSupported
		    elif [ ${patchno} -lt 02 ] ; then
	                Debugmessage "Found patchno = <02"
			JNotSupported
		    else
			JOK
		    fi
		else
		    JOK
		fi
	    else
		JOK
	    fi
	elif [ ${minorno} -ne 5 ] ; then
	    Debugmessage "Found java ${minorno} != 4, != 5"
	    JNotSupported
	else
	    JOK
	fi
    fi
fi
Debugmessage "DumpBuffer"

# If we are buffering up messages (-b option) dump the messages now
DumpBuffer

#-------------------------------
# If any warnings, wait a little to make sure they read them

if [ ${exit_status} != 0 ] ; then
    if [ "${psecs}" != "" ] ; then
        ${SLEEP} ${psecs}
    fi
fi

#-------------------------------
#  Now exit with the appropriate status

exit ${exit_status}
