source: main/trunk/gli/findjava.sh@ 33005

Last change on this file since 33005 was 33005, checked in by davidb, 5 years ago

When testing on Peyman's Mac, findjava.sh was locating the system installed JDK over the custom JDK even though JAVA_HOME was set.

  • Property svn:executable set to *
File size: 7.5 KB
Line 
1# We will already be in the correct folder (GLI folder), which would
2# contain a compiled up search4j if this GLI is part of an installation.
3# If a search4j executable is not there, then it means this is an SVN checkout.
4# In such a case, it's up to the user checking things out to ensure JAVA_HOME
5# is set and moreover points to the correct version of the Java.
6
7# Function to check if any JAVA_HOME is set and if so, try using that
8function try_java {
9 MIN_DISPLAY_VERSION=${1};
10
11 if [ "x$JAVA_HOME" = "x" -o ! -f "$JAVA_HOME/bin/java" ]; then
12 no_java "$MIN_DISPLAY_VERSION"
13 return $?
14 else
15 # There is a JAVA_HOME already set, we're going to try using that
16 javapath="$JAVA_HOME/bin/java"
17 javahome="$JAVA_HOME"
18 # Print a warning that we're going to use whatever JAVA_HOME is set (fingers crossed)
19 if [ "x$gslang" = "x" -o "$gslang" = "en" ]; then
20 echo
21 echo "***************************************************************************"
22 echo "WARNING: "
23 echo "Java Runtime not bundled with this Greenstone installation."
24 echo "Using JAVA_HOME: $JAVA_HOME"
25 echo "(NOTE: this needs to be $MIN_DISPLAY_VERSION or higher.)"
26 echo "***************************************************************************"
27 echo
28 fi
29 echo "Java:"
30 echo $javapath
31 echo
32 return 0
33 fi
34}
35
36function no_java {
37 MIN_DISPLAY_VERSION=${1};
38
39 echo
40 if [ "$gslang" = "es" ]; then
41 echo "No se pudo localizar una versión apropiada de Java. Usted deberá "
42 echo "instalar un Ambiente de Ejecución Java (versión $MIN_DISPLAY_VERSION o superior) "
43 echo "antes de correr la Interfaz de la $PROGNAME."
44 elif [ "$gslang" = "fr" ]; then
45 echo "Une version adéquate de Java n'a pas pu être localisée."
46 echo "Vous devez installer un Java Runtime Environment (version $MIN_DISPLAY_VERSION ou"
47 echo "supérieur) avant de démarrer $PROGNAME."
48 echo "Si vous avez Java installé sur votre ordinateur veuillez vérifier la variable"
49 echo "d'environnement JAVA_HOME."
50 elif [ "$gslang" = "ru" ]; then
51 echo "îÅ ÕÄÁÌÏÓØ ÏÐÒÅÄÅÌÉÔØ ÍÅÓÔÏÎÁÈÏÖÄÅÎÉÅ ÓÏÏÔ×ÅÔÓÔ×ÕÀÝÅÊ ×ÅÒÓÉÉ Java."
52 echo "÷Ù ÄÏÌÖÎÙ ÕÓÔÁÎÏ×ÉÔØ Java Runtime Environment (×ÅÒÓÉÀ $MIN_DISPLAY_VERSION ÉÌÉ ×ÙÛÅ)"
53 echo "ÐÅÒÅÄ ××ÏÄÏÍ ÂÉÂÌÉÏÔÅÞÎÏÇÏ $PROGNAME."
54 else
55 echo "Failed to locate an appropriate version of Java. You must install a"
56 echo "Java Runtime Environment (version $MIN_DISPLAY_VERSION or greater) before running the"
57 echo "$PROGNAME."
58 echo "If you have Java installed on your machine please set the environment variable JAVA_HOME."
59 fi
60 return 1
61}
62
63function set_java_exec {
64 SEARCH4J_EXECUTABLE=${1};
65 MINIMUM_JAVA_VERSION=${2};
66 MIN_DISPLAY_VERSION=${3};
67
68 # Give search4j a hint to find Java depending on the platform
69 # we now include a JRE with Mac (Mountain) Lion, because from Yosemite onwards there's no system Java on Macs
70 HINT=`cd "$GSDLHOME";pwd`/packages/jre
71
72 # we can't use boolean operator -a to do the AND, since it doesn't "short-circuit" if the first test fails
73 # see http://www.tldp.org/LDP/abs/html/comparison-ops.html
74 if [ "$GSDLOS" = "darwin" ] && [ ! -d "$HINT" ]; then
75 # http://java.dzone.com/articles/java-findingsetting
76 # explains that /usr/libexec/java_home will print the default JDK
77 # regardless of which Mac OS we're on. Tested on Maverick, Lion, Leopard
78 # (run `/usr/libexec/java_home -v 1.7` to find a specific version)
79
80 # run silently in case no system java installed, as it will result in a confusing message about there being no java
81 # when we're still searching for java
82 if [ "x$JAVA_HOME" != "x" ]; then
83 HINT="$JAVA_HOME"
84 else
85 #HINT=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
86 #/System/Library/Frameworks/JavaVM.framework/Home
87
88 macHINT=`/usr/libexec/java_home 2>&1`
89 status=$?
90 # if no java installed, then HINT will contain:
91 # Unable to find any JVMs matching version "(null)".
92 # No Java runtime present, try --request to install.
93 # and the status of running /usr/libexec/java_home will not be 0 but 1:
94 if [ "$status" = "0" ]; then
95 HINT=$macHINT
96 else
97 echo "No system Java on this mac..."
98 fi
99 fi
100 fi
101
102 javapath="`"$SEARCH4J_EXECUTABLE" -e -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
103 javahome="`"$SEARCH4J_EXECUTABLE" -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
104
105 if [ "$?" != "0" ]; then
106
107 OLDVER="`"$SEARCH4J_EXECUTABLE" -v -p "$HINT"`"
108
109 if [ "$?" = "0" ]; then
110
111 if [ "$gslang" = "es" ]; then
112 echo "La versión del Ambiente de Ejecución Java (JRE por sus siglas en "
113 echo "inglés) que usted tiene instalada es demasiado vieja para ejecutar "
114 echo "la Interfaz de la $PROGNAME. Por favor instale "
115 echo "una nueva versión del Ambiente de Ejecución Java (versión $MIN_DISPLAY_VERSION o "
116 echo "posterior) y ejecute nuevamente este guión."
117 elif [ "$gslang" = "fr" ]; then
118 echo "La version de Java Runtime Environment que vous avez installée est"
119 echo "trop vielle pour faire fonctionner $PROGNAME."
120 echo "Veuillez installer une nouvelle version du JRE (version $MIN_DISPLAY_VERSION ou plus"
121 echo "récente) et redémarrez le script."
122 elif [ "$gslang" = "ru" ]; then
123 echo "÷ÅÒÓÉÑ Java Runtime Environment, ËÏÔÏÒÕÀ ÷Ù ÕÓÔÁÎÏ×ÉÌÉ, ÏÞÅÎØ ÓÔÁÒÁ,"
124 echo "ÞÔÏÂÙ ÕÐÒÁ×ÌÑÔØ ÂÉÂÌÉÏÔÅÞÎÙÍ $PROGNAME. ðÏÖÁÌÕÊÓÔÁ, "
125 echo "ÕÓÔÁÎÏ×ÉÔÅ ÎÏ×ÕÀ ×ÅÒÓÉÀ JRE (×ÅÒÓÉÀ $MIN_DISPLAY_VERSION ÉÌÉ ÂÏÌÅÅ ÎÏ×ÕÀ) É"
126 echo "ÐÅÒÅÕÓÔÁÎÏ×ÉÔÅ ÜÔÏÔ ÓËÒÉÐÔ"
127 else
128 echo "The version of the Java Runtime Environment you have installed ($OLDVER)"
129 echo "is too old to run the $PROGNAME. Please install a new"
130 echo "version of the JRE (version $MIN_DISPLAY_VERSION or newer) and rerun this script."
131 fi
132 return 1
133
134 else
135 no_java "$MIN_DISPLAY_VERSION"
136 return $?
137 fi
138
139 fi
140 echo "Java:"
141 echo $javapath
142 echo
143 return 0
144}
145
146
147## ---- Check Java ----
148# Some users may set this line manually
149#JAVA_HOME=
150gslang=$1
151PROGNAME=$2
152MINIMUM_JAVA_VERSION=1.4.0_00
153MIN_DISPLAY_VERSION=1.4
154
155# sus out search4j
156# first look for compiled search4j executable inside the current folder
157if [ -x search4j ]; then
158 SEARCH4J_EXECUTABLE=search4j
159elif [ -x "$GSDLHOME/bin/$GSDLOS/search4j" ]; then
160 SEARCH4J_EXECUTABLE="$GSDLHOME/bin/$GSDLOS/search4j"
161elif [ -x "$GSDL3SRCHOME/bin/$GSDLOS/search4j" ]; then
162 SEARCH4J_EXECUTABLE="$GSDL3SRCHOME/bin/search4j"
163elif [ -x "../bin/$GSDLOS/search4j" ]; then
164 SEARCH4J_EXECUTABLE=../bin/$GSDLOS/search4j
165elif [ -x "../bin/search4j" ]; then
166 SEARCH4J_EXECUTABLE=../bin/search4j
167else
168 echo "Couldn't determine the location of the search4j executable"
169 echo "If you are running Greenstone2"
170 echo " * check GSDLHOME is set"
171 echo " * check bin/$GSDLOS/search4j exists"
172 echo " * check bin/$GSDLOS/search4j is executable"
173 echo "If you are running Greenstone3"
174 echo " * check GSDL3SRCHOME is set"
175 echo " * check bin/search4j exists"
176 echo " * check bin/search4j is executable"
177 echo " * try running 'ant compile-search4j'"
178fi
179
180# Now run set_java_exec with search4j if we found one, else try javahome
181if [ "x$SEARCH4J_EXECUTABLE" != "x" ]; then
182 set_java_exec "$SEARCH4J_EXECUTABLE" "$MINIMUM_JAVA_VERSION" "$MIN_DISPLAY_VERSION"
183 retval=$?
184else
185 try_java "$MIN_DISPLAY_VERSION"
186 retval=$?
187fi
188return $retval
Note: See TracBrowser for help on using the repository browser.