[15071] | 1 | @echo off
|
---|
| 2 |
|
---|
[22069] | 3 | setlocal enabledelayedexpansion
|
---|
| 4 |
|
---|
[20191] | 5 | set java_min_version=1.5.0_00
|
---|
[15071] | 6 |
|
---|
[27832] | 7 | if exist gs3-setup.bat goto prelim
|
---|
[15071] | 8 | echo This script must be run from within the Greenstone 3 home directory
|
---|
[27832] | 9 | goto done
|
---|
[15071] | 10 |
|
---|
[27832] | 11 | :prelim
|
---|
| 12 | if "!GSDL3SRCHOME!" == "" goto start
|
---|
| 13 | if "!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 |
|
---|
[15071] | 21 | :start
|
---|
[15363] | 22 | :: ---- Set some relevant environment variables ----
|
---|
| 23 |
|
---|
| 24 | :: this is the default
|
---|
[22069] | 25 | :: greenstone3 (!GSDL3SRCHOME!)
|
---|
| 26 | :: +-- web (!GSDL3HOME!)
|
---|
[15363] | 27 | :: +-- packages
|
---|
[22069] | 28 | :: +-- tomcat (!TOMCAT_HOME!)
|
---|
| 29 | :: +-- ant (!ANT_HOME!)
|
---|
[15363] | 30 |
|
---|
[24374] | 31 | :: set GSDL3SRCHOME to the current directory
|
---|
[22069] | 32 | cd | winutil\setvar.exe GSDL3SRCHOME > !TMP!\setgsdl3.bat
|
---|
| 33 | call !TMP!\setgsdl3.bat
|
---|
| 34 | del !TMP!\setgsdl3.bat
|
---|
[15363] | 35 |
|
---|
[24374] | 36 | :: set GSDL3HOME to the 'web' subdirectory
|
---|
[22069] | 37 | set GSDL3HOME=!GSDL3SRCHOME!\web
|
---|
[30574] | 38 | set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
|
---|
[30568] | 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
|
---|
[30592] | 42 | if exist "!GSDL3SRCHOME!\build.properties" for /F "usebackq tokens=1,2 delims==" %%G in ("!GSDL3SRCHOME!\build.properties") do (
|
---|
[30568] | 43 | if "%%G"=="web.home" (
|
---|
| 44 | set GSDL3HOME=%%H
|
---|
| 45 | set GSDL3HOME=!GSDL3HOME:/=\!
|
---|
[30574] | 46 | set WEB_CONTAINING_CLASSES=!GSDL3HOME!
|
---|
[30568] | 47 | if not exist "!GSDL3HOME!" cmd /c "!GSDL3SRCHOME!\userweb.cmd"
|
---|
[30574] | 48 | goto foundwebhome
|
---|
| 49 | )
|
---|
[30568] | 50 | )
|
---|
[15071] | 51 |
|
---|
[30574] | 52 | :foundwebhome
|
---|
[30568] | 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
|
---|
[30574] | 56 | if not exist "!GSDL3HOME!\WEB-INF\classes" set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
|
---|
[30568] | 57 |
|
---|
[15363] | 58 | :: change if using external tomcat or ant
|
---|
[22069] | 59 | set TOMCAT_HOME=!GSDL3SRCHOME!\packages\tomcat
|
---|
| 60 | if exist "!GSDL3SRCHOME!\packages\ant\*.*" set ANT_HOME=!GSDL3SRCHOME!\packages\ant
|
---|
[15071] | 61 |
|
---|
[15363] | 62 | :: other important environment variables
|
---|
[15071] | 63 | set GSDLOS=windows
|
---|
[15363] | 64 |
|
---|
| 65 | :: ---- Set the CLASSPATH and PATH environment variables ----
|
---|
[22069] | 66 | if "!GS_CP_SET!" == "yes" goto skipSetCp
|
---|
[30574] | 67 | set CLASSPATH=!WEB_CONTAINING_CLASSES!\WEB-INF\classes;!GSDL3SRCHOME!\resources\java;!GSDL3SRCHOME!\cp.jar;!CLASSPATH!;
|
---|
[24603] | 68 | set PATH=!GSDL3SRCHOME!\bin;!GSDL3SRCHOME!\bin\script;!GSDL3SRCHOME!\lib\jni;!ANT_HOME!\bin;!PATH!
|
---|
[15071] | 69 |
|
---|
[20304] | 70 | :: Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
|
---|
[24374] | 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!
|
---|
[20304] | 75 |
|
---|
[15363] | 76 | :: a little dynamic set cp stuff
|
---|
[22075] | 77 | if 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)
|
---|
| 82 | 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
|
---|
| 83 | for /f %%j in ('dir/b ^"!TOMCAT_HOME!\lib\*.jar^"') do echo set CLASSPATH=%%CLASSPATH%%;%%TOMCAT_HOME%%\lib\%%j>> !TMP!\setcp.bat
|
---|
| 84 |
|
---|
[22069] | 85 | if exist !TMP!\setcp.bat call !TMP!\setcp.bat
|
---|
| 86 | if exist !TMP!\setcp.bat del !TMP!\setcp.bat
|
---|
[15363] | 87 |
|
---|
| 88 | set GS_CP_SET=yes
|
---|
[15071] | 89 | :skipSetCp
|
---|
| 90 |
|
---|
[21320] | 91 | :: ---- if gs2build is there, run its setup.bat file ----
|
---|
[24374] | 92 | 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%
|
---|
[21320] | 93 |
|
---|
| 94 | if 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 ----
|
---|
| 103 | if exist ext (
|
---|
| 104 | for /D %%e IN ("ext/*") do (
|
---|
| 105 | cd ext\%%e
|
---|
[24336] | 106 | if EXIST gs3-setup.bat (
|
---|
| 107 | call gs3-setup.bat
|
---|
| 108 | ) else (
|
---|
| 109 | if EXIST setup.bat call setup.bat
|
---|
| 110 | )
|
---|
[21320] | 111 | cd ..\..
|
---|
| 112 | )
|
---|
| 113 | )
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | if 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 |
|
---|
[24374] | 124 | setlocal enabledelayedexpansion
|
---|
| 125 |
|
---|
[15363] | 126 | :: ---- Search for java ----
|
---|
[20300] | 127 | set JAVA_MIN_VERSION=1.5.0_00
|
---|
[22069] | 128 | set HINT=!CD!\packages\jre
|
---|
[31447] | 129 |
|
---|
[20300] | 130 | ::if search4j is present, use it
|
---|
| 131 | set FOUNDJAVAHOME=
|
---|
| 132 | set RUNJAVA=
|
---|
| 133 | if exist bin\search4j.exe (
|
---|
[22069] | 134 | for /F "tokens=*" %%r in ('bin\search4j.exe -d -p "!HINT!" -m !JAVA_MIN_VERSION!') do set FOUNDJAVAHOME=%%r
|
---|
| 135 | for /F "tokens=*" %%r in ('bin\search4j.exe -r -p "!HINT!" -m !JAVA_MIN_VERSION!') do set FOUNDJREHOME=%%r
|
---|
[20300] | 136 | )
|
---|
[15071] | 137 |
|
---|
[31447] | 138 |
|
---|
| 139 | echo.
|
---|
| 140 | echo ********************************************************************
|
---|
| 141 |
|
---|
| 142 | rem Check if any Java found matches the bitness of the Greenstone installation's binaries
|
---|
| 143 | rem The sort of output we want:
|
---|
| 144 | :: Installed GS as 32 bit
|
---|
| 145 | :: Detected java is 64 bit
|
---|
| 146 | :: Changing to use the GS bundled 32 bit jre
|
---|
| 147 | :: We've detected a mismatch, this will only affect MG/MGPP collections for searching and GDBM database collections
|
---|
| 148 |
|
---|
| 149 | :: 1. What bit-ness are this Greenstone installation's binaries?
|
---|
| 150 | :: GNUfile: http://stackoverflow.com/questions/2689168/checking-if-file-is-32bit-or-64bit-on-windows
|
---|
| 151 | :: http://gnuwin32.sourceforge.net/packages/file.htm
|
---|
| 152 | :: using Cygwin's file utility:
|
---|
| 153 | :: http://stackoverflow.com/questions/2062020/how-can-i-tell-if-im-running-in-64-bit-jvm-or-32-bit-jvm-from-within-a-program
|
---|
| 154 | :: http://stackoverflow.com/questions/4089641/programatically-determine-if-native-exe-is-32-bit-or-64-bit
|
---|
| 155 | :: http://cygwin.com/cgi-bin2/package-grep.cgi?grep=utility
|
---|
| 156 | :: https://cygwin.com/licensing.html
|
---|
| 157 | :: Messy way: http://superuser.com/questions/358434/how-to-check-if-a-binary-is-32-or-64-bit-on-windows
|
---|
| 158 |
|
---|
| 159 | :: "%GSDLHOME%\bin\windows\GNUfile\bin\file.exe" "%GSDLHOME%\bin\windows\wvWare.exe"
|
---|
| 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
|
---|
| 170 | for /f "usebackq tokens=2 delims= " %%G IN (`call "%GSDLHOME%\bin\windows\GNUfile\bin\file.exe" "%GSDLHOME%\bin\windows\wvWare.exe"`) do set bitness=%%G
|
---|
| 171 |
|
---|
| 172 | if "%bitness%" == "PE32+" (
|
---|
| 173 | set bitness=64
|
---|
| 174 | echo The installed Greenstone is 64 bit
|
---|
| 175 | ) else (
|
---|
| 176 | if "%bitness%" == "PE32" (
|
---|
| 177 | set bitness=32
|
---|
| 178 | echo The installed Greenstone is 32 bit
|
---|
| 179 | ) else (
|
---|
| 180 | echo WARNING: Greenstone installation is of unknown bitness. "%bitness%" is neither 32 nor 64 bit& goto bundledjre
|
---|
| 181 | set bitness=UNKNOWN
|
---|
| 182 | )
|
---|
| 183 | )
|
---|
| 184 |
|
---|
| 185 | :: 2. What bitness are any JAVA_HOME else JRE_HOME found by search4j?
|
---|
| 186 | :: If you run the non-existent program "pinky" from batch or the DOS console, the exit value is 9009
|
---|
| 187 | :: The same must be true if java is not installed and therefore not found. echo %errorlevel% produces 9009
|
---|
| 188 | :: If java exists and is 32 bit, then running "java -d32 -version" has a return value of 1. echo %errorlevel% (1)
|
---|
| 189 | :: If java exists and is 64 bit, then running "java -d32 -version" has a return value of 0. echo %errorlevel% (0)
|
---|
| 190 |
|
---|
| 191 | :testjavahome
|
---|
| 192 | :: http://www.robvanderwoude.com/errorlevel.php
|
---|
| 193 | :: https://ss64.com/nt/errorlevel.html
|
---|
[21988] | 194 | if DEFINED FOUNDJAVAHOME (
|
---|
[31447] | 195 | echo *** Testing bitness of JAVA_HOME found at !FOUNDJAVAHOME!:
|
---|
| 196 | "!FOUNDJAVAHOME!\bin\java.exe" -d%bitness% -version 2> nul
|
---|
| 197 | if !ERRORLEVEL! equ 1 echo *** The detected system JDK java is an incompatible bit architecture& goto testjre
|
---|
| 198 | if !ERRORLEVEL! equ 0 (
|
---|
| 199 | echo *** The detected system JDK java is a matching %bitness% bit
|
---|
| 200 | echo *** Using the system JAVA_HOME detected
|
---|
| 201 | set JAVA_HOME=!FOUNDJAVAHOME!
|
---|
| 202 | set PATH=!FOUNDJAVAHOME!\bin;!PATH!
|
---|
| 203 | set RUNJAVA=!FOUNDJAVAHOME!\bin\java.exe
|
---|
| 204 | goto summaryThenEnd
|
---|
| 205 | )
|
---|
[20300] | 206 | )
|
---|
[15071] | 207 |
|
---|
[31447] | 208 | :testjre
|
---|
| 209 | if DEFINED FOUNDJREHOME (
|
---|
| 210 | echo *** Testing bitness of JRE_HOME found at !FOUNDJREHOME!:
|
---|
| 211 | "!FOUNDJREHOME!\bin\java.exe" -d%bitness% -version 2> nul
|
---|
| 212 | if !ERRORLEVEL! equ 1 echo *** The detected JRE java is an incompatible bit architecture& goto bundledjre
|
---|
| 213 | if !ERRORLEVEL! equ 0 (
|
---|
| 214 | rem The JRE_HOME found by search4j may be the bundled JRE, overriding any system JRE_HOME,
|
---|
| 215 | rem because the bundled JRE_HOME was provided as HINT to search4j.
|
---|
| 216 | echo *** The detected JRE java is a matching %bitness% bit
|
---|
| 217 | echo *** Using the JRE_HOME detected
|
---|
| 218 | set JRE_HOME=!FOUNDJREHOME!
|
---|
| 219 | set PATH=!FOUNDJREHOME!\bin;!PATH!
|
---|
| 220 | set RUNJAVA=!FOUNDJREHOME!\bin\java.exe
|
---|
| 221 | goto summaryThenEnd
|
---|
| 222 | )
|
---|
[20307] | 223 | )
|
---|
| 224 |
|
---|
[31447] | 225 | :: 3. Fall back to 32 bit JRE bundled with GS
|
---|
| 226 | :bundledjre
|
---|
| 227 | :: We bundled a 32 bit JRE, but what if GS was compiled with 64 bit Java?
|
---|
| 228 | :: All but MG/MGPP and GDBM should still work with 64 bit java.
|
---|
[22069] | 229 | if exist "!HINT!\bin\java.exe" (
|
---|
[31447] | 230 | echo *** Changing to use the GS bundled 32-bit jre.
|
---|
[22069] | 231 | set JAVA_HOME=!HINT!
|
---|
| 232 | set PATH=!JAVA_HOME!\bin;!PATH!
|
---|
| 233 | set RUNJAVA=!JAVA_HOME!\bin\java.exe
|
---|
[20300] | 234 | goto summaryThenEnd
|
---|
| 235 | )
|
---|
[15071] | 236 |
|
---|
[31447] | 237 | :: 4. Last ditch effort: search4j couldn't find any java, but check any Java env vars set anyway
|
---|
| 238 | echo *** Search4j could not find an appropriate JAVA or JRE.
|
---|
| 239 | echo *** Attempting to use any JAVA_HOME else JRE_HOME in the environment...
|
---|
| 240 |
|
---|
[22069] | 241 | if exist "!JAVA_HOME!\bin\java.exe" (
|
---|
| 242 | set PATH=!JAVA_HOME!\bin;!PATH!
|
---|
| 243 | set RUNJAVA=!JAVA_HOME!\bin\java.exe
|
---|
[22082] | 244 | echo Using Java at !JAVA_HOME!
|
---|
| 245 | echo WARNING: Greenstone has not checked the version number of this Java installation
|
---|
| 246 | echo The source distribution of Greenstone3 requires Java 1.5 or greater
|
---|
| 247 | echo SVN users may still use Java 1.4
|
---|
[31447] | 248 | echo.
|
---|
[20300] | 249 | goto summaryThenEnd
|
---|
| 250 | )
|
---|
| 251 |
|
---|
[22069] | 252 | if exist "!JRE_HOME!\bin\java.exe" (
|
---|
| 253 | set PATH=!JRE_HOME!\bin;!PATH!
|
---|
| 254 | set RUNJAVA=!JRE_HOME!\bin\java.exe
|
---|
[22082] | 255 | echo Using Java at !JRE_HOME!
|
---|
[31447] | 256 | echo WARNING: Greenstone has not checked the version number of this JRE installation
|
---|
[22081] | 257 | echo The source distribution of Greenstone3 requires Java 1.5 or greater
|
---|
[22082] | 258 | echo SVN users may still use Java 1.4
|
---|
[31447] | 259 | echo.
|
---|
[20300] | 260 | goto summaryThenEnd
|
---|
| 261 | )
|
---|
| 262 |
|
---|
[22082] | 263 | echo ERROR: Failed to locate Java
|
---|
[31447] | 264 | echo Please set JAVA_HOME or JRE_HOME to point to an appropriate %bitness% bit Java
|
---|
[20300] | 265 | goto end
|
---|
| 266 |
|
---|
| 267 | :summaryThenEnd
|
---|
[31447] | 268 | :: Check that the bitness of any Java found is appropriate and warn if it is not.
|
---|
| 269 | "!RUNJAVA!" -d%bitness% -version 2> nul
|
---|
| 270 | if !ERRORLEVEL! equ 1 (
|
---|
| 271 | echo *** WARNING: Detected mismatch between the bit-ness of your Greenstone installation ^(%bitness% bit^) and the Java found.
|
---|
| 272 | echo *** Continuing with this Java anyway:
|
---|
| 273 | echo *** This will only affect MG/MGPP collections for searching, and GDBM database collections
|
---|
| 274 | echo *** Else set JAVA_HOME or JRE_HOME to point to an appropriate %bitness%-bit Java
|
---|
| 275 | echo *** Or recompile GS with your system Java:
|
---|
| 276 | if exist "!JAVA_HOME!" ( echo *** JAVA_HOME at !JAVA_HOME! ) else ( echo *** JRE_HOME at !JRE_HOME! )
|
---|
| 277 | )
|
---|
[20300] | 278 |
|
---|
[31447] | 279 | echo ********************************************************************
|
---|
| 280 | echo.
|
---|
| 281 |
|
---|
[22069] | 282 | echo GSDL3SRCHOME : !GSDL3SRCHOME!
|
---|
| 283 | echo GSDL3HOME : !GSDL3HOME!
|
---|
| 284 | echo JAVA : !RUNJAVA!
|
---|
[22075] | 285 |
|
---|
[22024] | 286 | if "!ANT_HOME!" == "" (
|
---|
[20493] | 287 | echo.
|
---|
| 288 | echo ANT_HOME is not yet set.
|
---|
| 289 | echo Please make sure you have Ant version 1.7.1 or higher installed
|
---|
[22082] | 290 | echo Then set ANT_HOME to the Ant installation folder
|
---|
[22075] | 291 | echo and add the path to its bin folder to the PATH environment variable
|
---|
[20493] | 292 | ) else (
|
---|
[22024] | 293 | echo ANT_HOME : !ANT_HOME!
|
---|
[20493] | 294 | )
|
---|
| 295 | echo.
|
---|
[22015] | 296 |
|
---|
[27832] | 297 | :done
|
---|
[22069] | 298 | :: End localisation of variables that started with the set local/set enabledelayedexpansion command
|
---|
| 299 | :: Restore global variables that would otherwise be lost at script's end due to their having been initialised in a
|
---|
| 300 | :: set local/set enabledelayedexpansion section. See http://ss64.com/nt/endlocal.html
|
---|
[22339] | 301 | 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%
|
---|
[22015] | 302 |
|
---|
[20300] | 303 | :end |
---|