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

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

Bugfixes (2) to previous commit: splitting long lines with carets requires a space before or after the caret. But a set command can't start with a space, and the ampersand character chaining commands should not leave trailing white space in the previous set operation else the white space becomes part of the variable assignment done with the set.

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