source: main/trunk/gli/findgsdl.sh@ 29369

Last change on this file since 29369 was 20186, checked in by kjdon, 15 years ago

added some quotes around various paths so that can install into somewhere with spaces in path

File size: 6.5 KB
Line 
1# Can't use exit in this script, since the script will be sourced
2# The calling script will end up exiting too, if we exit here
3
4# Uses GLIMODE which would have been set by the calling (client-)gli script.
5# This script sets GSDLHOME and _version, if a GS installation can be found.
6# May also set GSDL3SRCHOME and GSDL3HOME if a GS3 installation was found.
7
8
9# Prints a message if the greenstone version is unknown, depending on whether
10# the calling script launches the client-gli or not
11function version_unknown {
12 # if GLIMODE is client, we can live without a local GS installation
13 if [ "x$GLIMODE" == "xclient" ]; then
14 if [ "x$GLILANG" = "en" -o "x$GLILANG" = "x" ]; then
15 echo "Could not detect a Greenstone installation (no GSDLHOME)."
16 fi
17 # otherwise GLIMODE is not client, in which case it is an error to not know the version
18 else
19 if [ "x$GLILANG" = "en" -o "x$GLILANG" = "x" ]; then
20 echo "Error: can't determine which Greenstone version is being run."
21 fi
22 fi
23 echo
24}
25
26# Function that, when given gsdlpath as parameter, will return the
27# version of greenstone that is to run (2 or 3). If the version remains
28# unknown this script will return 1.
29function get_version {
30 # first parameter is value of gsdlpath
31 if [ -f "${1}/gs3-setup.sh" ]; then
32 return 3
33 elif [ -f "${1}/setup.bash" ]; then
34 return 2
35 else
36 # print message and return 1, which is not a valid Greenstone version
37 version_unknown
38 return 1
39 fi
40}
41
42# Function that is passed the following paramters (in order):
43# - the gsdlpath (GS3 home, GS2 home or gs2build for GS3),
44# - the version of greenstone that's running, and
45# - the language GLI is set to
46# and checks the installation.
47# If things are not right, this program will exit here.
48function check_installation {
49# Check that the Greenstone installation looks OK
50 if [ "$3" = "es" ]; then
51 echo "Revisando GSDL$2: $1"
52 elif [ "$3" = "fr" ]; then
53 echo "Vérification de GSDL$2: $1"
54 elif [ "$3" = "ru" ]; then
55 echo "ðÒÏ×ÅÒËÁ GSDL$2: $1"
56 else
57 echo "Checking GSDL$2: $1"
58 fi
59 # even if we are only checking for gs2build (gsdl2path), we still
60 # need the file setup.bash to exist in the following condition:
61 if [ ! -f "${1}/gs3-setup.sh" -a ! -f "${1}/setup.bash" ] ; then
62 echo
63 if [ "$3" = "es" ]; then
64 echo "No se pudo encontrar la instalación de Greenstone $2 o está incompleta."
65 echo "Trate de reinstalar Greenstone $2 y a continuación ejecute nuevamente"
66 echo "este guión."
67 elif [ "$3" = "fr" ]; then
68 echo "L'installation de Greenstone $2 est introuvable ou incomplète."
69 echo "Essayez de réinstaller Greenstone $2 et exécutez ce script à nouveau."
70 elif [ "$3" = "ru" ]; then
71 echo "éÎÓÔÁÌÌÑÃÉÑ Greenstone $_version ÎÅ ÂÙÌÁ ÎÁÊÄÅÎÁ ÉÌÉ ÏÎÁ ÎÅÐÏÌÎÁ."
72 echo "ðÏÐÒÏÂÕÊÔÅ ÐÏ×ÔÏÒÎÏ ÕÓÔÁÎÏ×ÉÔØ Greenstone $2, Á ÚÁÔÅÍ ××ÅÓÔÉ ÜÔÏÔ ÓËÒÉÐÔ ÓÎÏ×Á."
73 else
74 echo "The Greenstone $2 installation could not be found, or is incomplete."
75 echo "Try reinstalling Greenstone $2 then running this script again."
76 fi
77 exit 1
78 fi
79}
80
81
82## ---- Determine GSDLHOME ----
83## gsdlpath can be either Greenstone 3 or Greenstone 2
84gsdlpath=
85# Some users may set the above line manually
86
87
88# This variable is set automatically:
89_version=
90if [ "x$gsdlpath" != "x" ]; then
91 get_version "$gsdlpath"
92 _version=$?
93# otherwise $gsdlpath is not yet set
94else
95 # Check the environment variable first
96 # Check whether environment variables for both GS2 and GS3 are set
97 # and if so, warn the user that we have defaulted to GS3
98 if [ "x$GSDLHOME" != "x" -a "x$GSDL3SRCHOME" != "x" ]; then
99 # _version not set, but both env vars set, so default to 3
100 _version=3
101 gsdlpath="$GSDL3SRCHOME"
102 echo "Both Greenstone 2 and Greenstone 3 environments are set."
103 echo "It is assumed you want to run Greenstone 3."
104 echo "If you want to run Greenstone 2, please unset the"
105 echo "environment variable GSDL3SRCHOME before running GLI."
106 echo ""
107 elif [ "x$GSDL3SRCHOME" != "x" ]; then
108 echo "Only gsdl3srchome set"
109 gsdlpath="$GSDL3SRCHOME"
110 _version=3
111 echo "$gsdlpath"
112 elif [ "x$GSDLHOME" != "x" ]; then
113 gsdlpath="$GSDLHOME"
114 _version=2
115 # If it is not set, assume that the GLI is installed as a subdirectory of Greenstone
116 else
117 gsdlpath=`(cd .. && pwd)`
118 # Still need to find what version we are running:
119 # GS3 main directory contains file gs3-setup.sh, GS2 only setup.bash
120 get_version "$gsdlpath"
121 _version=$?
122 fi
123fi
124
125# if it's an invalid greenstone version, we exit the script here
126if [ "$_version" -lt 2 ]; then
127 return $_version;
128fi
129
130echo "Greenstone version found: $_version"
131
132# Check that the main Greenstone installation for the version we're running looks OK
133check_installation "$gsdlpath" "$_version" "$glilang"
134
135
136# Need to source the correct setup file depending on whether we are running
137# gs3 or gs2
138# If we're running version GS2
139if [ "$_version" -eq 2 ]; then
140 # Setup Greenstone 2, unless it has already been done
141 if [ "x$GSDLHOME" = "x" ]; then
142 cd "$gsdlpath"
143 . ./setup.bash
144 cd "$thisdir"
145 fi
146# else, if we're running GS3
147elif [ "$_version" -eq 3 ]; then
148 # Setup Greenstone 3, unless it has already been done
149 if [ "x$GSDL3HOME" = "x" -o "x$GSDL3SRCHOME" = "x" ]; then
150 cd "$gsdlpath"
151 . ./gs3-setup.sh
152 cd "$thisdir"
153 fi
154
155 ## if Greenstone version 3 is running, we want to set gsdl2path
156 ## ---- Determine GSDLHOME ----
157 ## may be already set, or manually entered here.
158 gsdl2path=
159
160 # Some users may set the above line manually
161 if [ "x$gsdl2path" = "x" ]; then
162 # Check the environment variable first
163 if [ "x$GSDLHOME" != "x" ]; then
164 echo "GSDLHOME environment variable is set to $GSDLHOME."
165 echo "Will use this to find build scripts."
166 gsdl2path="$GSDLHOME"
167 # If it is not set, assume that the gs2build subdirectory of Greenstone 3 exists
168 else
169 gsdl2path="$GSDL3SRCHOME/gs2build"
170 fi
171 fi
172 # Check that Greenstone 3's Greenstone 2 stuff looks OK (in gs2build)
173 check_installation "$gsdl2path" "" "$glilang"
174
175 # Setup Greenstone 3's gs2build, unless it has already been done
176 if [ "x$GSDLHOME" = "x" ]; then
177 cd "$gsdl2path"
178 . ./setup.bash
179 cd "$thisdir"
180 fi
181
182else
183 echo "Greenstone version unknown."
184 return 1
185fi
186
187echo
188if [ "x$GSDL3SRCHOME" != "x" ]; then
189 echo "GSDL3SRCHOME is: $GSDL3SRCHOME"
190fi
191if [ "x$GSDL3HOME" != "x" ]; then
192 echo "GSDL3HOME is: $GSDL3HOME"
193fi
194if [ "x$GSDLHOME" != "x" ]; then
195 echo "GSDLHOME is: $GSDLHOME"
196fi
197echo
Note: See TracBrowser for help on using the repository browser.