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

Last change on this file since 37732 was 37445, checked in by anupama, 15 months ago

A sed regex in gs3-setup.sh was in the wrong format and caused problems that Dr Bainbridge noticed and fixed: the sed regex was trying to get the bitness number by running a File command. It failed as the plus regex operator for one-or-more was not behaving correctly on Mac even with the unexpected escaping in place. Dr Bainbridge got the 2 digits captured with [0-9][0-9] but warned that for 3-digit bitness this would of course break. A stack overflow page reminded how one-or-more can be written as {1,}, but needs escaped braces. It worked with Dr Bainbridge's command line test and should be future proof

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 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 # one-or-more regex to get one or more digits was not working. Dr Bainbridge fixed as below
249 #bitness=`file $JNITESTFILE | sed 's/^.* \([0-9][0-9]-bit\).*$/\1/'`
250 # The following also does one-or-more and works on the command line and should support 3 digit bitness
251 # https://stackoverflow.com/questions/12101440/one-or-more-occurrences-not-working-with-sed-command
252 bitness=`file $JNITESTFILE | sed 's/^.* \([0-9]\{1,\}-bit\).*$/\1/'`
253 if [ $bitness = "64-bit" ] ; then
254 bitness=64
255# echo "The installed Greenstone is $bitness bit"
256 elif [ $bitness = "32-bit" ] ; then
257 bitness=32
258# echo "The installed Greenstone is $bitness bit"
259 else
260 bitness=-1
261 echo "WARNING: Greenstone installation is of unknown bitness. \"$bitness\" is neither '32-bit' nor '64-bit'"
262 fi
263 echo "JNI bitness test: $bitness"
264 fi
265
266 # If search4j is present, use it to locate a java.
267 # If search4j finds a Java, then:
268 # - If its bitness doesn't match and there's a bundled jre, use the bundled jre instead.
269 # - If its bitness doesn't match and there's no bundled jre, use the java found by search4j anyway,
270 # we'll print a warning about this bitness mismatch at the end
271
272 echo ""
273 echo "Checking for Java"
274
275 javaset=false
276 if [ -x bin/search4j ] ; then
277 FOUNDJAVAHOME="`bin/search4j -d -p \"$PRIORITY_HINT\" -m $java_min_version`"
278 javahome_retval=$?
279 FOUNDJREHOME="`bin/search4j -r -p \"$PRIORITY_HINT\" -m $java_min_version`"
280 jrehome_retval=$?
281 fi
282
283 # 1. check the bitness of any JDK java found by search4j, and use if appropriate
284 if [ "$javahome_retval" = "0" ] ; then
285 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
286 if [ "$?" = "0" ] ; then javaset="true"; fi
287 fi
288
289 # 2. check the bitness of any JRE java found by search4j, and use if appropriate
290 if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ] ; then
291 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
292 if [ "$?" = "0" ] ; then javaset="true"; fi
293 fi
294
295 # 3. check the bitness of any bundled JRE, and use if appropriate
296 # For linux, the bundled JRE ought to be of a bitness matching this OS.
297 if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ] ; then
298 setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "Bundled-JRE"
299 if [ "$?" = "0" ] ; then javaset="true"; fi
300 fi
301
302
303 # 4. None of the java found so far (via search4j, bundled_jre), if any, may have matched bitness wise
304 # So, fall back to using whichever is available in sequence anyway.
305 # We'll print a warning of bitness mismatch later
306
307 if [ "$javaset" != "true" ] ; then
308 # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present
309 if [ "$javahome_retval" = "0" ] ; then
310 setupJavaAt "$FOUNDJAVAHOME" "JDK"
311 javaset=true
312 elif [ "$jrehome_retval" = "0" ] ; then
313 setupJavaAt "$FOUNDJREHOME" "JRE"
314 javaset=true
315 elif [ -d "$BUNDLED_JRE" ] ; then
316 # bundled JRE should be >= than minimum version of java required
317 setupJavaAt "$BUNDLED_JRE" "JRE"
318 javaset=true
319 fi
320 fi
321
322 # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
323 if [ "$javaset" != "true" ] ; then
324
325 if [ -x bin/search4j ] ; then
326
327 # no suitable java could be found by search4j
328 echo " - Warning: Search4j failed to locate java $java_min_version or greater"
329 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
330 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
331
332 else
333 # search4j wasn't present, and no bundled JRE, so check JAVA_HOME or JRE_HOME manually
334 #echo "*** Could not find an appropriate JDK or JRE java"
335 #echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment"
336 echo " - search4j' not detected. Checking for Java explicitly set through environment variables"
337 if [ "x$JAVA_HOME" != "x" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ] ; then
338 echo " - Using Java at $JAVA_HOME"
339 if [ "$DEBUG" = "true" ] ; then
340 echo " - Detected Java version: `$JAVA_HOME/bin/java -version 2>&1 | head -n 1`"
341 echo " - Note that Greenstone requires Java 1.5 or greater"
342# echo " - WARNING: Greenstone has not checked the version number of this java installation"
343# echo " The source distribution of Greenstone3 requires java 1.5 or greater"
344 # echo " (SVN users may still use java 1.4)"
345 fi
346 elif [ "x$JRE_HOME" != "x" ] && [ "`which java`" = "$JRE_HOME/bin/java" ] ; then
347 echo " - Using java at $JRE_HOME"
348 if [ "$DEBUG" = "true" ] ; then
349 echo " - Detected Java version: `$JAVA_HOME/bin/java -version 2>&1 | head -n 1`"
350 echo " - Note that Greenstone requires Java 1.5 or greater"
351# echo " - WARNING: Greenstone has not checked the version number of this java installation"
352# echo " The source distribution of Greenstone3 requires java 1.5 or greater"
353# echo " (SVN users may still use java 1.4)"
354 fi
355 #failing all that, print a warning
356 else
357 echo " - Did not detect 'java' via JAVA_HOME or JRE_HOME"
358 echo "Testing for 'java' on PATH"
359 command -v java
360 if [ $? != 0 ] ; then
361 #no suitable java exists
362 echo " - Error: Failed to locate 'java'"
363 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
364 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
365 return
366 fi
367 fi
368 fi
369 fi
370
371 # If we know the bitness of this GS3 installation, then warn if there's a mismatch
372 # with the bitness of the Java found
373
374 if [ "$bitness" != "-1" ] ; then
375 if [ "x$JAVA_HOME" != "x" ] ; then
376 JAVA_FOUND=$JAVA_HOME
377 elif [ "x$JRE_HOME" != "x" ] ; then
378 JAVA_FOUND=$JRE_HOME
379 fi
380 checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness"
381 if [ "$?" = "1" ] ; then
382 echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)"
383 echo "*** and the Java found at $JAVA_FOUND/bin/java"
384 echo "*** Continuing with this Java anyway:"
385 echo "*** This will only affect MG/MGPP collections for searching, and GDBM database collections"
386 echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java"
387 echo "*** Or recompile GS with your system Java:"
388 if [ "x$JAVA_HOME" != "x" ] ; then
389 echo "*** JAVA_HOME at $JAVA_HOME"
390 else
391 echo "*** JRE_HOME at $JRE_HOME"
392 fi
393 fi
394 fi
395
396 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi
397
398}
399
400# http://www.linuxjournal.com/content/return-values-bash-functions
401setJavaIfOK() {
402
403 if [ "$DEBUG" = "true" ] ; then echo "Testing java at $3"; fi
404
405 DEBUG=$1
406 bitness=$2
407 PATHTOJAVA=$3
408 JDKorJRE=$4
409
410 checkJavaBitnessAgainstGSBitness "$PATHTOJAVA" "$bitness"
411 check_status=$?
412
413 isjavaset=false
414
415 if [ "$check_status" = "0" ] ; then
416 # http://tldp.org/LDP/abs/html/comparison-ops.html
417 if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then
418 # java matches GS bitness
419 if [ "$JDKorJRE" = "Bundled-JRE" ] ; then
420 echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
421 else
422 echo " The detected $JDKorJRE at $PATHTOJAVA is a matching $bitness bit"
423 fi
424 fi
425 setupJavaAt "$PATHTOJAVA" "$JDKorJRE"
426 isjavaset=true
427
428 elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then
429 if [ "$JDKorJRE" = "Bundled-JRE" ] ; then
430 echo " The $JDKorJRE java is an incompatible bit architecture"
431 else
432 echo " The detected $JDKorJRE java is an incompatible bit architecture"
433 fi
434 fi
435
436 if [ "$isjavaset" = "true" ] ; then
437 return 0 # success
438 else
439 return 1
440 fi
441}
442
443# if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
444checkJavaBitnessAgainstGSBitness() {
445# if [ "$DEBUG" = "true" ] ; then echo "Testing bitness of java found at $java_installation"; fi
446 java_installation="$1"
447 bitness="$2"
448
449 # bitness can be -1 if the 'file' utility could not be found to determine bitness
450 # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully
451 if [ "$bitness" = "-1" ] ; then
452 return 0
453 fi
454
455 # now we can actually work out if the java install's bitness matches that of GS ($bitness)
456 # java -d32 -version should return 0 if the Java is 32 bit, and 1 (failure) if the Java is 64 bit.
457 # Likewise, java -d64 -version will return 0 if the Java is 64 bit, and 1 (failure) if the Java is 32 bit.
458 `$java_installation/bin/java -d$bitness -version 2> /dev/null`
459
460 if [ "$?" = "0" ] ; then
461 return 0
462 elif [ "$?" = "1" ] ; then
463
464 # Newer Java's don't support -d, so resort to using dedicated java-based program GS3 provides
465 # for reporting Java bitness
466 java_bitness=`java -jar "$GSDL3SRCHOME/lib/java/display-java-bitness.jar"`
467 if [ $java_bitness = "$bitness" ] ; then
468 return 0
469 else
470 return 1
471 fi
472 else
473 echo "*** Problem determining bitness of java using java at $java_installation"
474 return $?
475 fi
476}
477
478
479setupJavaAt() {
480
481 # check the second parameter if non-null
482 if [ -n "$2" ] && [ "$2" = "JRE" ] ; then
483 export JRE_HOME="$1"
484 addtopath PATH "$JRE_HOME/bin"
485
486 # ant needs a JAVA_HOME, so set that too, to the JRE
487 export JAVA_HOME="$JRE_HOME"
488
489 BUNDLED_JRE="`pwd`/packages/jre"
490 if [ "$JRE_HOME" = "$BUNDLED_JRE" ] ; then
491 msg="the bundled"
492 fi
493
494 echo " - Exported JRE_HOME and JAVA_HOME to $msg $JRE_HOME"
495 else
496 export JAVA_HOME="$1"
497 addtopath PATH "$JAVA_HOME/bin"
498 echo " - Exported JAVA_HOME to $JAVA_HOME"
499 fi
500
501
502}
503
504pauseAndExit(){
505 echo -n "Please press any key to continue... "
506 read
507}
508
509isinpath() {
510 for file in `echo $1 | sed 's/:/ /g'`; do
511 if [ "$file" = "$2" ] ; then
512 echo true
513 return
514 fi
515 done
516 echo false
517}
518
519addtopath() {
520 eval "PV=\$$1"
521 #echo "$1 += $2"
522 if [ "x$PV" = "x" ] ; then
523 cmd="$1=\"$2\""
524 else
525 cmd="$1=\"$2:\$$1\""
526 fi
527 eval $cmd
528 eval "export $1"
529}
530
531# Note: use return not exit from a sourced script otherwise it kills the shell
532testSource
533if [ "$?" = "1" ] ; then
534 return
535fi
536
537testAlreadySourced
538if [ "$?" = "1" ] ; then
539 return
540fi
541
542setGS3ENV
543
544if test -e gs2build/setup.bash ; then
545 echo ""
546 echo "Sourcing gs2build/setup.bash"
547 cd gs2build ; . ./setup.bash ; cd ..
548fi
549
550
551if test "x$gsopt_noexts" != "x1" ; then
552 if test -e ext ; then
553 for gsdl_ext in ext/* ; do
554 if [ -d $gsdl_ext ] ; then
555 cd $gsdl_ext > /dev/null
556 if test -e gs3-setup.sh ; then
557 . ./gs3-setup.sh
558 elif test -e setup.bash ; then
559 . ./setup.bash
560 fi
561 cd ../..
562 fi
563 done
564 fi
565fi
566
567if test -e local ; then
568 if test -e local/gs3-setup.sh ; then
569 echo ""
570 echo "Sourcing local/gs3-setup.sh"
571 cd local ; . ./gs3-setup.sh ; cd ..
572 fi
573fi
574
575
576checkJava
577echo ""
578
579
580# If webswing-server.war is present, then (for X-Window systems)
581# work out if the system is capable of running webswing
582#
583# => If it can, but is a headless server, then needs 'xvfb-run'
584
585export CATALINA_START_RUNJAVA=""
586
587if [ -f packages/tomcat/webapps/webswing-server.war ] ; then
588
589 if [ "$GSDLOS" = "linux" ] && [ "x$DISPLAY" = "x" ] ; then
590 # a headless linux server
591 # => need xvfb-run to be able to operate webswing-server.war
592
593 command -v xvfb-run > /dev/null 2>&1
594 if [ $? = 0 ] ; then
595 echo "Setting CATALINA_START_RUNJAVA to '$GSDL3SRCHOME/bin/script/xvfb-run-java'"
596 echo " => Allows webswing-server.war to graphically render on headless server"
597 export CATALINA_START_RUNJAVA="$GSDL3SRCHOME/bin/script/xvfb-run-java"
598 else
599 echo "Warning: No DISPLAY variable set => looks like a headless server"
600 echo " Unable to detect 'xvfb-run' => webswing-server.war unlikely to work"
601 fi
602 echo ""
603 fi
604fi
605
606
607# Ant
608echo "Checking for Ant"
609
610# Note 1: No longer need to print out info about minimum version of
611# Ant needed for Greenstone3 (v1.8.2 at the time of updating this
612# comment!), as this is now explicitly tested for in the build.xml
613# file, and an error message generated if not new enough
614
615# Note 2: The setting of ANT_ARGS to '-noclasspath' flag below is to
616# void "cross-contamination' between this setup file -- which sets
617# CLASSPATH to include all the jars in <gsdl3srchome>web/WEB-INF,
618# including an ant.jar -- and what is needed to cleanly run the
619# 'ant' script and have it find the matching 'ant.jar' that goes
620# with it (i.e. is the same version). For example we want the
621# system installed /usr/bin/ant to find /usr/share/ant/lib/ant.jar
622#
623# Undesirable behaviour can occur, however, when the 'ant' that is
624# run is the one found on PATH, and a different ant.jar is found (as
625# can occur when CLASSPATH is set). For this pattern of running the
626# 'ant' script the 'ant.jar' that is in Greenstone's web/WEB-INF
627# area is found. This Greenstone ant.jar file (at the time of
628# writing) is for ant v.1.8.2, and causes some of the Java
629# properities ant uses to changed. Even if your installed 'ant' is
630# (say v1.10.9) and the JDK you are running is JDK11, as a
631# consequence of finding the older ant.jar file, ant.version is set
632# to 1.8.2 and ant.java.version to 1.7. As a consequence of this,
633# the Greenstone3 build.xml fails to run as its minimum Java version
634# needs to be >=1.8
635#
636# In looking at how to address this issue, updating the version of ant.jar
637# was considered. However, taking this approach means there will aways be
638# a risk of a version mismatch between a system installed 'ant' and
639# the version of ant.jar Greenstone includes.
640#
641# The approach taken here, then, is to more carefully control the
642# launching of ant. By setting ANT_ARGS to -noclasspath, the 'ant'
643# script is directed not to use CLASSPATH, thereby avoidig the
644# cross-contamination problem.
645#
646# Of further note, in the event ANT_HONE is set, then the situation
647# we are in is much simpler, as the cross-contamination problem
648# doesn't arise. This is because the 'ant' script explicitly sets
649# ANT_LIB, based on ANT_HOME, to explicitly pick out ant.jar file
650# that goes along with the script.
651#
652
653if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ] ; then
654 ANT_HOME="$GSDL3SRCHOME/packages/ant"
655 export ANT_HOME
656 addtopath PATH "$ANT_HOME/bin"
657 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
658else
659 if [ "x$ANT_HOME" != "x" ] ; then
660 addtopath PATH "$ANT_HOME/bin"
661 echo " - `ant -version`"
662 else
663 # which ant > /dev/null 2>&1
664 # Posix friendly way to determine if a program exists:
665 # https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
666 command -v ant > /dev/null 2>&1
667
668 if [ "$?" = "0" ] ; then
669 echo " - System install ant detected"
670
671 if [ "x$ANT_ARGS" = "x" ] ; then
672 ANT_ARGS="-noclasspath"
673 else
674 ANT_ARGS="-noclasspath $ANT_ARGS"
675 fi
676 export ANT_ARGS
677
678 echo " - `ant -version`"
679
680 else
681 echo " - WARNING: Failed to find 'ant'"
682 fi
683 fi
684fi
685
686echo "done"
687
Note: See TracBrowser for help on using the repository browser.