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