#!/bin/bash

echo JAVA HOME set to $JAVA_HOME

#verify that user env can run java programs of version 1.5 or higher.

jver=`java -version 2>&1 | grep 'java version' 2>&1 | awk '{print $3}' | sed 's/\"//g'`
 val=`java -version 2>&1 | grep -c '1.[5-9].[0-9]'`
val1=`java -version 2>&1 | grep -c '2.[0-9].[0-9]'`

echo "Installed Java version: $jver"

#if java version 1.5+ or 2.0+ exist, jdk is set properly
#if does not exist, exit shell program with return code 1
if [ $val == 0 ] && [ $val1 == 0 ]
then
        echo "ERROR: Java version 1.5 or higher NOT found."
        echo "Set JAVA_HOME and/or PATH to point at your Java Development Kit installation"
	exit 1
fi

if [ -d ${JAVA_HOME}/bin ]
then
	echo " "
else
	echo "ERROR: JAVA_HOME/bin is not found on the path!"
	exit 1
fi
	
exit 0
