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

Last change on this file since 28829 was 28829, checked in by ak19, 10 years ago

In the two Mac mavericks tested, java JDK was found in a different location. Furthermore, the JDK version numbers in the jdk installation folder need not be consistent. However, the means of finding out what javahome is, was consistent on Maverick. The java HINT that's set for search4j now goes through these steps to work out what the JAVAHOME hint out to be.

  • Property svn:executable set to *
File size: 7.3 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 intalled 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 if [ "$GSDLOS" = "linux" ]; then
70 HINT=`cd "$GSDLHOME";pwd`/packages/jre
71 elif [ "$GSDLOS" = "darwin" ]; then
72 osversion=`uname -r | sed 's/\..*$//'`;
73 # mac maverick is version 13
74 if [ $osversion -ge 13 ] ; then
75 # To work out java:
76 # 1. run "which java", which for example prints /usr/bin/java
77 # 2a. then do "ls -la" on that. The result is for example
78 # lrwxr-xr-x 1 root wheel 74 20 Jan 15:08 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
79 # 2b. remove everything before the symlink portion (before the "-> "), to get
80 # /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
81 # 3. then suffix "_home" to it, to get
82 # /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home
83 # 4. Then run this executable, which will tell you JAVA_HOME, e.g.
84 # /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
85
86 whichjava=`which java`;
87 symlink=`ls -la $whichjava | sed 's/[^>]*> //'`
88 javahome=$symlink"_home"
89 HINT=`$javahome`
90 else
91 HINT=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
92 #/System/Library/Frameworks/JavaVM.framework/Home
93 fi
94
95 fi
96
97 javapath="`"$SEARCH4J_EXECUTABLE" -e -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
98 javahome="`"$SEARCH4J_EXECUTABLE" -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
99
100 if [ "$?" != "0" ]; then
101
102 OLDVER="`"$SEARCH4J_EXECUTABLE" -v -p "$HINT"`"
103
104 if [ "$?" = "0" ]; then
105
106 if [ "$gslang" = "es" ]; then
107 echo "La versión del Ambiente de Ejecución Java (JRE por sus siglas en "
108 echo "inglés) que usted tiene instalada es demasiado vieja para ejecutar "
109 echo "la Interfaz de la $PROGNAME. Por favor instale "
110 echo "una nueva versión del Ambiente de Ejecución Java (versión $MIN_DISPLAY_VERSION o "
111 echo "posterior) y ejecute nuevamente este guión."
112 elif [ "$gslang" = "fr" ]; then
113 echo "La version de Java Runtime Environment que vous avez installée est"
114 echo "trop vielle pour faire fonctionner $PROGNAME."
115 echo "Veuillez installer une nouvelle version du JRE (version $MIN_DISPLAY_VERSION ou plus"
116 echo "récente) et redémarrez le script."
117 elif [ "$gslang" = "ru" ]; then
118 echo "÷ÅÒÓÉÑ Java Runtime Environment, ËÏÔÏÒÕÀ ÷Ù ÕÓÔÁÎÏ×ÉÌÉ, ÏÞÅÎØ ÓÔÁÒÁ,"
119 echo "ÞÔÏÂÙ ÕÐÒÁ×ÌÑÔØ ÂÉÂÌÉÏÔÅÞÎÙÍ $PROGNAME. ðÏÖÁÌÕÊÓÔÁ, "
120 echo "ÕÓÔÁÎÏ×ÉÔÅ ÎÏ×ÕÀ ×ÅÒÓÉÀ JRE (×ÅÒÓÉÀ $MIN_DISPLAY_VERSION ÉÌÉ ÂÏÌÅÅ ÎÏ×ÕÀ) É"
121 echo "ÐÅÒÅÕÓÔÁÎÏ×ÉÔÅ ÜÔÏÔ ÓËÒÉÐÔ"
122 else
123 echo "The version of the Java Runtime Environment you have installed ($OLDVER)"
124 echo "is too old to run the $PROGNAME. Please install a new"
125 echo "version of the JRE (version $MIN_DISPLAY_VERSION or newer) and rerun this script."
126 fi
127 return 1
128
129 else
130 no_java "$MIN_DISPLAY_VERSION"
131 return $?
132 fi
133
134 fi
135 echo "Java:"
136 echo $javapath
137 echo
138 return 0
139}
140
141
142## ---- Check Java ----
143# Some users may set this line manually
144#JAVA_HOME=
145gslang=$1
146PROGNAME=$2
147MINIMUM_JAVA_VERSION=1.4.0_00
148MIN_DISPLAY_VERSION=1.4
149
150# sus out search4j
151# first look for compiled search4j executable inside the current folder
152if [ -x search4j ]; then
153 SEARCH4J_EXECUTABLE=search4j
154elif [ -x "$GSDLHOME/bin/$GSDLOS/search4j" ]; then
155 SEARCH4J_EXECUTABLE="$GSDLHOME/bin/$GSDLOS/search4j"
156elif [ -x "$GSDL3SRCHOME/bin/$GSDLOS/search4j" ]; then
157 SEARCH4J_EXECUTABLE="$GSDL3SRCHOME/bin/search4j"
158elif [ -x "../bin/$GSDLOS/search4j" ]; then
159 SEARCH4J_EXECUTABLE=../bin/$GSDLOS/search4j
160elif [ -x "../bin/search4j" ]; then
161 SEARCH4J_EXECUTABLE=../bin/search4j
162else
163 echo "Couldn't determine the location of the search4j executable"
164 echo "If you are running Greenstone2"
165 echo " * check GSDLHOME is set"
166 echo " * check bin/$GSDLOS/search4j exists"
167 echo " * check bin/$GSDLOS/search4j is executable"
168 echo "If you are running Greenstone3"
169 echo " * check GSDL3SRCHOME is set"
170 echo " * check bin/search4j exists"
171 echo " * check bin/search4j is executable"
172 echo " * try running 'ant compile-search4j'"
173fi
174
175# Now run set_java_exec with search4j if we found one, else try javahome
176if [ "x$SEARCH4J_EXECUTABLE" != "x" ]; then
177 set_java_exec "$SEARCH4J_EXECUTABLE" "$MINIMUM_JAVA_VERSION" "$MIN_DISPLAY_VERSION"
178 retval=$?
179else
180 try_java "$MIN_DISPLAY_VERSION"
181 retval=$?
182fi
183return $retval
Note: See TracBrowser for help on using the repository browser.