Index: /greenstone3/trunk/gs3-server.sh
===================================================================
--- /greenstone3/trunk/gs3-server.sh	(revision 15130)
+++ /greenstone3/trunk/gs3-server.sh	(revision 15131)
@@ -1,4 +1,6 @@
 #!/bin/sh
 serverlang=en
+
+java_min_version=1.4.0_00
 
 echo "Greenstone 3 Server"
@@ -24,6 +26,6 @@
 fi
 
+# Setup Greenstone3, unless it has already been done
 if [ -z "$GSDL3SRCHOME" ]; then 
-  # Setup Greenstone3, unless it has already been done
   pushd $gsdl3path > /dev/null
   source gs3-setup.sh
@@ -33,6 +35,4 @@
 
 # JRE_HOME or JAVA_HOME must be set correctly to run this program
-if [ -n "$RUNJAVA" ]; then
-  "$RUNJAVA" -cp $CLASSPATH org.greenstone.server.Server $GSDL3SRCHOME 
-fi
+`search4j -m $java_min_version -e` org.greenstone.server.Server $GSDL3SRCHOME 
 
Index: /greenstone3/trunk/gs3-setup.sh
===================================================================
--- /greenstone3/trunk/gs3-setup.sh	(revision 15130)
+++ /greenstone3/trunk/gs3-setup.sh	(revision 15131)
@@ -1,12 +1,15 @@
 # if this file is executed, /bin/sh is used, as we don't start with #!
 # this should work under ash, bash, zsh, ksh, sh style shells.
-# make sure we are sourced, and not run
 
-export RUNJAVA=
-JRE_HOME=
-JAVA_HOME=
-CLASSPATH=$CLASSPATH
+#the purpose of this file is to check/set up the environment for greenstone3
+#sorts out
+#	- gsdl3home
+#	- java
+
+java_min_version=1.4.0_00
+
 
 function testSource(){
+
   if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
   # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
@@ -22,5 +25,5 @@
      echo "		$ source gs3-setup.sh"
      echo "	or"
-     echo "		$ . ./gs3-setup.sh"
+     echo "		$ . gs3-setup.sh"
      echo "	not"
      echo "		$ ./gs3-setup.sh"
@@ -33,153 +36,89 @@
     exit 1
   fi
+
 }
 
-function setGS3ENV(){
-   GSDL3SRCHOME=`pwd`
-   GSDL3HOME=$GSDL3SRCHOME/web
-   export GSDL3HOME
-   export GSDL3SRCHOME
-   GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-    # check for running bash under cygwin
-    if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
-        GSDLOS=windows
-    fi 
-    export GSDLOS
+function setGS3ENV() {
 
-    #change this if external tomcat
-    TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
+	echo "Setting up your environment for Greenstone3"
+	## main greenstone environment variables ##
+	GSDL3SRCHOME=`pwd`
+	GSDL3HOME=$GSDL3SRCHOME/web
+	export GSDL3HOME
+	export GSDL3SRCHOME
 
-    PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
-    export PATH
-    MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
-    export MANPATH
+	GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	# check for running bash under cygwin
+	if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
+		GSDLOS=windows
+	fi 
+	export GSDLOS
+	echo "  - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
 
-    CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
-     for JARFILE in $GSDL3SRCHOME/*.jar; do
-       CLASSPATH=$CLASSPATH:$JARFILE
-     done
-     for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
-        CLASSPATH=$CLASSPATH:$JARFILE
-     done
-     for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
-        CLASSPATH=$CLASSPATH:$JARFILE
-     done
-     for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
-        CLASSPATH=$CLASSPATH:$JARFILE
-     done    
-     for JARFILE in $GSDL3SRCHOME/build/*.jar; do
-       CLASSPATH=$CLASSPATH:$JARFILE
-     done
-     export CLASSPATH
-     LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
-     export LD_LIBRARY_PATH
-      ## for mac
-     DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
-     export DYLD_LIBRARY_PATH
+	#change this if external tomcat
+	TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
+
+
+	## adjustments to users (existing) environment ##
+	if [ `isinpath "$PATH" "$GSDL3SRCHOME/bin"` == "false" ]; then
+		PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
+		export PATH
+		MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
+		export MANPATH
+		echo "  - Adjusted PATH"
+	else
+		echo "  - PATH already correct"
+	fi
+
+	if [ `isinpath "$CLASSPATH" "$GSDL3HOME/WEB-INF/classes"` == "false" ]; then
+		CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
+		for JARFILE in $GSDL3SRCHOME/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done    
+		for JARFILE in $GSDL3SRCHOME/build/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		export CLASSPATH
+		echo "  - Adjusted CLASSPATH"
+	else
+		echo "  - CLASSPATH already correct"
+	fi
+
+	if [ `isinpath "$LD_LIBRARY_PATH" "$GSDL3SRCHOME/lib/jni"` == "false" ]; then
+		LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
+		export LD_LIBRARY_PATH
+		DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
+		export DYLD_LIBRARY_PATH
+		echo "  - Adjusted LD_LIBRARY_PATH"
+	else
+		echo "  - LD_LIBRARY_PATH already correct"
+	fi
+	echo
 }
 
-function setJAVAHOME(){
-    # see if we can find java
-    java="java"
-    jfound=1
-    jok=1
-    # if JREHOME, JRE_HOME is set, we'll use it to determine where java lives 
-    if [ "$JRE_HOME" != "" ]; then
-       java="$JRE_HOME/bin/java"
-       export JRE_HOME=$JRE_HOME
-    elif [ "$JREHOME" != "" ]; then
-       java="$JREHOME/bin/java"
-       export JRE_HOME=$JREHOME
-     # JAVAHOME or JAVA_HOME is set we'll use it to determine where java lives, otherwise
-     #  we just hope it's on the search path
-     elif [ "$JAVA_HOME" != "" ] ; then
-       java="$JAVA_HOME/bin/java"
-       export JAVA_HOME=$JAVA_HOME
-     elif [ "$JAVAHOME" != "" ] ; then
-       java="$JAVAHOME/bin/java"
-       export JAVA_HOME=$JAVAHOME
-    else
-        java=`which java 2> /dev/null`
-        if [ ! -x "$java" ]; then
-	    echo "Failed to locate Java. You must install a java runtime environment"
-	    echo "(version 1.4 or greater) before installing Greenstone 3."
-            pauseAndExit
-        else
-	  export JRE_HOME=`echo $java | sed -n 's/[\\\/]bin[\\\/]java$//p'`
-        fi
-   fi
-   checkJAVAHOME
+function checkJava() {
+	echo "Checking Java"
+  #check java
+  bin/search4j -m $java_min_version &> /dev/null
+  if [ "$?" != "0" ]; then
+  	echo "  - Failed to locate java ($java_min_version or greater)"
+		bin/search4j &> /dev/null
+		if [ "$?" == "0" ]; then echo "  (It looks like you hava java but it's too old)"; fi
+		echo "  - Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
+  	echo "    And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
+	else
+		echo "  - Found java at: `bin/search4j -m $java_min_version`"
+  fi
+	echo
 }
-
-function checkJAVAHOME(){
-# Make sure prerequisite environment variables are set
-  if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
-    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
-    echo "At least one of these environment variable is needed to run Greenstone3"  
-    pauseAndExit
-  else # check JRE_HOME
-      if [ -n "$JRE_HOME" ]; then
-         if [ ! -x "$JRE_HOME"/bin/java ]; then
-	    echo "JRE_HOME: $JRE_HOME" 
-	    echo "Couldn't find $JRE_HOME/bin/java"
-            echo "The JRE_HOME environment variable is not defined correctly"
-            echo "This environment variable is needed to run this program"
-	    pauseAndExit
-         else
-	   export RUNJAVA="$JRE_HOME"/bin/java 
-           checkVersion
-         fi  	
-      else
-          # check JAVA_HOME if JRE_HOME is not set   
-          if [ -n "$JAVA_HOME" ]; then
-              if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
-		echo "JAVA_HOME: $JAVA_HOME"  
-                echo "Couldn't find $JAVA_HOME/bin/java or $JAVA_HOME/bin/javac"
-                echo "The JAVA_HOME environment variable is not defined correctly"
-                echo "This environment variable is needed to run this program"
-                echo "NB: JAVA_HOME should point to a JDK not a JRE"
-		pauseAndExit
-	      else
-               export RUNJAVA="$JAVA_HOME"/bin/java
-               checkVersion
-              fi
-           fi
-        fi
-  fi
-}
-
-function checkVersion(){
-if [ $jfound -eq 1 ]; then
-    javaversion=`$RUNJAVA -version 2>&1 | sed -n 's/^java version \"\(.*\)\"/\1/p'`
-    jvmajor=`echo $javaversion | sed -n 's/^\([0-9]*\).*$/\1/p'`
-    jvminor=`echo $javaversion | sed -n 's/^[0-9]*\.\([0-9]*\).*$/\1/p'`
-    
-    if [ $jvmajor -lt 1 ] ; then
-	jok=0
-    fi
-    if [ $jvmajor -eq 1 ] && [ $jvminor -lt 4 ] ; then
-	jok=0
-    fi
-fi
-
-if [ $jfound -eq 1 ] && [ $jok -eq 0 ] ; then
-    echo "The version of the java runtime environment you have installed is too"
-    echo "old to run Greenstone 3. Please install a new version of the JRE (version"
-    echo "1.4 or newer) and rerun this installation."
-    export RUNJAVA=
-    pauseAndExit
-else
-    if [ -n "$JRE_HOME" ]; then
-     echo "JRE_HOME: $JRE_HOME" 
-     export PATH="$JRE_HOME"\bin:$PATH
-    fi
-    if [ -n "$JAVA_HOME" ]; then
-     echo "JAVA_HOME: $JAVA_HOME"
-     export PATH="$JAVA_HOME"\bin:$PATH
-    fi
-    echo "Your environment has successfully been set up to run Greenstone3"
-fi
-}
-
 
 function pauseAndExit(){
@@ -188,7 +127,16 @@
 }
 
+function isinpath() {
+	for file in `echo $1 | sed 's/:/ /g'`; do
+		if [ "$file" == "$2" ]; then
+			echo true
+			return
+		fi
+	done
+	echo false
+}
+
+echo
 testSource
 setGS3ENV
-setJAVAHOME
-
-
+checkJava
