source: main/trunk/greenstone2/setup.bash

Last change on this file was 36798, checked in by anupama, 19 months ago

Related to commit 36794: adding in the PERL_HASH_SEED=0 line to the linux setup.bash script too, as I forgot to do that.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1#!/bin/bash
2# if this file is executed, /bin/sh is used, as we don't start with #!
3# this should work under ash, bash, zsh, ksh, sh style shells.
4gsdllang=""
5# encoding inputs and outputs
6gsdltoenc=""
7gsdlfromenc=""
8
9# see if the shell has any language environment variables set
10# see locale(7) manpage for this ordering.
11if test ! -z "$LC_ALL" ; then
12 gsdllang="$LC_ALL"
13elif test ! -z "$LANG"; then
14 gsdllang="$LANG"
15fi
16
17
18# note... all our output strings have the charset hard-coded, but
19# people may be using a different encoding in their terminal. LANG
20# strings look like "en_NZ.UTF-8".
21
22# Determine the requested output encoding
23case $gsdllang in
24 *.*)
25 gsdltoenc=`echo $gsdllang | sed 's/.*\.//'`
26 ;;
27esac
28
29# Our french and spanish strings are currently in iso-8859-1 encoding.
30case $gsdllang in
31 fr*|FR*)
32 gsdllang=fr
33 gsdlfromenc="iso-8859-1"
34 ;;
35 es*|ES*)
36 gsdllang=es
37 gsdlfromenc="iso-8859-1"
38 ;;
39 ru*|RU*)
40 gsdllang=ru
41 gsdlfromenc="koi8r"
42 ;;
43 *) # default
44 gsdllang=en
45 gsdlfromenc="iso-8859-1"
46 ;;
47esac
48
49# "iconv" is the program for converting text between encodings.
50gsdliconv=`which iconv 2>/dev/null`
51if test $? -ne 0 || test ! -x "$gsdliconv" || test -z "$gsdlfromenc" || test -z "$gsdltoenc"; then
52# we can't convert encodings from some reason
53 gsdliconv="cat"
54else
55# add the encodings
56 gsdliconv="$gsdliconv -f $gsdlfromenc -t $gsdltoenc"
57fi
58
59# make sure we are sourced, and not run
60
61if test "$0" != "`echo $0 | sed s/setup\.bash//`" ; then
62# if $0 contains "setup.bash" we've been run... $0 is shellname if sourced.
63# One exception is zsh has an option to set it temporarily to the script name
64 if test -z "$ZSH_NAME" ; then
65 # we aren't using zsh
66 gsdl_not_sourced=true
67 fi
68fi
69
70
71if test -n "$gsdl_not_sourced" ; then
72 case "$gsdllang" in
73 "es")
74eval $gsdliconv <<EOF
75 Error: Asegúrese de compilar este guión, no de ejecutarlo. P. ej.:
76 $ source setup.bash
77 o
78 $ . ./setup.bash
79 no
80 $ ./setup.bash
81EOF
82 ;;
83 "fr")
84eval $gsdliconv <<EOF
85 Erreur: Assurez-vous de "sourcer" le script, plutôt que de l'exécuter. Ex:
86 $ source setup.bash
87 ou
88 $ . ./setup.bash
89 pas
90 $ ./setup.bash
91EOF
92 ;;
93 "ru")
94eval $gsdliconv <<EOF
95 ïÛÉÂËÁ: õÄÏÓÔÏ×ÅÒØÔÅÓØ × ÉÓÔÏÞÎÉËÅ ÜÔÏÇÏ ÓËÒÉÐÔÁ. îÅ ÉÓÐÏÌÎÑÊÔÅ ÅÇÏ.
96 îÁÐÒÉÍÅÒ:
97 $ source setup.bash
98 ÉÌÉ
99 $ . ./setup.bash
100 ÎÅÔ
101 $ ./setup.bash
102EOF
103 ;;
104 *)
105eval $gsdliconv <<EOF
106 Error: Make sure you source this script, not execute it. Eg:
107 $ source setup.bash
108 or
109 $ . ./setup.bash
110 not
111 $ ./setup.bash
112EOF
113 ;;
114 esac
115elif test -n "$GSDLHOME" ; then
116 case "$gsdllang" in
117 "es")
118 echo "¡Su ambiente ya está listo para $GSDL2_DESC!" | eval $gsdliconv
119 ;;
120 "fr")
121 echo "Votre environnement est déjà préparé pour $GSDL2_DESC!" | eval $gsdliconv
122 ;;
123 "ru")
124 echo "÷ÁÛÅ ÏËÒÕÖÅÎÉÅ ÕÖÅ ÎÁÓÔÒÏÅÎÏ ÄÌÑ $GSDL2_DESC!" | eval $gsdliconv
125 ;;
126 *)
127 echo "Your environment is already set up for $GSDL2_DESC!"
128 ;;
129 esac
130elif test ! -f setup.bash ; then
131 case "$gsdllang" in
132 "es")
133eval $gsdliconv <<EOF
134Usted debe compilar el guión desde el interior del directorio de inicio
135de Greenstone.
136EOF
137 ;;
138 "fr")
139echo 'Vous devez trouver la source du script dans le répertoire de base de Greenstone' | eval $gsdliconv
140 ;;
141 "ru")
142eval $gsdliconv <<EOF
143÷ÁÍ ÎÅÏÂÈÏÄÉÍ ÉÓÔÏÞÎÉË ÓËÒÉÐÔÁ ÉÚ ÂÁÚÏ×ÏÊ ÄÉÒÅËÔÏÒÉÉ Greenstone
144EOF
145 ;;
146 *)
147 echo 'You must source the script from within the Greenstone home directory'
148 ;;
149 esac
150else
151 GSDLHOME=`pwd`
152 export GSDLHOME
153
154 GSDL2_DESC="Greenstone2"
155 if test ${GSDLHOME##*/} = "gs2build" ; then
156 GSDL2_DESC="$GSDL2_DESC-Buildtime"
157 fi
158 export GSDL2_DESC
159
160 if test "x$GSDLOS" = "x" ; then
161 GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
162 # check for running bash under cygwin
163 if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ;
164 then
165 GSDLOS=windows
166 fi
167 fi
168 export GSDLOS
169
170 # check for running bash under mingw
171 if test "`echo $GSDLOS | sed 's/mingw//'`" != "$GSDLOS" ;
172 then
173 GSDLOS=windows
174 fi
175 export GSDLOS
176
177 # Establish cpu architecture
178 # 32-bit or 64-bit?
179 UNAME_HW_MACH=`uname -m`
180
181# Original test
182# if test "`echo x$UNAME_HW_MACH | sed 's/^x.*_64$/x/'`" == "x" ;
183# then
184# GSDLARCH=64
185# else
186# GSDLARCH=32
187# fi
188
189 # Following test came from VirtualBox's Guest Additions autostart.sh
190 # (adapted for use in Greenstone)
191 case "$UNAME_HW_MACH" in
192 i[3456789]86|x86|i86pc)
193 GSDLARCH='32'
194 ;;
195 x86_64|amd64|AMD64)
196 GSDLARCH='64'
197 ;;
198 *)
199 echo "Unknown architecture: $UNAME_HW_MACH"
200 ;;
201 esac
202
203 # for xpdf tools, need to know whether we're using the bin32 or bin64 folder
204 BITNESS=$GSDLARCH
205 export BITNESS
206
207 # Only want non-trival GSDLARCH value set if there is evidence of
208 # the installed bin (lib, ...) directories using linux32, linux64
209 # (otherwise probably looking at an SVN compiled up version for single OS)
210 if test ! -d "$GSDLHOME/bin/$GSDLOS$GSDLARCH" ;
211 then
212 GSDLARCH=""
213 fi
214
215 export GSDLARCH
216
217 PATH=$GSDLHOME/bin/script:$GSDLHOME/bin/$GSDLOS$GSDLARCH:$PATH
218 export PATH
219
220 if test "$GSDLOS" = "linux" ; then
221 LD_LIBRARY_PATH="$GSDLHOME/lib/$GSDLOS$GSDLARCH:$LD_LIBRARY_PATH"
222 export LD_LIBRARY_PATH
223 elif test "$GSDLOS" = "darwin" ; then
224 DYLD_LIBRARY_PATH="$GSDLHOME/lib/$GSDLOS$GSDLARCH:$DYLD_LIBRARY_PATH"
225 export DYLD_LIBRARY_PATH
226 fi
227
228 # Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
229
230# Imagemagick env vars are set in bin\script\gs-magick.pl
231
232
233 # Note: Ghostscript is only bundled with Greenstone on Mac and Windows, not on Linux. The code below should be used only for the Darwin platform
234 # for Windows please see setup.bat
235if test -d "$GSDLHOME/bin/$GSDLOS$GSDLARCH/ghostscript" ; then
236 PATH="$GSDLHOME/bin/$GSDLOS$GSDLARCH/ghostscript/bin":"$PATH"
237 export PATH
238
239 GS_LIB="$GSDLHOME/bin/$GSDLOS$GSDLARCH/ghostscript/share/ghostscript/8.63/lib"
240 export GS_LIB
241
242 GS_FONTPATH="$GSDLHOME/bin/$GSDLOS$GSDLARCH/ghostscript/share/ghostscript/8.63/Resource/Font"
243 export GS_FONTPATH
244fi
245
246
247
248 MANPATH=$MANPATH:$GSDLHOME/packages/mg/man
249 export MANPATH
250 case "$gsdllang" in
251 "es")
252 echo "Su ambiente ha sido configurado para correr los programas $GSDL2_DESC." | eval $gsdliconv
253 ;;
254 "fr")
255 echo "Votre environnement a été configuére avec succès pour exécuter $GSDL2_DESC" | eval $gsdliconv
256 ;;
257 "ru")
258eval $gsdliconv <<EOF
259÷ÁÛÅ ÏËÒÕÖÅÎÉÅ ÂÙÌÏ ÕÓÐÅÛÎÏ ÎÁÓÔÒÏÅÎÏ, ÞÔÏÂÙ ÕÓÔÁÎÏ×ÉÔØ $GSDL2_DESC
260EOF
261 ;;
262 *)
263 echo "Your environment has successfully been set up to run $GSDL2_DESC"
264 ;;
265 esac
266fi
267unset gsdl_not_sourced
268unset gsdliconv
269unset gsdlfromenc
270unset gsdltoenc
271
272if test "x$gsopt_noexts" != "x1" ; then
273 if test -e ext; then
274 for gsdl_ext in ext/*; do
275 if test -d $gsdl_ext; then
276 cd $gsdl_ext > /dev/null
277 if test -e setup.bash ; then
278 . ./setup.bash
279 fi
280 cd ../..
281 fi
282 done
283 fi
284fi
285
286if test -e apache-httpd ; then
287 echo "+Adding in executable path for apache-httpd"
288 PATH=$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin:$PATH
289 export PATH
290
291 if test "$GSDLOS" = "linux" ; then
292 LD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/lib:$LD_LIBRARY_PATH"
293 export LD_LIBRARY_PATH
294
295 elif test "$GSDLOS" = "darwin" ; then
296 DYLD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/lib:$DYLD_LIBRARY_PATH"
297 export DYLD_LIBRARY_PATH
298 fi
299fi
300
301if test -e local ; then
302 if test -e local/setup.bash ; then
303 echo "Sourcing local/setup.bash"
304 cd local ; . ./ setup.bash ; cd ..
305 fi
306
307 PATH=$GSDLHOME/local/bin:$PATH
308 export PATH
309 LD_LIBRARY_PATH=$GSDLHOME/local/lib:$LD_LIBRARY_PATH
310 export LD_LIBRARY_PATH
311fi
312
313# Only for GS2: work out java, and if the bundled jre is found, then set Java env vars with it
314# Then the same java will be consistently available for all aspects of GS2 (server or GLI, and any subshells these launch)
315if [ "x$GSDL3SRCHOME" = "x" ] ; then
316 MINIMUM_JAVA_VERSION=1.5.0_00
317
318 echo "GS2 installation: Checking for Java of version $MINIMUM_JAVA_VERSION or above"
319
320 SEARCH4J_EXECUTABLE="$GSDLHOME/bin/$GSDLOS$GSDLARCH/search4j"
321 if [ -f "$SEARCH4J_EXECUTABLE" ]; then
322
323 # Give search4j a hint to find Java depending on the platform
324 # we now include a JRE with Mac (Mountain) Lion, because from Yosemite onwards there's no system Java on Macs
325 HINT=`cd "$GSDLHOME";pwd`/packages/jre
326
327 # we can't use boolean operator -a to do the AND, since it doesn't "short-circuit" if the first test fails
328 # see http://www.tldp.org/LDP/abs/html/comparison-ops.html
329
330
331 if [ "x$GSDLOS" = "xdarwin" ] && [ ! -d "$HINT" ]; then
332 # http://java.dzone.com/articles/java-findingsetting
333 # explains that /usr/libexec/java_home will print the default JDK
334 # regardless of which Mac OS we're on. Tested on Maverick, Lion, Leopard
335 # (run `/usr/libexec/java_home -v 1.7` to find a specific version)
336 macHINT=`/usr/libexec/java_home 2>&1`
337 status=$?
338 # if no java installed, then HINT will contain:
339 # Unable to find any JVMs matching version "(null)".
340 # No Java runtime present, try --request to install.
341 # and the status of running /usr/libexec/java_home will not be 0 but 1:
342 if [ "$status" = "0" ]; then
343 HINT=$macHINT
344 else
345 echo "No system Java on this mac..."
346 fi
347 fi
348
349 javahome="`"$SEARCH4J_EXECUTABLE" -p "$HINT" -m $MINIMUM_JAVA_VERSION`"
350 BUNDLED_JRE="$GSDLHOME/packages/jre"
351
352 if [ "$?" != "0" ]; then
353 echo "setup.bash: Could not find Java in the environment or installation."
354 echo "Set JAVA_HOME or JRE_HOME, and put it on the PATH, if working with Java tools like Lucene."
355 elif [[ "x$javahome" != "x" && "x$javahome" != "x$BUNDLED_JRE" ]]; then
356 echo "Using Java found at $javahome"
357 if [ "x$JAVA_HOME" = "x" ]; then
358 # if Java env vars not already set, then set them to the $javahome found
359 echo "Found a Java on the system. Setting up GS2's Java environment to use this"
360 export JAVA_HOME=$javahome
361 export PATH=$JAVA_HOME/bin:$PATH
362 fi
363 # else JAVA_HOME, and PATH presumably too, would already be set
364 elif [ -d "$GSDLHOME/packages/jre" ]; then
365 echo "Found a bundled JRE. Setting up GS2's Java environment to use this"
366 export JRE_HOME=$GSDLHOME/packages/jre
367 export PATH=$JRE_HOME/bin:$PATH
368 else
369 # can we ever really get here?
370 echo "Java environment not set and bundled JRE doesn't exist. Some tools need the Java environment. Proceeding without..."
371 fi
372 fi
373fi
374
375# if the Perl-for-greenstone tarfile has been installed in the bin/linux
376# folder, then we set things up to use that, instead of a system perl
377if [ -d "$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl" ] ; then
378
379 if [ -d "$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl/bin" ] ; then
380 PERLPATH=$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl/bin
381 export PERLPATH
382 PATH=$PERLPATH:$PATH
383 export PATH
384 fi
385
386 if test "$GSDLOS" = "linux" ; then
387 LD_LIBRARY_PATH=$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl/lib/5.8.9/i686-linux-thread-multi/CORE:$LD_LIBRARY_PATH
388 export LD_LIBRARY_PATH
389 elif test "$GSDLOS" = "darwin" ; then
390 DYLD_LIBRARY_PATH=$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl/lib/5.8.9/darwin-thread-multi-2level/CORE:$DYLD_LIBRARY_PATH
391 export DYLD_LIBRARY_PATH
392 fi
393
394 if [ "x$PERL5LIB" = "x" ] ; then
395 PERL5LIB=$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl/lib
396 else
397 PERL5LIB=$GSDLHOME/bin/$GSDLOS$GSDLARCH/perl/lib:$PERL5LIB
398 fi
399 export PERL5LIB
400
401 echo ""
402 echo " - Detected Perl installation inside $GSDL2_DESC."
403# echo "Command-line scripts need to be run with \"perl -S ...\""
404# echo " e.g. perl -S import.pl -removeold demo"
405# echo ""
406# else we may in future need to update PERL5LIB with some other (further) locations
407fi
408
409# Perl >= v5.18.* randomises map iteration order within a process
410# And consistent seed, https://www.perlmonks.org/?node_id=1167787
411export PERL_PERTURB_KEYS=0
412export PERL_HASH_SEED=0
413
414# turn off certificate errors when using wget to retrieve over https
415# (to avoid turning it off with the --no-check-certificate flag to each wget cmd)
416# See https://superuser.com/questions/508696/wget-without-no-check-certificate
417# https://www.gnu.org/software/wget/manual/html_node/Wgetrc-Location.html
418export WGETRC=$GSDLHOME/bin/$GSDLOS/wgetrc
419
420#if [ "x$JAVA_TOOL_OPTIONS" = "x" ] ; then
421# export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
422#else
423# export JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS -Dfile.encoding=UTF-8
424#fi
Note: See TracBrowser for help on using the repository browser.