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

Last change on this file since 38874 was 35662, checked in by davidb, 3 years ago

Updated echo statement to reflect the new ant minimum number

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 16.2 KB
RevLine 
[15071]1@echo off
2
[22069]3setlocal enabledelayedexpansion
4
[31472]5set DEBUG=false
6
[20191]7set java_min_version=1.5.0_00
[15071]8
[27832]9if exist gs3-setup.bat goto prelim
[15071]10 echo This script must be run from within the Greenstone 3 home directory
[27832]11 goto done
[15071]12
[27832]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
[15071]23:start
[15363]24:: ---- Set some relevant environment variables ----
25
26:: this is the default
[22069]27:: greenstone3 (!GSDL3SRCHOME!)
28:: +-- web (!GSDL3HOME!)
[15363]29:: +-- packages
[22069]30:: +-- tomcat (!TOMCAT_HOME!)
31:: +-- ant (!ANT_HOME!)
[15363]32
[24374]33:: set GSDL3SRCHOME to the current directory
[22069]34cd | winutil\setvar.exe GSDL3SRCHOME > !TMP!\setgsdl3.bat
35call !TMP!\setgsdl3.bat
36del !TMP!\setgsdl3.bat
[15363]37
[24374]38:: set GSDL3HOME to the 'web' subdirectory
[22069]39set GSDL3HOME=!GSDL3SRCHOME!\web
[30574]40set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
[30568]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
[30592]44if exist "!GSDL3SRCHOME!\build.properties" for /F "usebackq tokens=1,2 delims==" %%G in ("!GSDL3SRCHOME!\build.properties") do (
[30568]45 if "%%G"=="web.home" (
46 set GSDL3HOME=%%H
47 set GSDL3HOME=!GSDL3HOME:/=\!
[30574]48 set WEB_CONTAINING_CLASSES=!GSDL3HOME!
[30568]49 if not exist "!GSDL3HOME!" cmd /c "!GSDL3SRCHOME!\userweb.cmd"
[30574]50 goto foundwebhome
51 )
[30568]52)
[15071]53
[30574]54:foundwebhome
[30568]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
[30574]58if not exist "!GSDL3HOME!\WEB-INF\classes" set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
[30568]59
[15363]60:: change if using external tomcat or ant
[22069]61set TOMCAT_HOME=!GSDL3SRCHOME!\packages\tomcat
62if exist "!GSDL3SRCHOME!\packages\ant\*.*" set ANT_HOME=!GSDL3SRCHOME!\packages\ant
[15071]63
[15363]64:: other important environment variables
[15071]65set GSDLOS=windows
[15363]66
67:: ---- Set the CLASSPATH and PATH environment variables ----
[22069]68if "!GS_CP_SET!" == "yes" goto skipSetCp
[30574]69set CLASSPATH=!WEB_CONTAINING_CLASSES!\WEB-INF\classes;!GSDL3SRCHOME!\resources\java;!GSDL3SRCHOME!\cp.jar;!CLASSPATH!;
[24603]70set PATH=!GSDL3SRCHOME!\bin;!GSDL3SRCHOME!\bin\script;!GSDL3SRCHOME!\lib\jni;!ANT_HOME!\bin;!PATH!
[15071]71
[20304]72:: Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
[24374]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!
[20304]77
[15363]78:: a little dynamic set cp stuff
[22075]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
[22069]87if exist !TMP!\setcp.bat call !TMP!\setcp.bat
88if exist !TMP!\setcp.bat del !TMP!\setcp.bat
[15363]89
90set GS_CP_SET=yes
[15071]91:skipSetCp
92
[21320]93:: ---- if gs2build is there, run its setup.bat file ----
[31472]94:: http://stackoverflow.com/questions/69068/long-commands-split-over-multiple-lines-in-windows-vista-batch-bat-file
[31473]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%
[21320]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
[24336]110 if EXIST gs3-setup.bat (
111 call gs3-setup.bat
112 ) else (
113 if EXIST setup.bat call setup.bat
114 )
[21320]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
[24374]128setlocal enabledelayedexpansion
129
[15363]130:: ---- Search for java ----
[20300]131set JAVA_MIN_VERSION=1.5.0_00
[31469]132set BUNDLED_JRE=!CD!\packages\jre
133set HINT=!BUNDLED_JRE!
[31447]134
[20300]135::if search4j is present, use it
136set FOUNDJAVAHOME=
137set RUNJAVA=
138if exist bin\search4j.exe (
[22069]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
[20300]141)
[15071]142
[31447]143
144echo.
[31472]145if "%DEBUG%" == "true" echo ********************************************************************
[31447]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
[31460]157:: Also http://stackoverflow.com/questions/4089641/programatically-determine-if-native-exe-is-32-bit-or-64-bit
[31447]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"
[31460]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
[31447]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:
[31472]171:: Note: Using call before the command to allow 2 sets of double quotes, see
[31447]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
[31472]174if not exist "!GSDL3SRCHOME!\lib\jni\gdbmjava.dll" set bitness=UNKNOWN& goto setupjavahome
[32969]175rem The following breaks when GS3 is installed in a path containing spaces
176rem 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
177rem So run with relative filepaths:
178for /f "usebackq tokens=2 delims= " %%G IN (`cd gs2build ^&^& call "bin\windows\GNUfile\bin\file.exe" "..\lib\jni\gdbmjava.dll"`) do set bitness=%%G
[31447]179
180if "%bitness%" == "PE32+" (
181 set bitness=64
[35314]182rem echo The installed Greenstone is 64 bit
[31447]183) else (
184 if "%bitness%" == "PE32" (
185 set bitness=32
[35314]186rem echo The installed Greenstone is 32 bit
[31447]187 ) else (
[35314]188 echo WARNING: Greenstone installation is of unknown bitness. "%bitness%" is neither '32-bit' nor '64-bit'
[31447]189 set bitness=UNKNOWN
190 )
191)
192
[35314]193echo JNI bitness test: %bitness%
194
[31447]195:: 2. What bitness are any JAVA_HOME else JRE_HOME found by search4j?
196:: If you run the non-existent program "pinky" from batch or the DOS console, the exit value is 9009
197:: The same must be true if java is not installed and therefore not found. echo %errorlevel% produces 9009
198:: If java exists and is 32 bit, then running "java -d32 -version" has a return value of 1. echo %errorlevel% (1)
199:: If java exists and is 64 bit, then running "java -d32 -version" has a return value of 0. echo %errorlevel% (0)
200
201:testjavahome
202:: http://www.robvanderwoude.com/errorlevel.php
203:: https://ss64.com/nt/errorlevel.html
[21988]204if DEFINED FOUNDJAVAHOME (
[31469]205 if "%bitness%" == "UNKNOWN" goto setupjavahome
[31472]206 if "%DEBUG%" == "true" echo Testing bitness of JAVA_HOME found at !FOUNDJAVAHOME!:
[31447]207 "!FOUNDJAVAHOME!\bin\java.exe" -d%bitness% -version 2> nul
[31472]208 if !ERRORLEVEL! equ 1 if "%DEBUG%" == "true" echo The detected JDK java is incompatible with !bitness! bit GS& goto testjre
[31447]209 if !ERRORLEVEL! equ 0 (
[31472]210 if "%DEBUG%" == "true" echo The detected JDK java is a matching %bitness% bit
[31461]211 goto setupjavahome
[31472]212 )
[20300]213)
[15071]214
[31447]215:testjre
216if DEFINED FOUNDJREHOME (
[31469]217 if "%bitness%" == "UNKNOWN" goto setupjrehome
[31472]218 if "%DEBUG%" == "true" echo Testing bitness of JRE_HOME found at !FOUNDJREHOME!:
[31447]219 "!FOUNDJREHOME!\bin\java.exe" -d%bitness% -version 2> nul
[31472]220 if !ERRORLEVEL! equ 1 if "%DEBUG%" == "true" echo The detected JRE java is incompatible with !bitness! bit GS& goto testbundledjre
[31471]221 if !ERRORLEVEL! equ 0 (
[31447]222 rem The JRE_HOME found by search4j may be the bundled JRE, overriding any system JRE_HOME,
[31471]223 rem because the bundled JRE_HOME was provided as HINT to search4j.
[31472]224 if "%DEBUG%" == "true" echo The detected JRE java is a matching %bitness% bit
[31461]225 goto setupjrehome
[31472]226 )
[20307]227)
228
[31447]229:: 3. Fall back to 32 bit JRE bundled with GS
[31469]230:testbundledjre
231if exist "!BUNDLED_JRE!\bin\java.exe" (
232 if "%bitness%" == "UNKNOWN" goto bundledjre
[31472]233 if "%DEBUG%" == "true" echo Testing bitness of bundled JRE at !BUNDLED_JRE!:
[31469]234 "!BUNDLED_JRE!\bin\java.exe" -d%bitness% -version 2> nul
[31472]235 if !ERRORLEVEL! equ 1 if "%DEBUG%" == "true" echo The bundled JRE java is incompatible with !bitness! bit& goto setupjavahome
[31471]236 if !ERRORLEVEL! equ 0 (
[31472]237 if "%DEBUG%" == "true" echo The bundled JRE java is a matching %bitness% bit
238 echo *** Changing to use Greenstone's bundled JRE.
[31469]239 goto bundledjre
240 )
241)
242
[31447]243:bundledjre
244:: We bundled a 32 bit JRE, but what if GS was compiled with 64 bit Java?
245:: All but MG/MGPP and GDBM should still work with 64 bit java.
[31469]246if exist "!BUNDLED_JRE!\bin\java.exe" (
247 set JRE_HOME=!BUNDLED_JRE!
248 ::set JAVA_HOME=!BUNDLED_JRE!
[31467]249 set PATH=!JRE_HOME!\bin;!PATH!
250 set RUNJAVA=!JRE_HOME!\bin\java.exe
[20300]251 goto summaryThenEnd
252)
[15071]253
[31461]254:: 4. If no bundled JRE exists either, we'd still need to check if search4j found a JAVA_HOME or JRE_HOME
255:: and use that even if there was a bitness mismatch btw GS3 and the Java found.
256:: Label summaryThenEnd will print out warnings on any mismatch
257:setupjavahome
258if DEFINED FOUNDJAVAHOME (
[31472]259 echo Using the JAVA_HOME detected at !FOUNDJAVAHOME!
[31471]260 set JAVA_HOME=!FOUNDJAVAHOME!
[31461]261 set PATH=!FOUNDJAVAHOME!\bin;!PATH!
262 set RUNJAVA=!FOUNDJAVAHOME!\bin\java.exe
263 goto summaryThenEnd
264)
265
266:setupjrehome
[31472]267if DEFINED FOUNDJREHOME (
268 if "!FOUNDJREHOME!" == "!BUNDLED_JRE!" (
269 echo Using the bundled JRE detected at !FOUNDJREHOME!
270 ) else (
271 echo Using the JRE detected at !FOUNDJREHOME!
272 )
[31461]273 set JRE_HOME=!FOUNDJREHOME!
274 set PATH=!FOUNDJREHOME!\bin;!PATH!
275 set RUNJAVA=!FOUNDJREHOME!\bin\java.exe
276 goto summaryThenEnd
277)
278
[31472]279if exist "!BUNDLED_JRE!\bin\java.exe" (
280 echo Using the bundled JRE detected at !FOUNDJREHOME!
281 goto bundledjre
282)
[31469]283
[31461]284:: 5. Last ditch effort: search4j couldn't find any java, but check any Java env vars set anyway
[31472]285echo Search4j could not find an appropriate JDK or JRE java.
[33932]286echo Checking for Java explicitly set through environment variables
287:echo Attempting to use any JAVA_HOME else JRE_HOME in the environment...
[31472]288
[22069]289if exist "!JAVA_HOME!\bin\java.exe" (
290 set PATH=!JAVA_HOME!\bin;!PATH!
291 set RUNJAVA=!JAVA_HOME!\bin\java.exe
[22082]292 echo Using Java at !JAVA_HOME!
[33932]293: echo WARNING: Greenstone has not checked the version number of this Java installation
294: echo The source distribution of Greenstone3 requires Java 1.5 or greater
295: echo SVN users may still use Java 1.4
296: echo.
[20300]297 goto summaryThenEnd
298)
299
[22069]300if exist "!JRE_HOME!\bin\java.exe" (
301 set PATH=!JRE_HOME!\bin;!PATH!
302 set RUNJAVA=!JRE_HOME!\bin\java.exe
[22082]303 echo Using Java at !JRE_HOME!
[33932]304: echo WARNING: Greenstone has not checked the version number of this JRE installation
305: echo The source distribution of Greenstone3 requires Java 1.5 or greater
306: echo SVN users may still use Java 1.4
307: echo.
[20300]308 goto summaryThenEnd
309)
310
[22082]311echo ERROR: Failed to locate Java
[31447]312echo Please set JAVA_HOME or JRE_HOME to point to an appropriate %bitness% bit Java
[32987]313echo and add JAVA_HOME/bin or JRE_HOME/bin to your PATH.
[20300]314goto end
315
316:summaryThenEnd
[31461]317:: 6. Check that the bitness of any Java found is appropriate and warn if it is not.
[31469]318if "%bitness%" == "UNKNOWN" goto displayvars
[31447]319"!RUNJAVA!" -d%bitness% -version 2> nul
320if !ERRORLEVEL! equ 1 (
[31468]321 echo *** WARNING: Detected mismatch between the bit-ness of your Greenstone installation ^(!bitness! bit^)
322 echo *** and the Java found at !RUNJAVA!.
[31447]323 echo *** Continuing with this Java anyway:
[31472]324 echo *** This will only affect MG/MGPP collections for searching, and GDBM database collections.
325 echo *** Else set JAVA_HOME or JRE_HOME to point to an appropriate %bitness%-bit Java,
326 echo *** or recompile GS with your system Java:
[31447]327 if exist "!JAVA_HOME!" ( echo *** JAVA_HOME at !JAVA_HOME! ) else ( echo *** JRE_HOME at !JRE_HOME! )
328)
[20300]329
[31469]330:displayvars
[31472]331if "%DEBUG%" == "true" echo ********************************************************************
[31447]332echo.
333
[22069]334echo GSDL3SRCHOME : !GSDL3SRCHOME!
335echo GSDL3HOME : !GSDL3HOME!
336echo JAVA : !RUNJAVA!
[22075]337
[22024]338if "!ANT_HOME!" == "" (
[20493]339 echo.
340 echo ANT_HOME is not yet set.
[35662]341 echo Please make sure you have Ant version 1.8.2 or higher installed
[22082]342 echo Then set ANT_HOME to the Ant installation folder
[22075]343 echo and add the path to its bin folder to the PATH environment variable
[20493]344) else (
[22024]345 echo ANT_HOME : !ANT_HOME!
[20493]346)
347echo.
[22015]348
[27832]349:done
[22069]350:: End localisation of variables that started with the set local/set enabledelayedexpansion command
[34098]351:: Restore global variables that would otherwise be lost at script's end due to their having been
352:: initialised in a set local/set enabledelayedexpansion section.
353:: See http://ss64.com/nt/endlocal.html
[34111]354endlocal & set RUNJAVA=%RUNJAVA%& set PATH=%PATH%& set GSDLOS=%GSDLOS%& set GSDLHOME=%GSDLHOME%& set GSDL3HOME=%GSDL3HOME%& set GSDL3SRCHOME=%GSDL3SRCHOME%& ^
355set JAVA_HOME=%JAVA_HOME%& set JRE_HOME=%JRE_HOME%& set ANT_HOME=%ANT_HOME%& set CLASSPATH=%CLASSPATH%
[34098]356
357:: For locales that are significantly different from the English locale, for example for
358:: Chinese locales, UTF-8 XML files parsed by DOM or SAX XML parser in Java code requires
359:: that -Dfile.encoding=UTF-8 be passed to the JVM. We can ensure this happens by setting
360:: the JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 in gs2build\setup.bat and exporting it as below.
361:: In that case, need to also set JAVA_TOOL_OPTIONS in force-start-tomcat and
362:: force-stop-tomcat in build.xml
363:: Finally, in DirectoryPlugin.pm, uncomment Alias.pm and rename *forLocaleIssue files
364:: in cpan\Encode to Alias.pm and the up-to-date Locale.pm.
[34111]365rem endlocal & set RUNJAVA=%RUNJAVA%& set PATH=%PATH%& set GSDLOS=%GSDLOS%& set GSDLHOME=%GSDLHOME%& set GSDL3HOME=%GSDL3HOME%& set GSDL3SRCHOME=%GSDL3SRCHOME%& ^
366rem set JAVA_HOME=%JAVA_HOME%& set JRE_HOME=%JRE_HOME%& set JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS%& set ANT_HOME=%ANT_HOME%& set CLASSPATH=%CLASSPATH%
[33793]367
[31473]368:end
Note: See TracBrowser for help on using the repository browser.