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

Last change on this file was 38436, checked in by davidb, 5 months ago

Additional details about xvfb-run added in

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