source: main/trunk/greenstone2/setup.bash@ 32131

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

Suppressing confusing message on Macs when there's no system Java installed but search4j is still trying to find a (custom) java and could potentially find one.

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