root/gli/trunk/gli.sh @ 19392

Revision 19392, 11.9 KB (checked in by ak19, 11 years ago)

Allowing the user to run the gli and client-gli scripts from other directories.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/bin/bash
2
3# Function that, when given gsdlpath as parameter, will return the
4# version of greenstone that is to run (2 or 3). If things are not,
5# this program will exit here.
6function get_version {
7    # first parameter is value of gsdlpath
8    if [ -f "${1}/gs3-setup.sh" ]; then
9    return 3
10    elif [ -f "${1}/setup.bash" ]; then
11    return 2
12    else
13    echo "Error: can't determine which Greenstone version is being run."
14    exit 1
15    fi
16}
17
18# Function that is passed the following paramters (in order):
19# - the gsdlpath (GS3 home, GS2 home or gs2build for GS3),
20# - the version of greenstone that's running, and
21# - the language GLI is set to
22# and checks the installation.
23# If things are not right, this program will exit here.
24function check_installation {
25# Check that the Greenstone installation looks OK
26    if [ "$3" = "es" ]; then
27    echo "Revisando GSDL$2: $1"
28    elif [ "$3" = "fr" ]; then
29    echo "Vérification de GSDL$2: $1"
30    elif [ "$3" = "ru" ]; then
31    echo "ðÒÏ×ÅÒËÁ GSDL$2: $1"
32    else
33    echo "Checking GSDL$2: $1"
34    fi
35    # even if we are only checking for gs2build (gsdl2path), we still
36    # need the file setup.bash to exist in the following condition:
37    if [ ! -f "${1}/gs3-setup.sh" -a ! -f "${1}/setup.bash" ] ; then
38    echo
39    if [ "$3" = "es" ]; then
40        echo "No se pudo encontrar la instalación de Greenstone $2 o está incompleta."
41        echo "Trate de reinstalar Greenstone $2 y a continuación ejecute nuevamente"
42        echo "este guión."
43    elif [ "$3" = "fr" ]; then
44        echo "L'installation de Greenstone $2 est introuvable ou incomplète."
45        echo "Essayez de réinstaller Greenstone $2 et exécutez ce script à nouveau."
46    elif [ "$3" = "ru" ]; then
47        echo "éÎÓÔÁÌÌÑÃÉÑ Greenstone $_version ÎÅ ÂÙÌÁ ÎÁÊÄÅÎÁ ÉÌÉ ÏÎÁ ÎÅÐÏÌÎÁ."
48        echo "ðÏÐÒÏÂÕÊÔÅ ÐÏ×ÔÏÒÎÏ ÕÓÔÁÎÏ×ÉÔØ Greenstone $2, Á ÚÁÔÅÍ ××ÅÓÔÉ ÜÔÏÔ ÓËÒÉÐÔ ÓÎÏ×Á."
49    else
50        echo "The Greenstone $2 installation could not be found, or is incomplete."
51        echo "Try reinstalling Greenstone $2 then running this script again."
52    fi
53    exit 1
54    fi
55}
56
57glilang=en
58
59if [ "x$PROGNAME" = "x" ] ; then
60  if [ "$glilang" = "es" ]; then
61    PROGNAME="Biblioteca Digital Greenstone"
62  elif [ "$glilang" = "fr" ]; then
63    PROGNAME="Bibliothécaire Greenstone"
64  elif [ "$glilang" = "ru" ]; then
65    PROGNAME="ÉÎÔÅÒÆÅÊÓ Greenstone"
66  else
67    PROGNAME="Greenstone Librarian Interface"
68  fi
69fi
70
71if [ "x$PROGABBR" = "x" ] ; then
72    PROGABBR="GLI"
73fi
74
75if [ "x$PROGNAME_EN" = "x" ] ; then
76    PROGNAME_EN="Greenstone Librarian Interface"
77fi
78
79echo
80if [ "$glilang" = "es" ]; then
81    echo "Interfaz de la $PROGNAME ($PROGNAME_EN - $PROGABBR)"
82    echo "Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato"
83    echo "La Interfaz de la $PROGNAME NO INCLUYE ABSOLUTAMENTE NINGUNA GARANTÍA."
84    echo "Para mayor información vea los términos de la licencia en LICENSE.txt"
85    echo "Este es un software abierto, por lo que lo invitamos a que lo distribuya de forma gratuita"
86elif [ "$glilang" = "fr" ]; then
87    echo "Interface du $PROGNAME ($PROGNAME_EN - $PROGABBR)"
88    echo "Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato"
89    echo "$PROGABBR est fourni sans AUCUNE GARANTIE; pour des détails, voir LICENSE.txt"
90    echo "Ceci est un logiciel libre, et vous êtes invité à le redistribuer"
91elif [ "$glilang" = "ru" ]; then
92    echo "âÉÂÌÉÏÔÅÞÎÙÊ $PROGNAME ($PROGNAME_EN - $PROGABBR)"
93    echo "Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato"
94    echo "âéç ÎÅ ÄÁÅÔ áâóïìàôîï îéëáëéè çáòáîôéê; ÄÅÔÁÌÉ ÓÍ. × ÔÅËÓÔÅ LICENSE.TXT"
95    echo "üÔÏ - Ó×ÏÂÏÄÎÏ ÒÁÓÐÒÏÓÔÒÁÎÑÅÍÏÅ ÐÒÏÇÒÁÍÍÎÏÅ ÏÂÅÓÐÅÞÅÎÉÅ É ÷Ù ÍÏÖÅÔÅ ÒÁÓÐÒÏÓÔÒÁÎÑÔØ ÅÇÏ"
96else
97    echo "$PROGNAME ($PROGABBR)"
98    echo "Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato"
99    echo "$PROGABBR comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt"
100    echo "This is free software, and you are welcome to redistribute it"
101fi
102echo
103
104##  -------- Run the Greenstone Librarian Interface --------
105# Need to run this script from its own directory instead of whichever directory it may be called from
106#currentdir=$(cd `dirname "$0"` && pwd)
107thisdir="`dirname \"$0\"`"
108thisdir="`cd \"$thisdir\" && pwd`"
109cd "$thisdir"
110
111
112##  ---- Determine GSDLHOME ----
113## gsdlpath can be either Greenstone 3 or Greenstone 2
114gsdlpath=
115# Some users may set the above line manually
116
117
118# This variable is set automatically:
119_version=
120if [ "x$gsdlpath" != "x" ]; then
121    get_version "$gsdlpath"
122    _version=$?
123# otherwise $gsdlpath is not yet set
124else
125    # Check the environment variable first
126    # Check whether environment variables for both GS2 and GS3 are set
127    # and if so, warn the user that we have defaulted to GS3
128    if [ "x$GSDLHOME" != "x" -a "x$GSDL3SRCHOME" != "x" ]; then
129        # _version not set, but both env vars set, so default to 3
130    _version=3
131    gsdlpath=$GSDL3SRCHOME
132    echo "Both Greenstone 2 and Greenstone 3 environments are set."
133    echo "It is assumed you want to run Greenstone 3."
134    echo "If you want to run Greenstone 2, please unset the"
135    echo "environment variable GSDL3SRCHOME before running GLI."
136    echo ""
137    elif [ "x$GSDL3SRCHOME" != "x" ]; then
138    echo "Only gsdl3srchome set"
139    gsdlpath=$GSDL3SRCHOME
140    _version=3
141    echo "$gsdlpath"
142    elif [ "x$GSDLHOME" != "x" ]; then
143    gsdlpath=$GSDLHOME
144    _version=2
145    # If it is not set, assume that the GLI is installed as a subdirectory of Greenstone
146    else
147    gsdlpath=`(cd .. && pwd)`
148    # Still need to find what version we are running:
149    # GS3 main directory contains file gs3-setup.sh, GS2 only setup.bash
150    get_version "$gsdlpath"
151    _version=$?
152    fi
153fi
154
155echo "Greenstone version found: $_version"
156
157# Check that the main Greenstone installation for the version we're running looks OK
158check_installation "$gsdlpath" "$_version" "$glilang"
159
160
161# Need to source the correct setup file depending on whether we are running
162# gs3 or gs2
163# If we're running version GS2
164if [ "$_version" -eq 2 ]; then
165    # Setup Greenstone 2, unless it has already been done
166    if [ "x$GSDLHOME" = "x" ]; then
167    cd "$gsdlpath"
168    . ./setup.bash
169    cd "$thisdir"
170    fi
171# else, if we're running GS3
172elif [ "$_version" -eq 3 ]; then
173    # Setup Greenstone 3, unless it has already been done
174    if [ "x$GSDL3HOME" = "x" -o "x$GSDL3SRCHOME" = "x" ]; then
175    cd "$gsdlpath"
176    . ./gs3-setup.sh
177    cd "$thisdir"
178    fi
179   
180    ## if Greenstone version 3 is running, we want to set gsdl2path
181    ##  ---- Determine GSDLHOME ----
182    ## may be already set, or manually entered here.
183    gsdl2path=
184   
185    # Some users may set the above line manually
186    if [ "x$gsdl2path" = "x" ]; then
187        # Check the environment variable first
188    if [ "x$GSDLHOME" != "x" ]; then
189        echo "GSDLHOME environment variable is set to $GSDLHOME."
190        echo "Will use this to find build scripts."
191        gsdl2path=$GSDLHOME
192        # If it is not set, assume that the gs2build subdirectory of Greenstone 3 exists
193    else
194        gsdl2path=$GSDL3SRCHOME/gs2build
195    fi
196    fi
197    # Check that Greenstone 3's Greenstone 2 stuff looks OK (in gs2build)
198    check_installation "$gsdl2path" "" "$glilang"
199 
200    # Setup Greenstone 3's gs2build, unless it has already been done
201    if [ "x$GSDLHOME" = "x" ]; then
202    cd "$gsdl2path"
203    . ./setup.bash
204    cd "$thisdir"
205    fi
206
207else
208    echo "Greenstone version unknown."   
209    exit 1
210fi
211
212echo
213if [ "x$GSDL3SRCHOME" != "x" ]; then
214    echo "GSDL3SRCHOME is: $GSDL3SRCHOME"
215fi
216if [ "x$GSDL3HOME" != "x" ]; then
217    echo "GSDL3HOME is: $GSDL3HOME"
218fi
219if [ "x$GSDLHOME" != "x" ]; then
220    echo "GSDLHOME is: $GSDLHOME"
221fi
222echo
223
224## ---- find perl ----
225exit_status=0
226./findperl.sh
227exit_status=$?
228if [ "$exit_status" -eq 1 ]; then
229    exit 1;
230fi
231
232## ---- Check Java ----
233# call the script with source, so that we have the variables it sets ($javapath)
234exit_status=0
235source ./findjava.sh
236exit_status=$?
237if [ "$exit_status" -eq 1 ]; then
238    exit 1;
239fi
240
241## ---- Check that the GLI has been compiled ----
242if [ ! -f "classes/org/greenstone/gatherer/GathererProg.class" ] && [ ! -f "GLI.jar" ]; then
243    echo
244    if [ "$glilang" = "es" ]; then
245    echo "Usted necesita compilar la Interfaz de la Biblioteca Digital Greenstone"
246    echo "(por medio de makegli.sh) antes de ejecutar este guión."
247    elif [ "$glilang" = "fr" ]; then
248    echo "Vous devez compiler le Greenstone Interface (en utilisant makegli.sh)"
249    echo "avant d'exécuter ce script."
250    elif [ "$glilang" = "ru" ]; then
251    echo "÷Ù ÄÏÌÖÎÙ ËÏÍÐÉÌÉÒÏ×ÁÔØ ÂÉÂÌÉÏÔÅÞÎÙÊ ÉÎÔÅÒÆÅÊÓ Greenstone"
252    echo "(ÉÓÐÏÌØÚÕÑ makegli.sh) ÐÅÒÅÄ ××ÏÄÏÍ ÜÔÏÇÏ ÓËÒÉÐÔÁ"
253    else
254    echo "You need to compile the Greenstone Librarian Interface (using makegli.sh)"
255    echo "before running this script."
256    fi
257    exit 1
258fi
259
260## ---- Explain how to bypass Imagemagick and Ghostscript bundled with Greenstone if needed ----
261if [ -e "$GSDLHOME/bin/$GSDLOS/ghostscript" ] ; then
262echo "GhostScript bundled with Greenstone will be used, if you wish to use the version installed on your system (if any) please go to $GSDLHOME/bin/$GSDLOS and rename the folder called ghostscript to something else."
263fi
264echo
265echo
266if [ -e "$GSDLHOME/bin/$GSDLOS/imagemagick" ] ; then
267echo "ImageMagick bundled with Greenstone will be used, if you wish to use the version installed on your system (if any) please go to $GSDLHOME/bin/$GSDLOS and rename the folder called imagemagick to something else."
268echo
269echo
270fi
271
272
273## ---- Finally, run the GLI ----
274if [ "$glilang" = "es" ]; then
275    echo "Ejecutando la Interfaz de la $PROGNAME..."
276elif [ "$glilang" = "fr" ]; then
277    echo "Exécution de $PROGNAME..."
278elif [ "$glilang" = "ru" ]; then
279    echo "ôÅËÕÝÉÊ ÂÉÂÌÉÏÔÅÞÎÙÊ $PROGNAME..."
280else
281    echo "Running the $PROGNAME..."
282fi
283
284# basic_command is the cmd string common to both Greenstone 3 and Greenstone 2 execution
285#basic_command="$javapath -Xmx128M -classpath classes/:GLI.jar:lib/apache.jar:lib/qfslib.jar org.greenstone.gatherer.GathererProg"
286stop_gli=0
287while [ "$stop_gli" = "0" ] ; do
288   
289    # Other arguments you can provide to GLI to work around memory limitations, or debug
290    # -Xms<number>M    To set minimum memory (by default 32MB)
291    # -Xmx<number>M    To set maximum memory (by default the nearest 2^n to the total remaining physical memory)
292    # -verbose:gc      To set garbage collection messages
293    # -Xincgc          For incremental garbage collection (significantly slows performance)
294    # -Xprof           Function call profiling
295    # -Xloggc:<file>   Write garbage collection log
296   
297    exit_status=0
298    if [ "$_version" -eq 2 ]; then
299# GS2 webLib
300    if [ "$PROGABBR" = "FLI" -o ! -f "$GSDLHOME/gs2-server.sh" ]; then
301        "$javapath" -Xmx128M -classpath classes/:GLI.jar:lib/apache.jar:lib/qfslib.jar org.greenstone.gatherer.GathererProg -gsdl "$GSDLHOME" -gsdlos $GSDLOS $*
302        exit_status=$?
303# GS2 localLib
304    else
305        "$javapath" -Xmx128M -classpath classes/:GLI.jar:lib/apache.jar:lib/qfslib.jar org.greenstone.gatherer.GathererProg -gsdl "$GSDLHOME" -gsdlos $GSDLOS -local_library "$GSDLHOME/gs2-server.sh" $*
306        exit_status=$?
307    fi
308# GS3
309    elif [ "$_version" -eq 3 ]; then   
310        "$javapath" -Xmx128M -classpath classes/:GLI.jar:lib/apache.jar:lib/qfslib.jar org.greenstone.gatherer.GathererProg -gsdl "$GSDLHOME" -gsdlos $GSDLOS -gsdl3 "$GSDL3HOME" -gsdl3src "$GSDL3SRCHOME" $*
311        exit_status=$?
312    fi
313   
314    if [ "$exit_status" != "2" ] ; then
315        stop_gli=1
316    else
317        echo
318        if [ "$glilang" = "es" ]; then
319            echo "Restarting/Ejecutando la Interfaz de la $PROGNAME..."
320        elif [ "$glilang" = "fr" ]; then
321            echo "Restarting/Exécution de $PROGNAME..."
322        elif [ "$glilang" = "ru" ]; then
323            echo "Restarting/ôÅËÕÝÉÊ ÂÉÂÌÉÏÔÅÞÎÙÊ $PROGNAME..."
324        else
325            echo "Restarting the $PROGNAME..."
326        fi
327    fi
328done
329
330if [ "$glilang" = "es" ]; then
331    echo "¡Hecho!"
332elif [ "$glilang" = "fr" ]; then
333    echo "Terminé!"
334elif [ "$glilang" = "ru" ]; then
335    echo "÷ÙÐÏÌÎÅÎÏ!"
336else
337    echo "Done!"
338fi
Note: See TracBrowser for help on using the browser.