source: main/trunk/greenstone3/gs3-setup.sh@ 36542

Last change on this file since 36542 was 36542, checked in by davidb, 20 months ago

indent return statements

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 21.9 KB
Line 
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
10java_min_version=1.8.0
11DEBUG=false
12
13testSource() {
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 " $ . ./gs3-setup.sh"
27 echo " or"
28 echo " $ source ./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.
46testAlreadySourced() {
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
59setGS3ENV() {
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:"
77 echo " GSDL3HOME = $GSDL3HOME"
78 echo " GSDL3SRCHOME = $GSDL3SRCHOME"
79 echo " GSDLOS = $GSDLOS"
80 echo ""
81
82 #change this if external tomcat
83 TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
84
85 ## adjustments to users (existing) environment ##
86
87 #PATH
88 addtopath PATH "$GSDL3SRCHOME/bin/script"
89 addtopath PATH "$GSDL3SRCHOME/bin"
90 echo " - Adjusted PATH"
91 if [ "$DEBUG" = "true" ] ; then
92 echo " = $PATH"
93 fi
94
95 #MANPATH
96 addtopath MANPATH "$GSDL3SRCHOME/doc/man"
97 echo " - Adjusted MANPATH"
98 if [ "$DEBUG" = "true" ] ; then
99 echo " = $MANPATH"
100 fi
101
102 #CLASSPATH
103 addtopath CLASSPATH "."
104 addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
105 addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
106 addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
107
108 # Greenstone JAR files
109 for JARFILE in "$GSDL3HOME/WEB-INF/lib"/*.jar; do
110 addtopath CLASSPATH "$JARFILE"
111 done
112
113 # Tomcat 5 jar files
114 if test -d "$TOMCAT_HOME"/common/endorsed ; then
115 for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
116 addtopath CLASSPATH "$JARFILE"
117 done
118 fi
119 # Tomcat 6 jar files
120 if test -d "$TOMCAT_HOME"/lib ; then
121 for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
122 addtopath CLASSPATH "$JARFILE"
123 done
124 fi
125
126 #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
127 #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
128 # addtopath CLASSPATH "$JARFILE"
129 #done
130
131 echo " - Adjusted CLASSPATH"
132 if [ "$DEBUG" = "true" ] ; then
133 echo " = $CLASSPATH"
134 fi
135
136 #LD_LIBRARY_PATH
137 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
138 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
139 echo " - Adjusted LD_LIBRARY_PATH"
140 if [ "$DEBUG" = "true" ] ; then
141 echo " = $LD_LIBRARY_PATH"
142 fi
143
144 echo " - Adjusted DYLD_LIBRARY_PATH"
145 if [ "$DEBUG" = "true" ] ; then
146 echo " = $DYLD_LIBRARY_PATH"
147 fi
148
149 #ImageMagick
150 #if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
151 # addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
152 # MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
153 # export MAGICK_HOME
154 # if test "$GSDLOS" = "linux"; then
155 # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
156 # elif test "$GSDLOS" = "darwin"; then
157 # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
158 # fi
159 # echo " - Setup ImageMagick"
160 #fi
161
162 #Ghostscript
163 if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
164 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
165 GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
166 export GS_LIB
167 GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
168 export GS_FONTPATH
169 echo " - Setup GhostScript"
170 fi
171
172 #wvWare
173 # wvWare's environment is now set up by bin/script/wvware.pl
174 # The wvware.pl script can be called from the cmdline to perform wvware tasks.
175 # GLI calls gsConvert.pl which calls wvware.pl to similarly perform wvware tasks.
176# if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
177# if test "$GSDLOS" = "linux"; then
178# addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
179# elif test "$GSDLOS" = "darwin"; then
180# addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
181# fi
182# echo " - Setup wvWare"
183# fi
184
185}
186
187checkJava() {
188
189 # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs
190 BUNDLED_JRE="`pwd`/packages/jre"
191 PRIORITY_HINT=$BUNDLED_JRE
192
193 if [ "$GSDLOS" = "darwin" ] ; then
194 # try $JAVA_HOME first, if it is set
195 if [ "x$JAVA_HOME" != "x" ] && [ -d "$JAVA_HOME" ] ; then
196 PRIORITY_HINT=$JAVA_HOME
197 elif [ ! -d "$PRIORITY_HINT" ] ; then
198 #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
199 # but if its not there, try the following:
200 # this will print out the path to java
201 PRIORITY_HINT=`/usr/libexec/java_home`
202 # old code used as fallback:
203 # But actually this is not valid for Mojave and Catalina
204 if [ ! -d "$PRIORITY_HINT" ] ; then
205 PRIORITY_HINT=/System/Library/Frameworks/JavaVM.framework/Home
206 fi
207 fi
208 fi
209
210 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi
211
212 # If the file utility exists, use it to determine the bitness of this GS3,
213 # particularly of this GS3's lib/jni/libgdbmjava.so/jnilib, since we prefer a matching java
214 # If any executable doesn't exist, the return value is 127.
215 # If file utility exists, then 0 is returned on successful execution, 1 is an error exit code
216 # Running file without arg returns 1 therefore.
217
218 # Determine the bitness of this GS3 installation, by running:
219 # `file lib/jni/libgdbmjava.so/jnilib`
220 # Output:
221 # lib/jni/libgdbmjava.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
222 # dynamically linked, BuildID[sha1]=5ae42cf69275408bdce97697d69e9e6fd481420d, not stripped
223 # On 32-bit linux, the output will contain "lib/jni/libgdbmjava.so: ELF 32-bit ..."
224 # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash
225
226 echo ""
227 command -v file > /dev/null 2>&1
228 file_cmd_status=$?
229
230 JNITESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.so"
231 if test "$GSDLOS" = "darwin"; then
232 JNITESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.jnilib"
233 fi
234
235 if [ $file_cmd_status != 0 ] ; then
236 if [ "$DEBUG" = "true" ] ; then
237 echo " 'file' utility not found installed on this unix-based system."
238 echo " Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found."
239 fi
240 bitness=-1
241 elif [ ! -f "$JNITESTFILE" ] ; then
242 # the file we want to test the bitness of, to determine GS3's bitness by, doesn't exist yet
243# echo " $JNITESTFILE is not found, unable to determine bitness of this Greenstone3"
244 echo " - No JNI files detected. Skipping Java bitness test"
245 bitness=-1
246 else
247 bitness=`file $JNITESTFILE | sed 's/^.* \([0-9]\+-bit\).*$/\1/'`
248 if [ $bitness = "64-bit" ] ; then
249 bitness=64
250# echo "The installed Greenstone is $bitness bit"
251 elif [ $bitness = "32-bit" ] ; then
252 bitness=32
253# echo "The installed Greenstone is $bitness bit"
254 else
255 bitness=-1
256 echo "WARNING: Greenstone installation is of unknown bitness. \"$bitness\" is neither '32-bit' nor '64-bit'"
257 fi
258 echo "JNI bitness test: $bitness"
259 fi
260
261 # If search4j is present, use it to locate a java.
262 # If search4j finds a Java, then:
263 # - If its bitness doesn't match and there's a bundled jre, use the bundled jre instead.
264 # - If its bitness doesn't match and there's no bundled jre, use the java found by search4j anyway,
265 # we'll print a warning about this bitness mismatch at the end
266
267 echo ""
268 echo "Checking for Java"
269
270 javaset=false
271 if [ -x bin/search4j ] ; then
272 FOUNDJAVAHOME="`bin/search4j -d -p \"$PRIORITY_HINT\" -m $java_min_version`"
273 javahome_retval=$?
274 FOUNDJREHOME="`bin/search4j -r -p \"$PRIORITY_HINT\" -m $java_min_version`"
275 jrehome_retval=$?
276 fi
277
278 # 1. check the bitness of any JDK java found by search4j, and use if appropriate
279 if [ "$javahome_retval" = "0" ] ; then
280 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
281 if [ "$?" = "0" ] ; then javaset="true"; fi
282 fi
283
284 # 2. check the bitness of any JRE java found by search4j, and use if appropriate
285 if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ] ; then
286 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
287 if [ "$?" = "0" ] ; then javaset="true"; fi
288 fi
289
290 # 3. check the bitness of any bundled JRE, and use if appropriate
291 # For linux, the bundled JRE ought to be of a bitness matching this OS.
292 if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ] ; then
293 setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "Bundled-JRE"
294 if [ "$?" = "0" ] ; then javaset="true"; fi
295 fi
296
297
298 # 4. None of the java found so far (via search4j, bundled_jre), if any, may have matched bitness wise
299 # So, fall back to using whichever is available in sequence anyway.
300 # We'll print a warning of bitness mismatch later
301
302 if [ "$javaset" != "true" ] ; then
303 # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present
304 if [ "$javahome_retval" = "0" ] ; then
305 setupJavaAt "$FOUNDJAVAHOME" "JDK"
306 javaset=true
307 elif [ "$jrehome_retval" = "0" ] ; then
308 setupJavaAt "$FOUNDJREHOME" "JRE"
309 javaset=true
310 elif [ -d "$BUNDLED_JRE" ] ; then
311 # bundled JRE should be >= than minimum version of java required
312 setupJavaAt "$BUNDLED_JRE" "JRE"
313 javaset=true
314 fi
315 fi
316
317 # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
318 if [ "$javaset" != "true" ] ; then
319
320 if [ -x bin/search4j ] ; then
321
322 # no suitable java could be found by search4j
323 echo " - Warning: Search4j failed to locate java $java_min_version or greater"
324 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
325 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
326
327 else
328 # search4j wasn't present, and no bundled JRE, so check JAVA_HOME or JRE_HOME manually
329 #echo "*** Could not find an appropriate JDK or JRE java"
330 #echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment"
331 echo " - search4j' not detected. Checking for Java explicitly set through environment variables"
332 if [ "x$JAVA_HOME" != "x" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ] ; then
333 echo " - Using Java at $JAVA_HOME"
334 if [ "$DEBUG" = "true" ] ; then
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 fi
341 elif [ "x$JRE_HOME" != "x" ] && [ "`which java`" = "$JRE_HOME/bin/java" ] ; then
342 echo " - Using java at $JRE_HOME"
343 if [ "$DEBUG" = "true" ] ; then
344 echo " - Detected Java version: `$JAVA_HOME/bin/java -version 2>&1 | head -n 1`"
345 echo " - Note that Greenstone requires Java 1.5 or greater"
346# echo " - WARNING: Greenstone has not checked the version number of this java installation"
347# echo " The source distribution of Greenstone3 requires java 1.5 or greater"
348# echo " (SVN users may still use java 1.4)"
349 fi
350 #failing all that, print a warning
351 else
352 echo " - Did not detect 'java' via JAVA_HOME or JRE_HOME"
353 echo "Testing for 'java' on PATH"
354 command -v java
355 if [ $? != 0 ] ; then
356 #no suitable java exists
357 echo " - Error: Failed to locate 'java'"
358 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
359 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
360 return
361 fi
362 fi
363 fi
364 fi
365
366 # If we know the bitness of this GS3 installation, then warn if there's a mismatch
367 # with the bitness of the Java found
368
369 if [ "$bitness" != "-1" ] ; then
370 if [ "x$JAVA_HOME" != "x" ] ; then
371 JAVA_FOUND=$JAVA_HOME
372 elif [ "x$JRE_HOME" != "x" ] ; then
373 JAVA_FOUND=$JRE_HOME
374 fi
375 checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness"
376 if [ "$?" = "1" ] ; then
377 echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)"
378 echo "*** and the Java found at $JAVA_FOUND/bin/java"
379 echo "*** Continuing with this Java anyway:"
380 echo "*** This will only affect MG/MGPP collections for searching, and GDBM database collections"
381 echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java"
382 echo "*** Or recompile GS with your system Java:"
383 if [ "x$JAVA_HOME" != "x" ] ; then
384 echo "*** JAVA_HOME at $JAVA_HOME"
385 else
386 echo "*** JRE_HOME at $JRE_HOME"
387 fi
388 fi
389 fi
390
391 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi
392
393}
394
395# http://www.linuxjournal.com/content/return-values-bash-functions
396setJavaIfOK() {
397
398 if [ "$DEBUG" = "true" ] ; then echo "Testing java at $3"; fi
399
400 DEBUG=$1
401 bitness=$2
402 PATHTOJAVA=$3
403 JDKorJRE=$4
404
405 checkJavaBitnessAgainstGSBitness "$PATHTOJAVA" "$bitness"
406 check_status=$?
407
408 isjavaset=false
409
410 if [ "$check_status" = "0" ] ; then
411 # http://tldp.org/LDP/abs/html/comparison-ops.html
412 if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then
413 # java matches GS bitness
414 if [ "$JDKorJRE" = "Bundled-JRE" ] ; then
415 echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
416 else
417 echo " The detected $JDKorJRE at $PATHTOJAVA is a matching $bitness bit"
418 fi
419 fi
420 setupJavaAt "$PATHTOJAVA" "$JDKorJRE"
421 isjavaset=true
422
423 elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then
424 if [ "$JDKorJRE" = "Bundled-JRE" ] ; then
425 echo " The $JDKorJRE java is an incompatible bit architecture"
426 else
427 echo " The detected $JDKorJRE java is an incompatible bit architecture"
428 fi
429 fi
430
431 if [ "$isjavaset" = "true" ] ; then
432 return 0 # success
433 else
434 return 1
435 fi
436}
437
438# if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
439checkJavaBitnessAgainstGSBitness() {
440# if [ "$DEBUG" = "true" ] ; then echo "Testing bitness of java found at $java_installation"; fi
441 java_installation="$1"
442 bitness="$2"
443
444 # bitness can be -1 if the 'file' utility could not be found to determine bitness
445 # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully
446 if [ "$bitness" = "-1" ] ; then
447 return 0
448 fi
449
450 # now we can actually work out if the java install's bitness matches that of GS ($bitness)
451 # java -d32 -version should return 0 if the Java is 32 bit, and 1 (failure) if the Java is 64 bit.
452 # Likewise, java -d64 -version will return 0 if the Java is 64 bit, and 1 (failure) if the Java is 32 bit.
453 `$java_installation/bin/java -d$bitness -version 2> /dev/null`
454
455 if [ "$?" = "0" ] ; then
456 return 0
457 elif [ "$?" = "1" ] ; then
458
459 # Newer Java's don't support -d, so resort to using dedicated java-based program GS3 provides
460 # for reporting Java bitness
461 java_bitness=`java -jar "$GSDL3SRCHOME/lib/java/display-java-bitness.jar"`
462 if [ $java_bitness = "$bitness" ] ; then
463 return 0
464 else
465 return 1
466 fi
467 else
468 echo "*** Problem determining bitness of java using java at $java_installation"
469 return $?
470 fi
471}
472
473
474setupJavaAt() {
475
476 # check the second parameter if non-null
477 if [ -n "$2" ] && [ "$2" = "JRE" ] ; then
478 export JRE_HOME="$1"
479 addtopath PATH "$JRE_HOME/bin"
480
481 # ant needs a JAVA_HOME, so set that too, to the JRE
482 export JAVA_HOME="$JRE_HOME"
483
484 BUNDLED_JRE="`pwd`/packages/jre"
485 if [ "$JRE_HOME" = "$BUNDLED_JRE" ] ; then
486 msg="the bundled"
487 fi
488
489 echo " - Exported JRE_HOME and JAVA_HOME to $msg $JRE_HOME"
490 else
491 export JAVA_HOME="$1"
492 addtopath PATH "$JAVA_HOME/bin"
493 echo " - Exported JAVA_HOME to $JAVA_HOME"
494 fi
495
496
497}
498
499pauseAndExit(){
500 echo -n "Please press any key to continue... "
501 read
502}
503
504isinpath() {
505 for file in `echo $1 | sed 's/:/ /g'`; do
506 if [ "$file" = "$2" ] ; then
507 echo true
508 return
509 fi
510 done
511 echo false
512}
513
514addtopath() {
515 eval "PV=\$$1"
516 #echo "$1 += $2"
517 if [ "x$PV" = "x" ] ; then
518 cmd="$1=\"$2\""
519 else
520 cmd="$1=\"$2:\$$1\""
521 fi
522 eval $cmd
523 eval "export $1"
524}
525
526# Note: use return not exit from a sourced script otherwise it kills the shell
527testSource
528if [ "$?" = "1" ] ; then
529 return
530fi
531
532testAlreadySourced
533if [ "$?" = "1" ] ; then
534 return
535fi
536
537setGS3ENV
538
539if test -e gs2build/setup.bash ; then
540 echo ""
541 echo "Sourcing gs2build/setup.bash"
542 cd gs2build ; . ./setup.bash ; cd ..
543fi
544
545
546if test "x$gsopt_noexts" != "x1" ; then
547 if test -e ext ; then
548 for gsdl_ext in ext/* ; do
549 if [ -d $gsdl_ext ] ; then
550 cd $gsdl_ext > /dev/null
551 if test -e gs3-setup.sh ; then
552 . ./gs3-setup.sh
553 elif test -e setup.bash ; then
554 . ./setup.bash
555 fi
556 cd ../..
557 fi
558 done
559 fi
560fi
561
562if test -e local ; then
563 if test -e local/gs3-setup.sh ; then
564 echo ""
565 echo "Sourcing local/gs3-setup.sh"
566 cd local ; . ./gs3-setup.sh ; cd ..
567 fi
568fi
569
570
571checkJava
572echo ""
573
574# Ant
575echo "Checking for Ant"
576
577# Note 1: No longer need to print out info about minimum version of
578# Ant needed for Greenstone3 (v1.8.2 at the time of updating this
579# comment!), as this is now explicitly tested for in the build.xml
580# file, and an error message generated if not new enough
581
582# Note 2: The setting of ANT_ARGS to '-noclasspath' flag below is to
583# void "cross-contamination' between this setup file -- which sets
584# CLASSPATH to include all the jars in <gsdl3srchome>web/WEB-INF,
585# including an ant.jar -- and what is needed to cleanly run the
586# 'ant' script and have it find the matching 'ant.jar' that goes
587# with it (i.e. is the same version). For example we want the
588# system installed /usr/bin/ant to find /usr/share/ant/lib/ant.jar
589#
590# Undesirable behaviour can occur, however, when the 'ant' that is
591# run is the one found on PATH, and a different ant.jar is found (as
592# can occur when CLASSPATH is set). For this pattern of running the
593# 'ant' script the 'ant.jar' that is in Greenstone's web/WEB-INF
594# area is found. This Greenstone ant.jar file (at the time of
595# writing) is for ant v.1.8.2, and causes some of the Java
596# properities ant uses to changed. Even if your installed 'ant' is
597# (say v1.10.9) and the JDK you are running is JDK11, as a
598# consequence of finding the older ant.jar file, ant.version is set
599# to 1.8.2 and ant.java.version to 1.7. As a consequence of this,
600# the Greenstone3 build.xml fails to run as its minimum Java version
601# needs to be >=1.8
602#
603# In looking at how to address this issue, updating the version of ant.jar
604# was considered. However, taking this approach means there will aways be
605# a risk of a version mismatch between a system installed 'ant' and
606# the version of ant.jar Greenstone includes.
607#
608# The approach taken here, then, is to more carefully control the
609# launching of ant. By setting ANT_ARGS to -noclasspath, the 'ant'
610# script is directed not to use CLASSPATH, thereby avoidig the
611# cross-contamination problem.
612#
613# Of further note, in the event ANT_HONE is set, then the situation
614# we are in is much simpler, as the cross-contamination problem
615# doesn't arise. This is because the 'ant' script explicitly sets
616# ANT_LIB, based on ANT_HOME, to explicitly pick out ant.jar file
617# that goes along with the script.
618#
619
620if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ] ; then
621 ANT_HOME="$GSDL3SRCHOME/packages/ant"
622 export ANT_HOME
623 addtopath PATH "$ANT_HOME/bin"
624 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
625else
626 if [ "x$ANT_HOME" != "x" ] ; then
627 addtopath PATH "$ANT_HOME/bin"
628 echo " - `ant -version`"
629 else
630 # which ant > /dev/null 2>&1
631 # Posix friendly way to determine if a program exists:
632 # https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
633 command -v ant > /dev/null 2>&1
634
635 if [ "$?" = "0" ] ; then
636 echo " - System install ant detected"
637
638 if [ "x$ANT_ARGS" = "x" ] ; then
639 ANT_ARGS="-noclasspath"
640 else
641 ANT_ARGS="-noclasspath $ANT_ARGS"
642 fi
643 export ANT_ARGS
644
645 echo " - `ant -version`"
646
647 else
648 echo " - WARNING: Failed to find 'ant'"
649 fi
650 fi
651fi
652
653echo "done"
654
Note: See TracBrowser for help on using the repository browser.