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

Last change on this file since 31462 was 31462, checked in by ak19, 7 years ago

Related to commits 31447 and 31461 which were for windows. The Linux GS3-setup script now also checks bitness of the GS3 installation against the bitness of the Java found. Two problems remain. 1. Linux script always sets the JAVA_HOME env var, even if a JRE_HOME is actually found. 2. On Windows, search4j favours system JAVA_HOME or JRE_HOME to the JRE_HOME in HINT. On linux, it favours the JRE_HOME in HINT over the system vars. The reason may be linked to 1.

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