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

Last change on this file since 33098 was 32488, checked in by kjdon, 6 years ago

added WEB-INF/lib jar files to classpath. needed for compiling Lucene classes in gberg coll. Not sure if it should go in here or in gs3-devel.sh...

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 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.5.0_00
11DEBUG=false
12
13function 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.x
46function 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
59function 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, GSDL3SRCHOME and GSDLOS"
77
78 #change this if external tomcat
79 TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
80
81 ## adjustments to users (existing) environment ##
82
83 #PATH
84 addtopath PATH "$GSDL3SRCHOME/bin/script"
85 addtopath PATH "$GSDL3SRCHOME/bin"
86 echo " - Adjusted PATH"
87
88 #MANPATH
89 addtopath MANPATH "$GSDL3SRCHOME/doc/man"
90 echo " - Adjusted MANPATH"
91
92 #CLASSPATH
93 addtopath CLASSPATH "."
94 addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
95 addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
96 addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
97
98 # Greenstone JAR files
99 for JARFILE in "$GSDL3HOME/WEB-INF/lib"/*.jar; do
100 addtopath CLASSPATH "$JARFILE"
101 done
102
103 # Tomcat 5 jar files
104 for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
105 addtopath CLASSPATH "$JARFILE"
106 done
107 # Tomcat 6 jar files
108 for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
109 addtopath CLASSPATH "$JARFILE"
110 done
111
112 #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
113 #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
114 # addtopath CLASSPATH "$JARFILE"
115 #done
116
117 echo " - Adjusted CLASSPATH"
118
119 #LD_LIBRARY_PATH
120 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
121 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
122 echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
123
124 #ant
125 ANT_VERSION=1.7.1
126 if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
127 ANT_HOME="$GSDL3SRCHOME/packages/ant"
128 export ANT_HOME
129 addtopath PATH "$ANT_HOME/bin"
130 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
131 else
132 which ant &> /dev/null
133 if [ "$?" == "0" ]; then
134 echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
135 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
136 elif [ "ANT_HOME" != "" ]; then
137 addtopath PATH "$ANT_HOME/bin"
138 echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
139 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
140 else
141 echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
142 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
143 fi
144 fi
145
146 #ImageMagick
147 #if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
148 # addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
149 # MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
150 # export MAGICK_HOME
151 # if test "$GSDLOS" = "linux"; then
152 # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
153 # elif test "$GSDLOS" = "darwin"; then
154 # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
155 # fi
156 # echo " - Setup ImageMagick"
157 #fi
158
159 #Ghostscript
160 if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
161 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
162 GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
163 export GS_LIB
164 GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
165 export GS_FONTPATH
166 echo " - Setup GhostScript"
167 fi
168
169 #wvWare
170 # wvWare's environment is now set up by bin/script/wvware.pl
171 # The wvware.pl script can be called from the cmdline to perform wvware tasks.
172 # GLI calls gsConvert.pl which calls wvware.pl to similarly perform wvware tasks.
173# if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
174# if test "$GSDLOS" = "linux"; then
175# addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
176# elif test "$GSDLOS" = "darwin"; then
177# addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
178# fi
179# echo " - Setup wvWare"
180# fi
181
182}
183
184function checkJava() {
185
186 # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs
187 BUNDLED_JRE="`pwd`/packages/jre"
188 HINT=$BUNDLED_JRE
189
190 #if [ "$GSDLOS" = "darwin" ] && [ ! -d "$HINT" ]; then
191 if [ "$GSDLOS" = "darwin" ]; then
192 if [ "$JAVA_HOME" != "" ] && [ -d "$JAVA_HOME" ]; then
193 HINT=$JAVA_HOME
194 elif [ ! -d "$HINT" ]; then
195 HINT=`/usr/libexec/java_home`
196 # old code used as fallback:
197 if [ ! -d "$HINT" ]; then
198 HINT=/System/Library/Frameworks/JavaVM.framework/Home
199 fi
200 fi
201 fi
202
203 if [ "$DEBUG" == "true" ]; then echo "**********************************************"; fi
204
205 # If the file utility exists, use it to determine the bitness of this GS3,
206 # particularly of this GS3's lib\jni\libgdbmjava.so (gdbmjava.dll), since we prefer a matching java
207 # If any executable doesn't exist, the return value is 127.
208 # If file utility exists, then 0 is returned on successful execution, 1 is an error exit code
209 # Running file without arg returns 1 therefore.
210
211 # Determine the bitness of this GS3 installation, by running:
212 # `file lib/jni/libgdbmjava.so`
213 # Output:
214 # lib/jni/libgdbmjava.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
215 # dynamically linked, BuildID[sha1]=5ae42cf69275408bdce97697d69e9e6fd481420d, not stripped
216 # On 32-bit linux, the output will contain "lib/jni/libgdbmjava.so: ELF 32-bit ..."
217 # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash
218
219 fileexists=`file 2&> /dev/null`
220
221 # Integer comparison, http://tldp.org/LDP/abs/html/comparison-ops.html
222 # can also use double brackets: if [[ $? > 1 ]]; then ...
223 if [ "$?" -gt "1" ]; then
224 if [ "$DEBUG" == "true" ]; then
225 echo " 'file' utility not found installed on this unix-based system."
226 echo " Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found."
227 fi
228 bitness=-1
229 elif [ ! -f "$GSDL3SRCHOME/lib/jni/libgdbmjava.so" ]; then
230 # the file we want to test the bitness of, to determine GS3's bitness by, doesn't exist yet
231 bitness=-1
232 else
233 bitness=`file $GSDL3SRCHOME/lib/jni/libgdbmjava.so`
234 if [[ $bitness == *"64-bit"* ]]; then
235 bitness=64
236 echo "The installed Greenstone is $bitness bit"
237 elif [[ $bitness == *"32-bit"* ]]; then
238 bitness=32
239 echo "The installed Greenstone is $bitness bit"
240 else
241 bitness=-1
242 echo "WARNING: Greenstone installation is of unknown bitness. \"$bitness\" is neither 32 nor 64 bit"
243 fi
244 fi
245
246 # If search4j is present, use it to locate a java.
247 # If search4j finds a Java, then:
248 # - If its bitness doesn't match and there's a bundled jre, use the bundled jre instead.
249 # - If its bitness doesn't match and there's no bundled jre, use the java found by search4j anyway,
250 # we'll print a warning about this bitness mismatch at the end
251
252 javaset=false
253 if [ -x bin/search4j ] ; then
254 FOUNDJAVAHOME="`bin/search4j -d -p \"$HINT\" -m $java_min_version`"
255 javahome_retval=$?
256 FOUNDJREHOME="`bin/search4j -r -p \"$HINT\" -m $java_min_version`"
257 jrehome_retval=$?
258 fi
259
260 # 1. check the bitness of any JDK java found by search4j, and use if appropriate
261 if [ "$javahome_retval" == "0" ]; then
262 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
263 if [ "$?" == "0" ]; then javaset="true"; fi
264 fi
265
266 # 2. check the bitness of any JRE java found by search4j, and use if appropriate
267 if [ "$javaset" != "true" ] && [ "$jrehome_retval" == "0" ]; then
268 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
269 if [ "$?" == "0" ]; then javaset="true"; fi
270 fi
271
272 # 3. check the bitness of any bundled JRE, and use if appropriate
273 # For linux, the bundled JRE ought to be of a bitness matching this OS.
274 if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ]; then
275 setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "bundled JRE"
276 if [ "$?" == "0" ]; then javaset="true"; fi
277 fi
278
279
280 # 4. None of the java found so far (via search4j, bundled_jre), if any, may have matched bitness wise
281 # So, fall back to using whichever is available in sequence anyway.
282 # We'll print a warning of bitness mismatch later
283
284 if [ "$javaset" != "true" ]; then
285 # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present
286 if [ "$javahome_retval" == "0" ]; then
287 setupJavaAt "$FOUNDJAVAHOME" "JDK"
288 javaset=true
289 elif [ "$jrehome_retval" == "0" ]; then
290 setupJavaAt "$FOUNDJREHOME" "JRE"
291 javaset=true
292 elif [ -d "$BUNDLED_JRE" ]; then
293 # bundled JRE should be >= than minimum version of java required
294 setupJavaAt "$BUNDLED_JRE" "JRE"
295 javaset=true
296 fi
297 fi
298
299 # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
300 if [ "$javaset" != "true" ]; then
301
302 if [ -x bin/search4j ]; then
303
304 # no suitable java could be found by search4j
305 echo " - ERROR: Failed to locate java $java_min_version or greater"
306 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
307 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
308
309 else
310 # search4j wasn't present, and no bundled JRE, so check JAVA_HOME or JRE_HOME manually
311 echo "*** Could not find an appropriate JDK or JRE java"
312 echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment"
313
314 if [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
315 echo " - Using java at $JAVA_HOME"
316 echo " - WARNING: Greenstone has not checked the version number of this java installation"
317 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
318 echo " (SVN users may still use java 1.4)"
319 elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
320 echo " - Using java at $JRE_HOME"
321 echo " - WARNING: Greenstone has not checked the version number of this java installation"
322 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
323 echo " (SVN users may still use java 1.4)"
324
325 #failing all that, print a warning
326 else
327 #no suitable java exists
328 echo " - ERROR: Failed to locate java"
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 return
332 fi
333 fi
334 fi
335
336 # If we know the bitness of this GS3 installation, then warn if there's a mismatch
337 # with the bitness of the Java found
338
339 if [ "$bitness" != "-1" ]; then
340 if [ "$JAVA_HOME" != "" ]; then
341 JAVA_FOUND=$JAVA_HOME
342 elif [ "$JRE_HOME" != "" ]; then
343 JAVA_FOUND=$JRE_HOME
344 fi
345 checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness"
346 if [ "$?" == "1" ]; then
347 echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)"
348 echo "*** and the Java found at $JAVA_FOUND/bin/java"
349 echo "*** Continuing with this Java anyway:"
350 echo "*** This will only affect MG/MGPP collections for searching, and GDBM database collections"
351 echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java"
352 echo "*** Or recompile GS with your system Java:"
353 if [ "$JAVA_HOME" != "" ]; then
354 echo "*** JAVA_HOME at $JAVA_HOME"
355 else
356 echo "*** JRE_HOME at $JRE_HOME"
357 fi
358 fi
359 fi
360
361 if [ "$DEBUG" == "true" ]; then echo "**********************************************"; fi
362
363}
364
365# http://www.linuxjournal.com/content/return-values-bash-functions
366function setJavaIfOK {
367
368 if [ "$DEBUG" == "true" ]; then echo "Testing java at $3"; fi
369
370 DEBUG=$1
371 bitness=$2
372 PATHTOJAVA=$3
373 JDKorJRE=$4
374
375 checkJavaBitnessAgainstGSBitness "$PATHTOJAVA" "$bitness"
376
377 isjavaset=false
378
379 if [ "$?" == "0" ]; then
380 # http://tldp.org/LDP/abs/html/comparison-ops.html
381 if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
382 # java matches GS bitness
383 if [[ "$JDKorJRE" == *"bundled"* ]]; then
384 echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
385 else
386 echo " The detected $JDKorJRE at $PATHTOJAVA is a matching $bitness bit"
387 fi
388 fi
389 setupJavaAt "$PATHTOJAVA" "$JDKorJRE"
390 isjavaset=true
391
392 elif [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
393 if [[ "$JDKorJRE" == *"bundled"* ]]; then
394 echo " The $JDKorJRE java is an incompatible bit architecture"
395 else
396 echo " The detected $JDKorJRE java is an incompatible bit architecture"
397 fi
398 fi
399
400 if [ "$isjavaset" == "true" ]; then
401 return 0 # success
402 else
403 return 1
404 fi
405}
406
407# if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
408function checkJavaBitnessAgainstGSBitness() {
409# if [ "$DEBUG" == "true" ]; then echo "Testing bitness of java found at $java_installation"; fi
410 java_installation="$1"
411 bitness="$2"
412
413 # bitness can be -1 if the 'file' utility could not be found to determine bitness
414 # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully
415 if [ "$bitness" == "-1" ]; then
416 return 0
417 fi
418
419 # now we can actually work out if the java install's bitness matches that of GS ($bitness)
420 # java -d32 -version should return 0 if the Java is 32 bit, and 1 (failure) if the Java is 64 bit.
421 # Likewise, java -d64 -version will return 0 if the Java is 64 bit, and 1 (failure) if the Java is 32 bit.
422 `$java_installation/bin/java -d$bitness -version 2> /dev/null`
423
424 if [ "$?" == "0" ]; then
425 return 0
426 elif [ "$?" == "1" ]; then
427 return 1
428 else
429 echo "*** Problem determining bitness of java using java at $java_installation"
430 return $?
431 fi
432}
433
434
435function setupJavaAt() {
436
437 # check the second parameter if non-null
438 if [ -n "$2" ] && [ "$2" == "JRE" ]; then
439 export JRE_HOME="$1"
440 addtopath PATH "$JRE_HOME/bin"
441
442 BUNDLED_JRE="`pwd`/packages/jre"
443 if [[ "$JRE_HOME" == *"$BUNDLED_JRE"* ]]; then
444 msg="the bundled"
445 fi
446
447 echo " - Exported JRE_HOME to $msg $JRE_HOME"
448 else
449 export JAVA_HOME="$1"
450 addtopath PATH "$JAVA_HOME/bin"
451 echo " - Exported JAVA_HOME to $JAVA_HOME"
452 fi
453
454
455}
456
457function pauseAndExit(){
458 echo -n "Please press any key to continue... "
459 read
460}
461
462function isinpath() {
463 for file in `echo $1 | sed 's/:/ /g'`; do
464 if [ "$file" == "$2" ]; then
465 echo true
466 return
467 fi
468 done
469 echo false
470}
471
472function addtopath() {
473 eval "PV=\$$1"
474 #echo "$1 += $2"
475 if [ "$PV" == "" ]; then
476 cmd="$1=\"$2\""
477 else
478 cmd="$1=\"$2:\$$1\""
479 fi
480 eval $cmd
481 eval "export $1"
482}
483
484# Note: use return not exit from a sourced script otherwise it kills the shell
485echo
486testSource
487if [ "$?" == "1" ]; then
488return
489fi
490testAlreadySourced
491if [ "$?" == "1" ]; then
492return
493fi
494setGS3ENV
495
496if test -e gs2build/setup.bash ; then
497 echo ""
498 echo "Sourcing gs2build/setup.bash"
499 cd gs2build ; source setup.bash ; cd ..
500fi
501
502
503if test "x$gsopt_noexts" != "x1" ; then
504 if test -e ext ; then
505 for gsdl_ext in ext/* ; do
506 if [ -d $gsdl_ext ] ; then
507 cd $gsdl_ext > /dev/null
508 if test -e gs3-setup.sh ; then
509 source ./gs3-setup.sh
510 elif test -e setup.bash ; then
511 source ./setup.bash
512 fi
513 cd ../..
514 fi
515 done
516 fi
517fi
518
519if test -e local ; then
520 if test -e local/gs3-setup.sh ; then
521 echo ""
522 echo "Sourcing local/gs3-setup.sh"
523 cd local ; source gs3-setup.sh ; cd ..
524 fi
525fi
526
527
528checkJava
529echo ""
Note: See TracBrowser for help on using the repository browser.