source: main/trunk/greenstone3/gs3-setup.bat@ 31471

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

Removed dangerous trailing whitespace when setting environment variable

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 14.3 KB
Line 
1@echo off
2
3setlocal enabledelayedexpansion
4
5set java_min_version=1.5.0_00
6
7if exist gs3-setup.bat goto prelim
8 echo This script must be run from within the Greenstone 3 home directory
9 goto done
10
11:prelim
12if "!GSDL3SRCHOME!" == "" goto start
13if "!GSDL3SRCHOME!" == "!CD!" (
14 echo Your environment is already set up for Greenstone3
15 goto done
16) else (
17 echo Your environment was set up for Greenstone 3 in !GSDL3SRCHOME!.
18 echo Overwriting that set up for the current Greenstone 3 in !CD!.
19)
20
21:start
22:: ---- Set some relevant environment variables ----
23
24:: this is the default
25:: greenstone3 (!GSDL3SRCHOME!)
26:: +-- web (!GSDL3HOME!)
27:: +-- packages
28:: +-- tomcat (!TOMCAT_HOME!)
29:: +-- ant (!ANT_HOME!)
30
31:: set GSDL3SRCHOME to the current directory
32cd | winutil\setvar.exe GSDL3SRCHOME > !TMP!\setgsdl3.bat
33call !TMP!\setgsdl3.bat
34del !TMP!\setgsdl3.bat
35
36:: set GSDL3HOME to the 'web' subdirectory
37set GSDL3HOME=!GSDL3SRCHOME!\web
38set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
39:: set GSDL3HOME to any web.home property provided, and create that folder if it doesn't exist
40:: Replace forward slashes in web.home with back slashes
41:: http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute!OpenDocument&ExpandSection=3&BaseTarget=East&AutoFramed
42if exist "!GSDL3SRCHOME!\build.properties" for /F "usebackq tokens=1,2 delims==" %%G in ("!GSDL3SRCHOME!\build.properties") do (
43 if "%%G"=="web.home" (
44 set GSDL3HOME=%%H
45 set GSDL3HOME=!GSDL3HOME:/=\!
46 set WEB_CONTAINING_CLASSES=!GSDL3HOME!
47 if not exist "!GSDL3HOME!" cmd /c "!GSDL3SRCHOME!\userweb.cmd"
48 goto foundwebhome
49 )
50)
51
52:foundwebhome
53:: Whatever the web directory is, it should contain the WEB-INF\classes folder, else go back to using default for this
54:: The WEB-INF\classes folder will be absent in a userweb folder, but will be present if GSDL3HOME=GSDL3SRCHOME\web
55:: or if web.home points to GS3 as a webapp inside tomcat
56if not exist "!GSDL3HOME!\WEB-INF\classes" set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
57
58:: change if using external tomcat or ant
59set TOMCAT_HOME=!GSDL3SRCHOME!\packages\tomcat
60if exist "!GSDL3SRCHOME!\packages\ant\*.*" set ANT_HOME=!GSDL3SRCHOME!\packages\ant
61
62:: other important environment variables
63set GSDLOS=windows
64
65:: ---- Set the CLASSPATH and PATH environment variables ----
66if "!GS_CP_SET!" == "yes" goto skipSetCp
67set CLASSPATH=!WEB_CONTAINING_CLASSES!\WEB-INF\classes;!GSDL3SRCHOME!\resources\java;!GSDL3SRCHOME!\cp.jar;!CLASSPATH!;
68set PATH=!GSDL3SRCHOME!\bin;!GSDL3SRCHOME!\bin\script;!GSDL3SRCHOME!\lib\jni;!ANT_HOME!\bin;!PATH!
69
70:: Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
71:: if exist "!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin\gsdll32.dll" set GS_DLL=!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin\gsdll32.dll
72:: if exist "!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\lib\*.*" set GS_LIB=!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\lib
73:: if exist "!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin\*.*" set PATH=!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin;!PATH!
74:: if exist "!GSDL3SRCHOME!\gs2build\bin\windows\imagemagick\*.*" set PATH=!GSDL3SRCHOME!\gs2build\bin\windows\imagemagick;!PATH!
75
76:: a little dynamic set cp stuff
77if exist "!TMP!\setcp.bat" del "!TMP!\setcp.bat"
78
79:: http://ss64.com/nt/for_cmd.html, how to deal with spaces in the file list in a for command
80:: Note that TOMCAT_HOME\common\endorsed only exists for Tomcat 5, not Tomcat 6
81:: (where it contains xercesImpl.jar and xml-apis.jar which aren't there in Tomcat 6)
82if exist "!TOMCAT_HOME!\common\endorsed\*.jar" for /f %%j in ('dir/b ^"!TOMCAT_HOME!\common\endorsed\*.jar^"') do echo set CLASSPATH=%%CLASSPATH%%;%%TOMCAT_HOME%%\common\endorsed\%%j>> !TMP!\setcp.bat
83for /f %%j in ('dir/b ^"!TOMCAT_HOME!\lib\*.jar^"') do echo set CLASSPATH=%%CLASSPATH%%;%%TOMCAT_HOME%%\lib\%%j>> !TMP!\setcp.bat
84
85if exist !TMP!\setcp.bat call !TMP!\setcp.bat
86if exist !TMP!\setcp.bat del !TMP!\setcp.bat
87
88set GS_CP_SET=yes
89:skipSetCp
90
91:: ---- if gs2build is there, run its setup.bat file ----
92endlocal & set RUNJAVA=%RUNJAVA%& set PATH=%PATH%& set GSDLOS=%GSDLOS%& set GSDLHOME=%GSDLHOME%& set GSDL3HOME=%GSDL3HOME%& set GSDL3SRCHOME=%GSDL3SRCHOME%& set JAVA_HOME=%JAVA_HOME%& set JRE_HOME=%JRE_HOME%& set ANT_HOME=%ANT_HOME%& set CLASSPATH=%CLASSPATH%
93
94if exist gs2build\setup.bat (
95 echo.
96 echo Running gs2build\setup.bat
97 cd gs2build
98 call setup.bat
99 cd ..
100)
101
102:: ---- Check for any setup files in ext or local folders ----
103if exist ext (
104 for /D %%e IN ("ext/*") do (
105 cd ext\%%e
106 if EXIST gs3-setup.bat (
107 call gs3-setup.bat
108 ) else (
109 if EXIST setup.bat call setup.bat
110 )
111 cd ..\..
112 )
113)
114
115
116if exist local\gs3-setup.bat (
117 echo.
118 echo Running local\gs3-setup.bat
119 cd local
120 call gs3-setup.bat
121 cd ..
122)
123
124setlocal enabledelayedexpansion
125
126:: ---- Search for java ----
127set JAVA_MIN_VERSION=1.5.0_00
128set BUNDLED_JRE=!CD!\packages\jre
129set HINT=!BUNDLED_JRE!
130
131::if search4j is present, use it
132set FOUNDJAVAHOME=
133set RUNJAVA=
134if exist bin\search4j.exe (
135 for /F "tokens=*" %%r in ('bin\search4j.exe -d -p "!HINT!" -m !JAVA_MIN_VERSION!') do set FOUNDJAVAHOME=%%r
136 for /F "tokens=*" %%r in ('bin\search4j.exe -r -p "!HINT!" -m !JAVA_MIN_VERSION!') do set FOUNDJREHOME=%%r
137)
138
139
140echo.
141echo ********************************************************************
142
143rem Check if any Java found matches the bitness of the Greenstone installation's binaries
144rem The sort of output we want:
145:: Installed GS as 32 bit
146:: Detected java is 64 bit
147:: Changing to use the GS bundled 32 bit jre
148:: We've detected a mismatch, this will only affect MG/MGPP collections for searching and GDBM database collections
149
150:: 1. What bit-ness are this Greenstone installation's binaries?
151:: GNUfile: http://stackoverflow.com/questions/2689168/checking-if-file-is-32bit-or-64bit-on-windows
152:: http://gnuwin32.sourceforge.net/packages/file.htm
153:: Also http://stackoverflow.com/questions/4089641/programatically-determine-if-native-exe-is-32-bit-or-64-bit
154:: http://stackoverflow.com/questions/2062020/how-can-i-tell-if-im-running-in-64-bit-jvm-or-32-bit-jvm-from-within-a-program
155:: Messy way: http://superuser.com/questions/358434/how-to-check-if-a-binary-is-32-or-64-bit-on-windows
156
157:: "%GSDLHOME%\bin\windows\GNUfile\bin\file.exe" "%GSDLHOME%\bin\windows\wvWare.exe"
158:: But we'll test the bitness of gdbmjava.dll itself as it's guaranteed to be present in GS3 and is also dependent on JNI
159:: No need to have the right bitness for GS2, since it doesn't use JNI
160
161:: See https://ss64.com/nt/for_cmd.html for using batch FOR to loop against the results of another command.
162:: Running
163:: for /f "usebackq delims=" %%G IN (`"gs2build\bin\windows\GNUfile\bin\file.exe" gs2build\bin\windows\wvWare.exe`) do echo %%G
164:: prints out the entire output, e.g.:
165:: gs2build\bin\windows\wvWare.exe; PE32 executable for MS Windows (console) Intel 80386 32-bit
166:: To just get the "PE32" part of that output, set the delimiter char to space and request only the 2nd token:
167:: Note: Using call before the command to allow 2 sets of double quotes, see
168:: http://stackoverflow.com/questions/6474738/batch-file-for-f-doesnt-work-if-path-has-spaces
169:: Could use shortfilenames, see http://stackoverflow.com/questions/10227144/convert-long-filename-to-short-filename-8-3-using-cmd-exe
170if not exist "!GSDL3SRCHOME!\lib\jni\gdbmjava.dll" set bitness=UNKNOWN& goto testjavahome
171for /f "usebackq tokens=2 delims= " %%G IN (`call "!GSDLHOME!\bin\windows\GNUfile\bin\file.exe" "!GSDL3SRCHOME!\lib\jni\gdbmjava.dll"`) do set bitness=%%G
172
173if "%bitness%" == "PE32+" (
174 set bitness=64
175 echo The installed Greenstone is 64 bit
176) else (
177 if "%bitness%" == "PE32" (
178 set bitness=32
179 echo The installed Greenstone is 32 bit
180 ) else (
181 echo WARNING: Greenstone installation is of unknown bitness. "%bitness%" is neither 32 nor 64 bit
182 set bitness=UNKNOWN
183 )
184)
185
186:: 2. What bitness are any JAVA_HOME else JRE_HOME found by search4j?
187:: If you run the non-existent program "pinky" from batch or the DOS console, the exit value is 9009
188:: The same must be true if java is not installed and therefore not found. echo %errorlevel% produces 9009
189:: If java exists and is 32 bit, then running "java -d32 -version" has a return value of 1. echo %errorlevel% (1)
190:: If java exists and is 64 bit, then running "java -d32 -version" has a return value of 0. echo %errorlevel% (0)
191
192:testjavahome
193:: http://www.robvanderwoude.com/errorlevel.php
194:: https://ss64.com/nt/errorlevel.html
195if DEFINED FOUNDJAVAHOME (
196 if "%bitness%" == "UNKNOWN" goto setupjavahome
197 echo *** Testing bitness of JAVA_HOME found at !FOUNDJAVAHOME!:
198 "!FOUNDJAVAHOME!\bin\java.exe" -d%bitness% -version 2> nul
199 if !ERRORLEVEL! equ 1 echo *** The detected JDK java is incompatible with !bitness! bit GS& goto testjre
200 if !ERRORLEVEL! equ 0 (
201 echo *** The detected JDK java is a matching %bitness% bit
202 goto setupjavahome
203 )
204)
205
206:testjre
207if DEFINED FOUNDJREHOME (
208 if "%bitness%" == "UNKNOWN" goto setupjrehome
209 echo *** Testing bitness of JRE_HOME found at !FOUNDJREHOME!:
210 "!FOUNDJREHOME!\bin\java.exe" -d%bitness% -version 2> nul
211 if !ERRORLEVEL! equ 1 echo *** The detected JRE java is incompatible with !bitness! bit GS& goto testbundledjre
212 if !ERRORLEVEL! equ 0 (
213 rem The JRE_HOME found by search4j may be the bundled JRE, overriding any system JRE_HOME,
214 rem because the bundled JRE_HOME was provided as HINT to search4j.
215 echo *** The detected JRE java is a matching %bitness% bit
216 goto setupjrehome
217 )
218)
219
220:: 3. Fall back to 32 bit JRE bundled with GS
221:testbundledjre
222if exist "!BUNDLED_JRE!\bin\java.exe" (
223 if "%bitness%" == "UNKNOWN" goto bundledjre
224
225 echo *** Testing bitness of bundled JRE at !BUNDLED_JRE!:
226 "!BUNDLED_JRE!\bin\java.exe" -d%bitness% -version 2> nul
227 if !ERRORLEVEL! equ 1 echo *** The detected JRE java is incompatible with !bitness! bit& goto setupjavahome
228 if !ERRORLEVEL! equ 0 (
229 echo *** The detected JRE java is a matching %bitness% bit
230 goto bundledjre
231 )
232)
233
234:bundledjre
235:: We bundled a 32 bit JRE, but what if GS was compiled with 64 bit Java?
236:: All but MG/MGPP and GDBM should still work with 64 bit java.
237if exist "!BUNDLED_JRE!\bin\java.exe" (
238 echo *** Changing to use Greenstone's bundled jre.
239 set JRE_HOME=!BUNDLED_JRE!
240 ::set JAVA_HOME=!BUNDLED_JRE!
241 set PATH=!JRE_HOME!\bin;!PATH!
242 set RUNJAVA=!JRE_HOME!\bin\java.exe
243 goto summaryThenEnd
244)
245
246:: 4. If no bundled JRE exists either, we'd still need to check if search4j found a JAVA_HOME or JRE_HOME
247:: and use that even if there was a bitness mismatch btw GS3 and the Java found.
248:: Label summaryThenEnd will print out warnings on any mismatch
249:setupjavahome
250if DEFINED FOUNDJAVAHOME (
251 echo *** Using the JAVA_HOME detected at !FOUNDJAVAHOME!
252 set JAVA_HOME=!FOUNDJAVAHOME!
253 set PATH=!FOUNDJAVAHOME!\bin;!PATH!
254 set RUNJAVA=!FOUNDJAVAHOME!\bin\java.exe
255 goto summaryThenEnd
256)
257
258:setupjrehome
259if DEFINED FOUNDJREHOME (
260 echo *** Using the JRE_HOME detected at !FOUNDJREHOME!
261 set JRE_HOME=!FOUNDJREHOME!
262 set PATH=!FOUNDJREHOME!\bin;!PATH!
263 set RUNJAVA=!FOUNDJREHOME!\bin\java.exe
264 goto summaryThenEnd
265)
266
267if exist "!BUNDLED_JRE!\bin\java.exe" goto bundledjre
268
269:: 5. Last ditch effort: search4j couldn't find any java, but check any Java env vars set anyway
270echo *** Search4j could not find an appropriate JDK or JRE java.
271echo *** Attempting to use any JAVA_HOME else JRE_HOME in the environment...
272
273if exist "!JAVA_HOME!\bin\java.exe" (
274 set PATH=!JAVA_HOME!\bin;!PATH!
275 set RUNJAVA=!JAVA_HOME!\bin\java.exe
276 echo Using Java at !JAVA_HOME!
277 echo WARNING: Greenstone has not checked the version number of this Java installation
278 echo The source distribution of Greenstone3 requires Java 1.5 or greater
279 echo SVN users may still use Java 1.4
280 echo.
281 goto summaryThenEnd
282)
283
284if exist "!JRE_HOME!\bin\java.exe" (
285 set PATH=!JRE_HOME!\bin;!PATH!
286 set RUNJAVA=!JRE_HOME!\bin\java.exe
287 echo Using Java at !JRE_HOME!
288 echo WARNING: Greenstone has not checked the version number of this JRE installation
289 echo The source distribution of Greenstone3 requires Java 1.5 or greater
290 echo SVN users may still use Java 1.4
291 echo.
292 goto summaryThenEnd
293)
294
295echo ERROR: Failed to locate Java
296echo Please set JAVA_HOME or JRE_HOME to point to an appropriate %bitness% bit Java
297goto end
298
299:summaryThenEnd
300:: 6. Check that the bitness of any Java found is appropriate and warn if it is not.
301if "%bitness%" == "UNKNOWN" goto displayvars
302"!RUNJAVA!" -d%bitness% -version 2> nul
303if !ERRORLEVEL! equ 1 (
304 echo *** WARNING: Detected mismatch between the bit-ness of your Greenstone installation ^(!bitness! bit^)
305 echo *** and the Java found at !RUNJAVA!.
306 echo *** Continuing with this Java anyway:
307 echo *** This will only affect MG/MGPP collections for searching, and GDBM database collections
308 echo *** Else set JAVA_HOME or JRE_HOME to point to an appropriate %bitness%-bit Java
309 echo *** Or recompile GS with your system Java:
310 if exist "!JAVA_HOME!" ( echo *** JAVA_HOME at !JAVA_HOME! ) else ( echo *** JRE_HOME at !JRE_HOME! )
311)
312
313:displayvars
314echo ********************************************************************
315echo.
316
317echo GSDL3SRCHOME : !GSDL3SRCHOME!
318echo GSDL3HOME : !GSDL3HOME!
319echo JAVA : !RUNJAVA!
320
321if "!ANT_HOME!" == "" (
322 echo.
323 echo ANT_HOME is not yet set.
324 echo Please make sure you have Ant version 1.7.1 or higher installed
325 echo Then set ANT_HOME to the Ant installation folder
326 echo and add the path to its bin folder to the PATH environment variable
327) else (
328 echo ANT_HOME : !ANT_HOME!
329)
330echo.
331
332:done
333:: End localisation of variables that started with the set local/set enabledelayedexpansion command
334:: Restore global variables that would otherwise be lost at script's end due to their having been initialised in a
335:: set local/set enabledelayedexpansion section. See http://ss64.com/nt/endlocal.html
336endlocal & set RUNJAVA=%RUNJAVA%& set PATH=%PATH%& set GSDLOS=%GSDLOS%& set GSDLHOME=%GSDLHOME%& set GSDL3HOME=%GSDL3HOME%& set GSDL3SRCHOME=%GSDL3SRCHOME%& set JAVA_HOME=%JAVA_HOME%& set JRE_HOME=%JRE_HOME%& set ANT_HOME=%ANT_HOME%& set CLASSPATH=%CLASSPATH%
337
338:end
Note: See TracBrowser for help on using the repository browser.