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

Last change on this file since 34259 was 34259, checked in by ak19, 4 years ago

Related to commit 34258. Equivalent changes for linux/mac: when running a standalone client-gli installation, if there's a packages/OS/jre (as for running GS3/GLI, this JRE may not get used on Mac as this comes preinstalled with Java) and if there's a bin/OS/search4j, client-gli.sh and findjava.sh will now use the path to a jre inside the standalone client-gli as hint for a bundled search4j to locate an appropriate java.

  • Property svn:executable set to *
File size: 7.8 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 if [ "x$GSDL3SRCHOME" != "x" ]; then
71 HINT=`cd "$GSDL3SRCHOME";pwd`/packages/jre
72 elif [ "x$GLIHOME" != "x" ]; then
73 HINT=`cd "$GLIHOME";pwd`/packages/$GSDLOS/jre
74 else
75 HINT=`cd "$GSDLHOME";pwd`/packages/jre
76 fi
77
78 # we can't use boolean operator -a to do the AND, since it doesn't "short-circuit" if the first test fails
79 # see http://www.tldp.org/LDP/abs/html/comparison-ops.html
80 if [ "$GSDLOS" = "darwin" ] && [ ! -d "$HINT" ]; then
81 # http://java.dzone.com/articles/java-findingsetting
82 # explains that /usr/libexec/java_home will print the default JDK
83 # regardless of which Mac OS we're on. Tested on Maverick, Lion, Leopard
84 # (run `/usr/libexec/java_home -v 1.7` to find a specific version)
85
86 # run silently in case no system java installed, as it will result in a confusing message about there being no java
87 # when we're still searching for java
88 if [ "x$JAVA_HOME" != "x" ]; then
89 HINT="$JAVA_HOME"
90 else
91 #HINT=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
92 #/System/Library/Frameworks/JavaVM.framework/Home
93
94 macHINT=`/usr/libexec/java_home 2>&1`
95 status=$?
96 # if no java installed, then HINT will contain:
97 # Unable to find any JVMs matching version "(null)".
98 # No Java runtime present, try --request to install.
99 # and the status of running /usr/libexec/java_home will not be 0 but 1:
100 if [ "$status" = "0" ]; then
101 HINT=$macHINT
102 else
103 echo "No system Java on this mac..."
104 fi
105 fi
106 fi
107
108 javapath="`"$SEARCH4J_EXECUTABLE" -e -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
109 javahome="`"$SEARCH4J_EXECUTABLE" -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
110
111 if [ "$?" != "0" ]; then
112
113 OLDVER="`"$SEARCH4J_EXECUTABLE" -v -p "$HINT"`"
114
115 if [ "$?" = "0" ]; then
116
117 if [ "$gslang" = "es" ]; then
118 echo "La versión del Ambiente de Ejecución Java (JRE por sus siglas en "
119 echo "inglés) que usted tiene instalada es demasiado vieja para ejecutar "
120 echo "la Interfaz de la $PROGNAME. Por favor instale "
121 echo "una nueva versión del Ambiente de Ejecución Java (versión $MIN_DISPLAY_VERSION o "
122 echo "posterior) y ejecute nuevamente este guión."
123 elif [ "$gslang" = "fr" ]; then
124 echo "La version de Java Runtime Environment que vous avez installée est"
125 echo "trop vielle pour faire fonctionner $PROGNAME."
126 echo "Veuillez installer une nouvelle version du JRE (version $MIN_DISPLAY_VERSION ou plus"
127 echo "récente) et redémarrez le script."
128 elif [ "$gslang" = "ru" ]; then
129 echo "÷ÅÒÓÉÑ Java Runtime Environment, ËÏÔÏÒÕÀ ÷Ù ÕÓÔÁÎÏ×ÉÌÉ, ÏÞÅÎØ ÓÔÁÒÁ,"
130 echo "ÞÔÏÂÙ ÕÐÒÁ×ÌÑÔØ ÂÉÂÌÉÏÔÅÞÎÙÍ $PROGNAME. ðÏÖÁÌÕÊÓÔÁ, "
131 echo "ÕÓÔÁÎÏ×ÉÔÅ ÎÏ×ÕÀ ×ÅÒÓÉÀ JRE (×ÅÒÓÉÀ $MIN_DISPLAY_VERSION ÉÌÉ ÂÏÌÅÅ ÎÏ×ÕÀ) É"
132 echo "ÐÅÒÅÕÓÔÁÎÏ×ÉÔÅ ÜÔÏÔ ÓËÒÉÐÔ"
133 else
134 echo "The version of the Java Runtime Environment you have installed ($OLDVER)"
135 echo "is too old to run the $PROGNAME. Please install a new"
136 echo "version of the JRE (version $MIN_DISPLAY_VERSION or newer) and rerun this script."
137 fi
138 return 1
139
140 else
141 no_java "$MIN_DISPLAY_VERSION"
142 return $?
143 fi
144
145 fi
146 echo "Java:"
147 echo $javapath
148 echo
149 return 0
150}
151
152
153## ---- Check Java ----
154# Some users may set this line manually
155#JAVA_HOME=
156gslang=$1
157PROGNAME=$2
158MINIMUM_JAVA_VERSION=1.4.0_00
159MIN_DISPLAY_VERSION=1.4
160
161echo "### GLIHOME: $GLIHOME"
162# sus out search4j
163# first look for compiled search4j executable inside the current folder
164if [ -x search4j ]; then
165 SEARCH4J_EXECUTABLE=search4j
166elif [ -x "$GSDLHOME/bin/$GSDLOS/search4j" ]; then
167 SEARCH4J_EXECUTABLE="$GSDLHOME/bin/$GSDLOS/search4j"
168elif [ -x "$GSDL3SRCHOME/bin/$GSDLOS/search4j" ]; then
169 SEARCH4J_EXECUTABLE="$GSDL3SRCHOME/bin/search4j"
170elif [ -x "../bin/$GSDLOS/search4j" ]; then
171 SEARCH4J_EXECUTABLE=../bin/$GSDLOS/search4j
172elif [ -x "../bin/search4j" ]; then
173 SEARCH4J_EXECUTABLE=../bin/search4j
174elif [ "x$GLIHOME" != "x" ] && [ -x "$GLIHOME/bin/$GSDLOS/search4j" ]; then
175 SEARCH4J_EXECUTABLE=$GLIHOME/bin/$GSDLOS/search4j
176else
177 echo "Couldn't determine the location of the search4j executable"
178 echo "If you are running Greenstone2"
179 echo " * check GSDLHOME is set"
180 echo " * check bin/$GSDLOS/search4j exists"
181 echo " * check bin/$GSDLOS/search4j is executable"
182 echo "If you are running Greenstone3"
183 echo " * check GSDL3SRCHOME is set"
184 echo " * check bin/search4j exists"
185 echo " * check bin/search4j is executable"
186 echo " * try running 'ant compile-search4j'"
187fi
188
189# Now run set_java_exec with search4j if we found one, else try javahome
190if [ "x$SEARCH4J_EXECUTABLE" != "x" ]; then
191 set_java_exec "$SEARCH4J_EXECUTABLE" "$MINIMUM_JAVA_VERSION" "$MIN_DISPLAY_VERSION"
192 retval=$?
193else
194 try_java "$MIN_DISPLAY_VERSION"
195 retval=$?
196fi
197return $retval
Note: See TracBrowser for help on using the repository browser.