1 | # if this file is executed, /bin/sh is used, as we don't start with #!
|
---|
2 | # this should work under ash, bash, zsh, ksh, sh style shells.
|
---|
3 |
|
---|
4 | #the purpose of this file is to check/set up the environment for greenstone3
|
---|
5 | #sorts out:
|
---|
6 | # - gsdl3home
|
---|
7 | # - java
|
---|
8 |
|
---|
9 | # java_min_version gets passed to search4j as the minimum java version
|
---|
10 | java_min_version=1.5.0_00
|
---|
11 | DEBUG=false
|
---|
12 |
|
---|
13 | function testSource(){
|
---|
14 |
|
---|
15 | if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
|
---|
16 | # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
|
---|
17 | # One exception is zsh has an option to set it temporarily to the script name
|
---|
18 | if test -z "$ZSH_NAME" ; then
|
---|
19 | # we aren't using zsh
|
---|
20 | gsdl_not_sourced=true
|
---|
21 | fi
|
---|
22 | fi
|
---|
23 |
|
---|
24 | if test -n "$gsdl_not_sourced" ; then
|
---|
25 | echo " Error: Make sure you source this script, not execute it. Eg:"
|
---|
26 | echo " $ source gs3-setup.sh"
|
---|
27 | echo " or"
|
---|
28 | echo " $ . gs3-setup.sh"
|
---|
29 | echo " not"
|
---|
30 | echo " $ ./gs3-setup.sh"
|
---|
31 | unset gsdl_not_sourced
|
---|
32 | exit 1
|
---|
33 | fi
|
---|
34 |
|
---|
35 | if test ! -f gs3-setup.sh ; then
|
---|
36 | echo "You must source the script from within the Greenstone home directory"
|
---|
37 | return 1
|
---|
38 | fi
|
---|
39 | return 0
|
---|
40 | }
|
---|
41 |
|
---|
42 | # if GSDL3SRCHOME is set, then we assume that we have already sourced the
|
---|
43 | # script so don't do it again. UNLESS, GSDL3SRCHOME doesn't match the
|
---|
44 | # current directory in which case it was a different gs3 installation, so lets
|
---|
45 | # do it now.
|
---|
46 | function testAlreadySourced() {
|
---|
47 | if [ ! -z "$GSDL3SRCHOME" ]; then
|
---|
48 | localgs3sourcehome="`pwd`"
|
---|
49 | if [ "$GSDL3SRCHOME" = "$localgs3sourcehome" ]; then
|
---|
50 | echo "Your environment is already set up for Greenstone3"
|
---|
51 | return 1
|
---|
52 | fi
|
---|
53 | echo "Your environment was set up for Greenstone 3 in $GSDL3SRCHOME."
|
---|
54 | echo "Overwriting that set up for the current Greenstone 3 in $localgs3sourcehome"
|
---|
55 | fi
|
---|
56 | return 0
|
---|
57 | }
|
---|
58 |
|
---|
59 | function setGS3ENV() {
|
---|
60 |
|
---|
61 | echo "Setting up your environment for Greenstone3"
|
---|
62 | ## main greenstone environment variables ##
|
---|
63 | GSDL3SRCHOME="`pwd`"
|
---|
64 | GSDL3HOME="$GSDL3SRCHOME/web"
|
---|
65 | export GSDL3HOME
|
---|
66 | export GSDL3SRCHOME
|
---|
67 |
|
---|
68 | if test "x$GSDLOS" = "x" ; then
|
---|
69 | GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
---|
70 | # check for running bash under cygwin
|
---|
71 | if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
|
---|
72 | GSDLOS=windows
|
---|
73 | fi
|
---|
74 | fi
|
---|
75 | export GSDLOS
|
---|
76 | echo " - Exported GSDL3HOME=$GSDL3HOME"
|
---|
77 | echo " GSDL3SRCHOME=$GSDL3SRCHOME"
|
---|
78 | echo " GSDLOS=$GSDLOS"
|
---|
79 |
|
---|
80 | #change this if external tomcat
|
---|
81 | TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
|
---|
82 |
|
---|
83 | ## adjustments to users (existing) environment ##
|
---|
84 |
|
---|
85 | #PATH
|
---|
86 | addtopath PATH "$GSDL3SRCHOME/bin/script"
|
---|
87 | addtopath PATH "$GSDL3SRCHOME/bin"
|
---|
88 | echo " - Adjusted PATH"
|
---|
89 | if [ "$DEBUG" = "true" ]; then
|
---|
90 | echo " = $PATH"
|
---|
91 | fi
|
---|
92 |
|
---|
93 | #MANPATH
|
---|
94 | addtopath MANPATH "$GSDL3SRCHOME/doc/man"
|
---|
95 | echo " - Adjusted MANPATH"
|
---|
96 | if [ "$DEBUG" = "true" ]; then
|
---|
97 | echo " = $MANPATH"
|
---|
98 | fi
|
---|
99 |
|
---|
100 | #CLASSPATH
|
---|
101 | addtopath CLASSPATH "."
|
---|
102 | addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
|
---|
103 | addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
|
---|
104 | addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
|
---|
105 |
|
---|
106 | # Greenstone JAR files
|
---|
107 | for JARFILE in "$GSDL3HOME/WEB-INF/lib"/*.jar; do
|
---|
108 | addtopath CLASSPATH "$JARFILE"
|
---|
109 | done
|
---|
110 |
|
---|
111 | # Tomcat 5 jar files
|
---|
112 | if test -d "$TOMCAT_HOME"/common/endorsed ; then
|
---|
113 | for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
|
---|
114 | addtopath CLASSPATH "$JARFILE"
|
---|
115 | done
|
---|
116 | fi
|
---|
117 | # Tomcat 6 jar files
|
---|
118 | if test -d "$TOMCAT_HOME"/lib ; then
|
---|
119 | for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
|
---|
120 | addtopath CLASSPATH "$JARFILE"
|
---|
121 | done
|
---|
122 | fi
|
---|
123 |
|
---|
124 | #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
|
---|
125 | #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
|
---|
126 | # addtopath CLASSPATH "$JARFILE"
|
---|
127 | #done
|
---|
128 |
|
---|
129 | echo " - Adjusted CLASSPATH"
|
---|
130 | if [ "$DEBUG" = "true" ]; then
|
---|
131 | echo " = $CLASSPATH"
|
---|
132 | fi
|
---|
133 |
|
---|
134 | #LD_LIBRARY_PATH
|
---|
135 | addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
136 | addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
137 | echo " - Adjusted LD_LIBRARY_PATH"
|
---|
138 | if [ "$DEBUG" = "true" ]; then
|
---|
139 | echo " = $LD_LIBRARY_PATH"
|
---|
140 | fi
|
---|
141 |
|
---|
142 | echo " - Adjusted DYLD_LIBRARY_PATH"
|
---|
143 | if [ "$DEBUG" = "true" ]; then
|
---|
144 | echo " = $DYLD_LIBRARY_PATH"
|
---|
145 | fi
|
---|
146 |
|
---|
147 | #ImageMagick
|
---|
148 | #if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
|
---|
149 | # addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
|
---|
150 | # MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
|
---|
151 | # export MAGICK_HOME
|
---|
152 | # if test "$GSDLOS" = "linux"; then
|
---|
153 | # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
|
---|
154 | # elif test "$GSDLOS" = "darwin"; then
|
---|
155 | # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
|
---|
156 | # fi
|
---|
157 | # echo " - Setup ImageMagick"
|
---|
158 | #fi
|
---|
159 |
|
---|
160 | #Ghostscript
|
---|
161 | if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
|
---|
162 | addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
|
---|
163 | GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
|
---|
164 | export GS_LIB
|
---|
165 | GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
|
---|
166 | export GS_FONTPATH
|
---|
167 | echo " - Setup GhostScript"
|
---|
168 | fi
|
---|
169 |
|
---|
170 | #wvWare
|
---|
171 | # wvWare's environment is now set up by bin/script/wvware.pl
|
---|
172 | # The wvware.pl script can be called from the cmdline to perform wvware tasks.
|
---|
173 | # GLI calls gsConvert.pl which calls wvware.pl to similarly perform wvware tasks.
|
---|
174 | # if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
|
---|
175 | # if test "$GSDLOS" = "linux"; then
|
---|
176 | # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
|
---|
177 | # elif test "$GSDLOS" = "darwin"; then
|
---|
178 | # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
|
---|
179 | # fi
|
---|
180 | # echo " - Setup wvWare"
|
---|
181 | # fi
|
---|
182 |
|
---|
183 | }
|
---|
184 |
|
---|
185 | function checkJava() {
|
---|
186 |
|
---|
187 | # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs
|
---|
188 | BUNDLED_JRE="`pwd`/packages/jre"
|
---|
189 | HINT=$BUNDLED_JRE
|
---|
190 |
|
---|
191 | if [ "$GSDLOS" = "darwin" ]; then
|
---|
192 | # try $JAVA_HOME first, if it is set
|
---|
193 | if [ "$JAVA_HOME" != "" ] && [ -d "$JAVA_HOME" ]; then
|
---|
194 | HINT=$JAVA_HOME
|
---|
195 | elif [ ! -d "$HINT" ]; then
|
---|
196 | #we test for the existence of bundled_jre - will be present in binary release. Use that if it is there as we know that it works with GS
|
---|
197 | # but if its not there, try the following:
|
---|
198 | # this will print out the path to java
|
---|
199 | HINT=`/usr/libexec/java_home`
|
---|
200 | # old code used as fallback:
|
---|
201 | # But actually this is not valid for Mojave and Catalina
|
---|
202 | if [ ! -d "$HINT" ]; then
|
---|
203 | HINT=/System/Library/Frameworks/JavaVM.framework/Home
|
---|
204 | fi
|
---|
205 | fi
|
---|
206 | fi
|
---|
207 |
|
---|
208 | if [ "$DEBUG" = "true" ]; then echo "**********************************************"; fi
|
---|
209 |
|
---|
210 | # If the file utility exists, use it to determine the bitness of this GS3,
|
---|
211 | # particularly of this GS3's lib/jni/libgdbmjava.so/jnilib, since we prefer a matching java
|
---|
212 | # If any executable doesn't exist, the return value is 127.
|
---|
213 | # If file utility exists, then 0 is returned on successful execution, 1 is an error exit code
|
---|
214 | # Running file without arg returns 1 therefore.
|
---|
215 |
|
---|
216 | # Determine the bitness of this GS3 installation, by running:
|
---|
217 | # `file lib/jni/libgdbmjava.so/jnilib`
|
---|
218 | # Output:
|
---|
219 | # lib/jni/libgdbmjava.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
|
---|
220 | # dynamically linked, BuildID[sha1]=5ae42cf69275408bdce97697d69e9e6fd481420d, not stripped
|
---|
221 | # On 32-bit linux, the output will contain "lib/jni/libgdbmjava.so: ELF 32-bit ..."
|
---|
222 | # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
223 |
|
---|
224 | fileexists=`file 2&> /dev/null`
|
---|
225 |
|
---|
226 | TESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.so"
|
---|
227 | if test "$GSDLOS" = "darwin"; then
|
---|
228 | TESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.jnilib"
|
---|
229 | fi
|
---|
230 |
|
---|
231 | # Integer comparison, http://tldp.org/LDP/abs/html/comparison-ops.html
|
---|
232 | # can also use double brackets: if [[ $? > 1 ]]; then ...
|
---|
233 | if [ "$?" -gt "1" ]; then
|
---|
234 | if [ "$DEBUG" = "true" ]; then
|
---|
235 | echo " 'file' utility not found installed on this unix-based system."
|
---|
236 | echo " Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found."
|
---|
237 | fi
|
---|
238 | bitness=-1
|
---|
239 | elif [ ! -f "$TESTFILE" ]; then
|
---|
240 | # the file we want to test the bitness of, to determine GS3's bitness by, doesn't exist yet
|
---|
241 | echo " $TESTFILE is not found, unable to determine bitness of this Greenstone3"
|
---|
242 | bitness=-1
|
---|
243 | else
|
---|
244 | bitness=`file $TESTFILE`
|
---|
245 | if [[ $bitness = *"64-bit"* ]]; then
|
---|
246 | bitness=64
|
---|
247 | echo "The installed Greenstone is $bitness bit"
|
---|
248 | elif [[ $bitness = *"32-bit"* ]]; then
|
---|
249 | bitness=32
|
---|
250 | echo "The installed Greenstone is $bitness bit"
|
---|
251 | else
|
---|
252 | bitness=-1
|
---|
253 | echo "WARNING: Greenstone installation is of unknown bitness. \"$bitness\" is neither 32 nor 64 bit"
|
---|
254 | fi
|
---|
255 | fi
|
---|
256 | echo bitness = $bitness
|
---|
257 |
|
---|
258 | # If search4j is present, use it to locate a java.
|
---|
259 | # If search4j finds a Java, then:
|
---|
260 | # - If its bitness doesn't match and there's a bundled jre, use the bundled jre instead.
|
---|
261 | # - If its bitness doesn't match and there's no bundled jre, use the java found by search4j anyway,
|
---|
262 | # we'll print a warning about this bitness mismatch at the end
|
---|
263 |
|
---|
264 | javaset=false
|
---|
265 | if [ -x bin/search4j ] ; then
|
---|
266 | FOUNDJAVAHOME="`bin/search4j -d -p \"$HINT\" -m $java_min_version`"
|
---|
267 | javahome_retval=$?
|
---|
268 | FOUNDJREHOME="`bin/search4j -r -p \"$HINT\" -m $java_min_version`"
|
---|
269 | jrehome_retval=$?
|
---|
270 | fi
|
---|
271 |
|
---|
272 | # 1. check the bitness of any JDK java found by search4j, and use if appropriate
|
---|
273 | if [ "$javahome_retval" = "0" ]; then
|
---|
274 | setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
|
---|
275 | if [ "$?" = "0" ]; then javaset="true"; fi
|
---|
276 | fi
|
---|
277 |
|
---|
278 | # 2. check the bitness of any JRE java found by search4j, and use if appropriate
|
---|
279 | if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ]; then
|
---|
280 | setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
|
---|
281 | if [ "$?" = "0" ]; then javaset="true"; fi
|
---|
282 | fi
|
---|
283 |
|
---|
284 | # 3. check the bitness of any bundled JRE, and use if appropriate
|
---|
285 | # For linux, the bundled JRE ought to be of a bitness matching this OS.
|
---|
286 | if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ]; then
|
---|
287 | setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "bundled JRE"
|
---|
288 | if [ "$?" = "0" ]; then javaset="true"; fi
|
---|
289 | fi
|
---|
290 |
|
---|
291 |
|
---|
292 | # 4. None of the java found so far (via search4j, bundled_jre), if any, may have matched bitness wise
|
---|
293 | # So, fall back to using whichever is available in sequence anyway.
|
---|
294 | # We'll print a warning of bitness mismatch later
|
---|
295 |
|
---|
296 | if [ "$javaset" != "true" ]; then
|
---|
297 | # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present
|
---|
298 | if [ "$javahome_retval" = "0" ]; then
|
---|
299 | setupJavaAt "$FOUNDJAVAHOME" "JDK"
|
---|
300 | javaset=true
|
---|
301 | elif [ "$jrehome_retval" = "0" ]; then
|
---|
302 | setupJavaAt "$FOUNDJREHOME" "JRE"
|
---|
303 | javaset=true
|
---|
304 | elif [ -d "$BUNDLED_JRE" ]; then
|
---|
305 | # bundled JRE should be >= than minimum version of java required
|
---|
306 | setupJavaAt "$BUNDLED_JRE" "JRE"
|
---|
307 | javaset=true
|
---|
308 | fi
|
---|
309 | fi
|
---|
310 |
|
---|
311 | # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
|
---|
312 | if [ "$javaset" != "true" ]; then
|
---|
313 |
|
---|
314 | if [ -x bin/search4j ]; then
|
---|
315 |
|
---|
316 | # no suitable java could be found by search4j
|
---|
317 | echo " - ERROR: Failed to locate java $java_min_version or greater"
|
---|
318 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
319 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
320 |
|
---|
321 | else
|
---|
322 | # search4j wasn't present, and no bundled JRE, so check JAVA_HOME or JRE_HOME manually
|
---|
323 | #echo "*** Could not find an appropriate JDK or JRE java"
|
---|
324 | #echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment"
|
---|
325 | echo "Checking for Java explicitly set through environment variables"
|
---|
326 | if [ "$JAVA_HOME" != "" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ]; then
|
---|
327 | echo " - Using Java at $JAVA_HOME"
|
---|
328 | echo " - Detected Java version: `$JAVA_HOME/bin/java -version 2>&1 | head -n 1`"
|
---|
329 | echo " - Note that Greenstone requires Java 1.5 or greater"
|
---|
330 | # echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
331 | # echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
332 | # echo " (SVN users may still use java 1.4)"
|
---|
333 | elif [ "$JRE_HOME" != "" ] && [ "`which java`" = "$JRE_HOME/bin/java" ]; then
|
---|
334 | echo " - Using java at $JRE_HOME"
|
---|
335 | echo " - Detected Java version: `$JAVA_HOME/bin/java -version 2>&1 | head -n 1`"
|
---|
336 | echo " - Note that Greenstone requires Java 1.5 or greater"
|
---|
337 | # echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
338 | # echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
339 | # echo " (SVN users may still use java 1.4)"
|
---|
340 |
|
---|
341 | #failing all that, print a warning
|
---|
342 | else
|
---|
343 | #no suitable java exists
|
---|
344 | echo " - ERROR: Failed to locate java"
|
---|
345 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
346 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
347 | return
|
---|
348 | fi
|
---|
349 | fi
|
---|
350 | fi
|
---|
351 |
|
---|
352 | # If we know the bitness of this GS3 installation, then warn if there's a mismatch
|
---|
353 | # with the bitness of the Java found
|
---|
354 |
|
---|
355 | if [ "$bitness" != "-1" ]; then
|
---|
356 | if [ "$JAVA_HOME" != "" ]; then
|
---|
357 | JAVA_FOUND=$JAVA_HOME
|
---|
358 | elif [ "$JRE_HOME" != "" ]; then
|
---|
359 | JAVA_FOUND=$JRE_HOME
|
---|
360 | fi
|
---|
361 | checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness"
|
---|
362 | if [ "$?" = "1" ]; then
|
---|
363 | echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)"
|
---|
364 | echo "*** and the Java found at $JAVA_FOUND/bin/java"
|
---|
365 | echo "*** Continuing with this Java anyway:"
|
---|
366 | echo "*** This will only affect MG/MGPP collections for searching, and GDBM database collections"
|
---|
367 | echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java"
|
---|
368 | echo "*** Or recompile GS with your system Java:"
|
---|
369 | if [ "$JAVA_HOME" != "" ]; then
|
---|
370 | echo "*** JAVA_HOME at $JAVA_HOME"
|
---|
371 | else
|
---|
372 | echo "*** JRE_HOME at $JRE_HOME"
|
---|
373 | fi
|
---|
374 | fi
|
---|
375 | fi
|
---|
376 |
|
---|
377 | if [ "$DEBUG" = "true" ]; then echo "**********************************************"; fi
|
---|
378 |
|
---|
379 | }
|
---|
380 |
|
---|
381 | # http://www.linuxjournal.com/content/return-values-bash-functions
|
---|
382 | function setJavaIfOK {
|
---|
383 |
|
---|
384 | if [ "$DEBUG" = "true" ]; then echo "Testing java at $3"; fi
|
---|
385 |
|
---|
386 | DEBUG=$1
|
---|
387 | bitness=$2
|
---|
388 | PATHTOJAVA=$3
|
---|
389 | JDKorJRE=$4
|
---|
390 |
|
---|
391 | checkJavaBitnessAgainstGSBitness "$PATHTOJAVA" "$bitness"
|
---|
392 | check_status=$?
|
---|
393 |
|
---|
394 | isjavaset=false
|
---|
395 |
|
---|
396 | if [ "$check_status" = "0" ]; then
|
---|
397 | # http://tldp.org/LDP/abs/html/comparison-ops.html
|
---|
398 | if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ]; then
|
---|
399 | # java matches GS bitness
|
---|
400 | if [[ "$JDKorJRE" = *"bundled"* ]]; then
|
---|
401 | echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
|
---|
402 | else
|
---|
403 | echo " The detected $JDKorJRE at $PATHTOJAVA is a matching $bitness bit"
|
---|
404 | fi
|
---|
405 | fi
|
---|
406 | setupJavaAt "$PATHTOJAVA" "$JDKorJRE"
|
---|
407 | isjavaset=true
|
---|
408 |
|
---|
409 | elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ]; then
|
---|
410 | if [[ "$JDKorJRE" = *"bundled"* ]]; then
|
---|
411 | echo " The $JDKorJRE java is an incompatible bit architecture"
|
---|
412 | else
|
---|
413 | echo " The detected $JDKorJRE java is an incompatible bit architecture"
|
---|
414 | fi
|
---|
415 | fi
|
---|
416 |
|
---|
417 | if [ "$isjavaset" = "true" ]; then
|
---|
418 | return 0 # success
|
---|
419 | else
|
---|
420 | return 1
|
---|
421 | fi
|
---|
422 | }
|
---|
423 |
|
---|
424 | # if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
|
---|
425 | function checkJavaBitnessAgainstGSBitness() {
|
---|
426 | # if [ "$DEBUG" = "true" ]; then echo "Testing bitness of java found at $java_installation"; fi
|
---|
427 | java_installation="$1"
|
---|
428 | bitness="$2"
|
---|
429 |
|
---|
430 | # bitness can be -1 if the 'file' utility could not be found to determine bitness
|
---|
431 | # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully
|
---|
432 | if [ "$bitness" = "-1" ]; then
|
---|
433 | return 0
|
---|
434 | fi
|
---|
435 |
|
---|
436 | # now we can actually work out if the java install's bitness matches that of GS ($bitness)
|
---|
437 | # java -d32 -version should return 0 if the Java is 32 bit, and 1 (failure) if the Java is 64 bit.
|
---|
438 | # Likewise, java -d64 -version will return 0 if the Java is 64 bit, and 1 (failure) if the Java is 32 bit.
|
---|
439 | `$java_installation/bin/java -d$bitness -version 2> /dev/null`
|
---|
440 |
|
---|
441 | if [ "$?" = "0" ]; then
|
---|
442 | return 0
|
---|
443 | elif [ "$?" = "1" ]; then
|
---|
444 |
|
---|
445 | # Newer Java's don't support -d, so result to using 'file' to determin bitness of 'java' binary
|
---|
446 | java_bitness=`file $java_installation/bin/java`
|
---|
447 | if [[ $java_bitness = *"$bitness-bit"* ]]; then
|
---|
448 | return 0
|
---|
449 | else
|
---|
450 | return 1
|
---|
451 | fi
|
---|
452 | else
|
---|
453 | echo "*** Problem determining bitness of java using java at $java_installation"
|
---|
454 | return $?
|
---|
455 | fi
|
---|
456 | }
|
---|
457 |
|
---|
458 |
|
---|
459 | function setupJavaAt() {
|
---|
460 |
|
---|
461 | # check the second parameter if non-null
|
---|
462 | if [ -n "$2" ] && [ "$2" = "JRE" ]; then
|
---|
463 | export JRE_HOME="$1"
|
---|
464 | addtopath PATH "$JRE_HOME/bin"
|
---|
465 |
|
---|
466 | # ant needs a JAVA_HOME, so set that too, to the JRE
|
---|
467 | export JAVA_HOME="$JRE_HOME"
|
---|
468 |
|
---|
469 | BUNDLED_JRE="`pwd`/packages/jre"
|
---|
470 | if [[ "$JRE_HOME" = *"$BUNDLED_JRE"* ]]; then
|
---|
471 | msg="the bundled"
|
---|
472 | fi
|
---|
473 |
|
---|
474 | echo " - Exported JRE_HOME and JAVA_HOME to $msg $JRE_HOME"
|
---|
475 | else
|
---|
476 | export JAVA_HOME="$1"
|
---|
477 | addtopath PATH "$JAVA_HOME/bin"
|
---|
478 | echo " - Exported JAVA_HOME to $JAVA_HOME"
|
---|
479 | fi
|
---|
480 |
|
---|
481 |
|
---|
482 | }
|
---|
483 |
|
---|
484 | function pauseAndExit(){
|
---|
485 | echo -n "Please press any key to continue... "
|
---|
486 | read
|
---|
487 | }
|
---|
488 |
|
---|
489 | function isinpath() {
|
---|
490 | for file in `echo $1 | sed 's/:/ /g'`; do
|
---|
491 | if [ "$file" = "$2" ]; then
|
---|
492 | echo true
|
---|
493 | return
|
---|
494 | fi
|
---|
495 | done
|
---|
496 | echo false
|
---|
497 | }
|
---|
498 |
|
---|
499 | function addtopath() {
|
---|
500 | eval "PV=\$$1"
|
---|
501 | #echo "$1 += $2"
|
---|
502 | if [ "$PV" = "" ]; then
|
---|
503 | cmd="$1=\"$2\""
|
---|
504 | else
|
---|
505 | cmd="$1=\"$2:\$$1\""
|
---|
506 | fi
|
---|
507 | eval $cmd
|
---|
508 | eval "export $1"
|
---|
509 | }
|
---|
510 |
|
---|
511 | # Note: use return not exit from a sourced script otherwise it kills the shell
|
---|
512 | testSource
|
---|
513 | if [ "$?" = "1" ]; then
|
---|
514 | return
|
---|
515 | fi
|
---|
516 |
|
---|
517 | testAlreadySourced
|
---|
518 | if [ "$?" = "1" ]; then
|
---|
519 | return
|
---|
520 | fi
|
---|
521 |
|
---|
522 | setGS3ENV
|
---|
523 |
|
---|
524 | echo "done"
|
---|
525 |
|
---|
526 | if test -e gs2build/setup.bash ; then
|
---|
527 | echo ""
|
---|
528 | echo "Sourcing gs2build/setup.bash"
|
---|
529 | cd gs2build ; source setup.bash ; cd ..
|
---|
530 | fi
|
---|
531 |
|
---|
532 |
|
---|
533 | if test "x$gsopt_noexts" != "x1" ; then
|
---|
534 | if test -e ext ; then
|
---|
535 | for gsdl_ext in ext/* ; do
|
---|
536 | if [ -d $gsdl_ext ] ; then
|
---|
537 | cd $gsdl_ext > /dev/null
|
---|
538 | if test -e gs3-setup.sh ; then
|
---|
539 | source ./gs3-setup.sh
|
---|
540 | elif test -e setup.bash ; then
|
---|
541 | source ./setup.bash
|
---|
542 | fi
|
---|
543 | cd ../..
|
---|
544 | fi
|
---|
545 | done
|
---|
546 | fi
|
---|
547 | fi
|
---|
548 |
|
---|
549 | if test -e local ; then
|
---|
550 | if test -e local/gs3-setup.sh ; then
|
---|
551 | echo ""
|
---|
552 | echo "Sourcing local/gs3-setup.sh"
|
---|
553 | cd local ; source gs3-setup.sh ; cd ..
|
---|
554 | fi
|
---|
555 | fi
|
---|
556 |
|
---|
557 |
|
---|
558 | checkJava
|
---|
559 | echo ""
|
---|
560 |
|
---|
561 | #ant
|
---|
562 | ANT_VERSION=1.7.1
|
---|
563 | echo "Checking for Ant"
|
---|
564 | if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
|
---|
565 | ANT_HOME="$GSDL3SRCHOME/packages/ant"
|
---|
566 | export ANT_HOME
|
---|
567 | addtopath PATH "$ANT_HOME/bin"
|
---|
568 | echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
|
---|
569 | else
|
---|
570 | if [ "$ANT_HOME" != "" ]; then
|
---|
571 | addtopath PATH "$ANT_HOME/bin"
|
---|
572 | echo " - `ant -version`"
|
---|
573 | echo " - Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
574 | else
|
---|
575 | which ant &> /dev/null
|
---|
576 | if [ "$?" = "0" ]; then
|
---|
577 | echo " - System install ant detected"
|
---|
578 | echo " - `ant -version`"
|
---|
579 | echo " - Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
580 | else
|
---|
581 | echo " - WARNING: Failed to find 'ant'"
|
---|
582 | fi
|
---|
583 | fi
|
---|
584 | fi
|
---|
585 |
|
---|