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