source: main/trunk/greenstone2/setup.bat

Last change on this file was 36794, checked in by anupama, 19 months ago

Dr Bainbridge fixed a diffcol classifier's subsidiary documents ordering issue: for identical titles under an authorr bookshelf for AZCompactList classifier on Creators in Word-PDF-Basic tutorial model collection, a different order of the documents would appear each time. The solution was 2-fold: Besides the PERL_PERTURB_KEYS environment variable, which we set to 0, there is also the PERL_HASH_SEED (see https://www.perlmonks.org/?node_id=1167787 ), and they both need to be set to 0 to get consistent ordering when calling perl's 'keys' command on a hashmap. The other part of the solution is to initialise AZCompactList's sort property to 'nosort' which then uses an array (thus, having a sense of ordering) instead of AZCompactList's default behaviour of using a hashmap (which does not enforce a sense of ordering). Setting the sort property to nosort had the effect of a consistent order of the same identically Titled documents upon a single build, but no consistent ordering between builds which is what PERL_PERTURB_KEYS in conjunction with PERL_HASH_SEED ensure.

File size: 13.9 KB
Line 
1@echo off
2
3setlocal enabledelayedexpansion
4
5pushd "%CD%"
6CD /D "%~dp0"
7set GSDLLANG=en
8
9:: This script's contents were created in Windows codepage 850 (Western European).
10:: When this script is run in non-English locales like the Chinese locale, the
11:: character content/encoding of this script can get wrongly interpreted by the
12:: different encoding of the locale. And then the GS environment gets set wrongly
13:: or incompletely in those cases.
14:: So we force this script to be run and interpreted in codepage 850.
15:: However, the Russian display strings in this script were desgined to work in the
16:: default Russian Windows codepage 866. Whereas, codepage 850 works for this
17:: script's remaining English, French, Spanish display strings. So:
18if ("!GSDLLANG!" == "ru") (
19 chcp 866
20) else (
21 chcp 850
22)
23
24echo.
25echo.
26echo #### #
27echo ## #
28echo # ### ## ## ### ### ### ## ### ##
29echo # # # #### #### # # ## # # # # # ####
30echo ## # # # # # # # # # # # # #
31echo #### # ### ### # # ### ## ## # # ###
32echo (C) 2008, New Zealand Digital Library Project
33echo.
34echo.
35echo.
36
37if "!GSDLHOME!" == "" goto start
38if "!GSDLHOME!" == "!CD!" if not "!GSDLOS!" == "" (
39 echo Your environment is already set up for Greenstone
40 goto done
41)
42
43:start
44if "!OS!" == "Windows_NT" goto WinNT
45if "!OS!" == "" goto Win95
46if "!GSDLLANG!" == "en" echo Setup failed - your PATH has not been set
47if "!GSDLLANG!" == "es" echo No se pudo realizar la configuraci¢n - no se ha establecido la RUTA.
48if "!GSDLLANG!" == "fr" echo Ech‚c de l'installation - votre variable PATH n'a pas ‚t‚ ajust‚e
49if "!GSDLLANG!" == "ru" echo “áâ ­®¢ª  ­¥ 〠« áì - “’œ ­¥ ¡ë« ãáâ ­®¢«¥­
50goto End
51
52:WinNT
53set GSDLHOME=%CD%
54set GSDLOS=windows
55
56REM Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
57if exist "!GSDLHOME!\bin\windows\ghostscript\bin\gsdll32.dll" set GS_DLL=!GSDLHOME!\bin\windows\ghostscript\bin\gsdll32.dll
58if exist "!GSDLHOME!\bin\windows\ghostscript\lib\*.*" set GS_LIB=!GSDLHOME!\bin\windows\ghostscript\lib
59if exist "!GSDLHOME!\bin\windows\ghostscript\bin\*.*" set PATH=!GSDLHOME!\bin\windows\ghostscript\bin;!PATH!
60:: ImageMagick environment vars are now set in bin\script\gs-magick.pl
61::if exist "!GSDLHOME!\bin\windows\imagemagick\*.*" set PATH=!GSDLHOME!\bin\windows\imagemagick;!PATH!
62
63if "!GS_CP_SET!" == "yes" goto Success
64set PATH=!GSDLHOME!\bin\windows;!GSDLHOME!\bin\script;!PATH!
65if exist "!GSDLHOME!\bin\windows\perl\bin" (
66 set PERLPATH=!GSDLHOME!\bin\windows\perl\bin
67 set PATH=!PERLPATH!;!PATH!
68)
69
70set GS_CP_SET=yes
71goto Success
72
73:Win95
74if "%1" == "SetEnv" goto Win95Env
75REM We'll invoke a second copy of the command processor to make
76REM sure there's enough environment space
77COMMAND /E:2048 /K %0 SetEnv
78goto End
79
80:Win95Env
81set GSDLHOME=%CD%
82set GSDLOS=windows
83
84REM Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
85if exist "!GSDLHOME!\bin\windows\ghostscript\bin\gsdll32.dll" set GS_DLL="!GSDLHOME!\bin\windows\ghostscript\bin\gsdll32.dll"
86if exist "!GSDLHOME!\bin\windows\ghostscript\lib\*.*" set GS_LIB="!GSDLHOME!\bin\windows\ghostscript\lib"
87if exist "!GSDLHOME!\bin\windows\ghostscript\bin\*.*" set PATH="!GSDLHOME!\bin\windows\ghostscript\bin";"!PATH!"
88:: ImageMagick environment vars are now set in bin\script\gs-magick.pl
89::if exist "!GSDLHOME!\bin\windows\imagemagick\*.*" set PATH="!GSDLHOME!\bin\windows\imagemagick";"!PATH!"
90
91if "!GS_CP_SET!" == "yes" goto Success
92set PATH=!GSDLHOME!\bin\windows;!GSDLHOME!\bin\script;!PATH!
93if exist "!GSDLHOME!\bin\windows\perl\bin" (
94 set PERLPATH=!GSDLHOME!\bin\windows\perl\bin
95 set PATH=!PERLPATH!;!PATH!
96)
97set GS_CP_SET=yes
98goto Success
99
100
101:Success
102if "!GSDLLANG!" == "en" echo.
103if "!GSDLLANG!" == "en" echo Your environment has successfully been set up to run Greenstone.
104if "!GSDLLANG!" == "en" echo Note that these settings will only have effect within this MS-DOS
105if "!GSDLLANG!" == "en" echo session. You will therefore need to rerun setup.bat if you want
106if "!GSDLLANG!" == "en" echo to run Greenstone programs from a different MS-DOS session.
107if "!GSDLLANG!" == "en" echo.
108
109if "!GSDLLANG!" == "es" echo.
110if "!GSDLLANG!" == "es" echo Su ambiente ha sido configurado para correr los programas Greenstone.
111if "!GSDLLANG!" == "es" echo Recuerde que estos ajustes £nicamente tendr n efecto dentro de esta sesi¢n
112if "!GSDLLANG!" == "es" echo MS-DOS. Por lo tanto deber  ejecutar nuevamente setup.bat si desea
113if "!GSDLLANG!" == "es" echo correr los programas de Greenstone desde una sesi¢n MS-DOS diferente.
114if "!GSDLLANG!" == "es" echo.
115
116if "!GSDLLANG!" == "fr" echo.
117if "!GSDLLANG!" == "fr" echo Votre environnement a ‚t‚ configu‚re avec succŠs pour ex‚cuter Greenstone
118if "!GSDLLANG!" == "fr" echo Notez que ces paramŠtrages n'auront d'effet que dans cette session MS-DOS.
119if "!GSDLLANG!" == "fr" echo Vous devrez par cons‚quent r‚ex‚cuter setup.bat si vous voulez faire
120if "!GSDLLANG!" == "fr" echo lancer des programmes Greenstone dans une autre session MS-DOS.
121if "!GSDLLANG!" == "fr" echo.
122
123if "!GSDLLANG!" == "ru" echo.
124if "!GSDLLANG!" == "ru" echo ‚ è¥ ®ªà㊥­š¥ ¡ë«® ãᯥ譮 ­ áâ஥­®, ç⮡ë ãáâ ­®¢šâì Greenstone Ž¡à âšâ¥
125if "!GSDLLANG!" == "ru" echo ¢­š¬ ­š¥, çâ® íâš ­ §­ ç¥­šï ¡ã€ãâ ⮫쪮 š¬¥âì íä䥪⠢ ¯à¥€¥« å í⮣® MS DOS
126if "!GSDLLANG!" == "ru" echo á¥áášï. ‚ë ¡ã€¥â¥ ¯®í⮬㠀®«Š­ë ¯®¢â®à­® ã¯à ¢«ïâì setup.bat, ¥á«š ‚ë å®âšâ¥
127if "!GSDLLANG!" == "ru" echo ã¯à ¢«ïâì ¯à®£à ¬¬ ¬š ‡¥«ñ­ëå š§¢¥àŠ¥­­ëå ¯®à®€ ®â à §«šç­®© á¥áášš MS DOS.
128if "!GSDLLANG!" == "ru" echo.
129
130:End
131endlocal & set PATH=%PATH%& set GSDLHOME=%GSDLHOME%& set GSDLOS=%GSDLOS%
132
133set savedir=%CD%
134cd "%GSDLHOME%"
135if exist ext (
136 for /D %%e IN ("ext/*") do call :addexts %%e
137)
138cd "%savedir%"
139set savedir=
140goto :doneexts
141
142:addexts
143set folder=%1
144cd "ext\%folder%"
145if EXIST setup.bat call setup.bat
146cd ..\..
147goto :eof
148
149:doneexts
150
151
152if exist "%GSDLHOME%\local\setup.bat" (
153 echo.
154 echo Running %GSDLHOME%\local\setup.bat
155 cd "%GSDLHOME%\local"
156 call setup.bat
157 cd "%GSDLHOME%"
158)
159
160setlocal enabledelayedexpansion
161
162if exist "%GSDLHOME%\local" (
163 set PATH=!GSDLHOME!\local\bin;!PATH!
164)
165
166if exist "%GSDLHOME%\apache-httpd" (
167 echo +Adding in executable path for apache-httpd
168 set PATH=!GSDLHOME!\apache-httpd\!GSDLOS!\bin;!PATH!
169 set PATH=!GSDLHOME!\apache-httpd\!GSDLOS!\lib;!PATH!
170)
171
172:: test writability of GSDLHOME
173@call "!GSDLHOME!\bin\script\checkwritability.bat"
174
175::::::::::::::::::::::::::::::
176if "!GSDL3SRCHOME!" == "" (goto javacheck) else (goto done)
177
178:javacheck
179:: Only for GS2: work out java, and if the bundled jre is found, then set Java env vars with it
180:: Then the same java will be consistently available for all aspects of GS2 (server or GLI, and any subshells these launch)
181echo.
182set MINIMUM_JAVA_VERSION=1.5.0_00
183echo GS2 installation: Checking for Java of version !MINIMUM_JAVA_VERSION! or above
184
185set BUNDLED_JRE=!GSDLHOME!\packages\jre
186if exist "!BUNDLED_JRE!" (
187 set HINT=!BUNDLED_JRE!
188) else (
189 echo No bundled JRE
190 set HINT=
191)
192
193set SEARCH4J_EXECUTABLE=!GSDLHOME!\bin\!GSDLOS!\search4j.exe
194if not exist "!SEARCH4J_EXECUTABLE!" (
195 echo Can't check for java, no Search4j
196 if not exist "!BUNDLED_JRE!" echo Ensure Java environment variables are set ^(either JAVA_HOME or JRE_HOME and on PATH^) & goto done
197 :: else use Bundled JRE
198 echo Will use the bundled JRE and unset any JAVA_HOME to prevent conflicts
199 set JAVA_HOME=
200 set JRE_HOME=!BUNDLED_JRE!
201 set PATH=!BUNDLED_JRE!\bin;!PATH!
202 goto done
203)
204
205:: Need the call stmt, the usebackq with backticks around the full command, AND the double quotes around filepaths to properly handle spaces in the filepaths
206for /f "usebackq tokens=*" %%r in (`call "!GSDLHOME!\bin\!GSDLOS!\search4j.exe" -p "!HINT!" -m !MINIMUM_JAVA_VERSION!`) do set GS_JAVA_HOME=%%r
207
208
209if "!GS_JAVA_HOME!" == "" (
210 if not exist "!BUNDLED_JRE!" echo There's no bundled JRE.
211 echo setup.bat: Could not find Java in the environment or installation.
212 echo Set JAVA_HOME or JRE_HOME, and put it on the PATH, if working with Java tools like Lucene.
213 goto done
214)
215
216:: found java, now GS_JAVA_HOME env vars set, set JAVA_HOME else JRE_HOME
217
218if "!GS_JAVA_HOME!" == "!BUNDLED_JRE!" (
219 :: since our bundled JRE was selected by search4j and we'll be using that, clearing any existing JAVA_HOME to prevent version conflicts
220 echo Found a bundled JRE. Setting up GS2's Java environment to use this ^(and unsetting any JAVA_HOME to prevent version conflicts^)
221 set JAVA_HOME=
222 set JRE_HOME=!BUNDLED_JRE!
223 set PATH=!BUNDLED_JRE!\bin;!PATH!
224 goto done
225)
226
227:: Otherwise, the java that search4j found is not the bundled jre. In that case
228:: if JAVA_HOME or JRE_HOME is already set to the Java found, then PATH presumably would already be set too.
229if "!JAVA_HOME!" == "!GS_JAVA_HOME!" (
230 echo Looks like the Java environment is already set up with a JAVA_HOME
231 ::echo Looks like the Java environment is already set up with a JAVA_HOME, unsetting any JRE_HOME
232 goto done
233)
234if "!JRE_HOME!" == "!GS_JAVA_HOME!" (
235 echo Looks like the Java environment is already set up with a JRE_HOME, unsetting any JAVA_HOME to prevent java version conflicts
236 set JAVA_HOME=
237 goto done
238)
239
240:: if Java env vars not already set, then set them to the GS_JAVA_HOME found
241echo Found a Java on the system. Setting up GS2's Java environment to use this
242::echo Found a Java on the system. Setting up GS2's Java environment to use this: !GS_JAVA_HOME!
243set PATH=!GS_JAVA_HOME!\bin;!PATH!
244:: extract the last 4 chars from folder name. Could be \jre or jre\ or otherwise
245set javafoldername=!GS_JAVA_HOME:~-4!
246:: now can test if the foldername contains jre or otherwise, and based on that set either JAVA_HOME or JRE_HOME
247:: https://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file
248:: https://ss64.com/nt/syntax-substring.html
249if /i "x!javafoldername:jre=!" == "x!javafoldername!" (
250 echo Setting JAVA_HOME, and unsetting any JRE_HOME to prevent version conflicts
251 set JAVA_HOME=!GS_JAVA_HOME!
252 set JRE_HOME=
253) else (
254 echo Setting JRE_HOME, and unsetting any JAVA_HOME to prevent version conflicts
255 set JRE_HOME=!GS_JAVA_HOME!
256 set JAVA_HOME=
257)
258
259::::::::::::::::::::::::::::::
260
261:done
262
263:: COMMENTING OUT THE 2 LINES DETERMINING AND SETTING THE BITNESS (32/64) ON WIN MACHINES
264:: AS IT MAY BE USEFUL IN FUTURE AND IT TOOK ME SOME TIME TO GET THESE LINES WORKING RIGHT
265:: To know bitness (32 vs 64) of a Windows machine, the cmd is "SET Processor"
266:: and look through the lines of output for the line PROCESSOR_ARCHITECTURE=x86
267:: or PROCESSOR_ARCHITECTURE=x64. See techgenix.com/aquicktiptocheckoperatingsystemarchitecture/
268:: The following runs the cmd "set Processor". Then, among the multiline output, it finds the line
269:: containing "PROCESSOR_ARCHITECTURE", splits this line on the delimiter "=" and stores the 2nd token in %%G
270:: Based on the example "_ping_cmd" at https://ss64.com/nt/for_cmd.html
271:: REM for /f "tokens=2 delims==" %%G in ('set Processor ^|find "PROCESSOR_ARCHITECTURE"') do set BITNESS=%%G
272:: Easier way to above: %PROCESSOR_ARCHITECTURE% already contains a value of amd64/x64 or x86. So don't need to run the "set Processor"
273:: command and hunt for PROCESSOR_ARCHITECTURE line. See https://superuser.com/questions/321988/how-do-i-determine-if-my-windows-is-32-bit-or-64-bit-using-a-command
274REM set BITNESS=%PROCESSOR_ARCHITECTURE%
275:: BITNESS will now be "x86" for 32 bit or something like "amd64" or "x64" for 64 bit
276:: From https://ss64.com/nt/syntax-substring.html
277:: "To do a string comparison, remove the SearchString and compare the result with the original
278:: variable before removal. If both strings are the same, then SearchString was not found:"
279REM if /i "%BITNESS:64=%" == "%BITNESS%" (set BITNESS=32) else (set BITNESS=64)
280
281
282popd
283endlocal & set PATH=%PATH%& set GSDLHOME=%GSDLHOME%& set GSDLOS=%GSDLOS%& set JRE_HOME=%JRE_HOME%& set JAVA_HOME=%JAVA_HOME%
284REM & set BITNESS=%BITNESS%
285
286if not "%JAVA_HOME%" == "" echo JAVA_HOME: %JAVA_HOME%
287if not "%JRE_HOME%" == "" echo JRE_HOME: %JRE_HOME%
288:: if GS3, then we'll do some more checking such as bundled JRE if the bitness is right
289if "%GSDL3SRCHOME%" == "" if "%JAVA_HOME%" == "" if "%JRE_HOME%" == "" echo Warning: Neither JAVA_HOME nor JRE_HOME set. Ensure one is set and on PATH.
290if not "%GSDL3SRCHOME%" == "" if "%JAVA_HOME%" == "" if "%JRE_HOME%" == "" echo Neither JAVA_HOME nor JRE_HOME set. Will shortly check for bundled JRE of correct bitness.
291
292:: Perl >= v5.18.* randomises map iteration order within a process
293set PERL_PERTURB_KEYS=0
294set PERL_HASH_SEED=0
295
296:: The user can customise wget flags like number of retries and setting timeouts in the Wgetrc file.
297:: The WGETRC environment variable is used by wget to find a user wgetrc file overriding any system level one
298:: https://www.gnu.org/software/wget/manual/html_node/Wgetrc-Location.html
299set WGETRC=%GSDLHOME%/bin/%GSDLOS%/wgetrc
300
301
302:: On other locales, like Chinese locales, for XMLParsers to read (XML) files
303:: in UTF-8 encoding (instead of defaulting to encoding GBK when on Chinese locale),
304:: need to pass -Dfile.encoding=UTF-8 to the JVM. Can have this passed to the JVM by
305:: setting the JAVA_TOOL_OPTIONS environment variable to this here.
306:: For example, the example at https://www.mkyong.com/java/how-to-read-utf-8-xml-file-in-java-sax-parser/
307:: doesn't work in a Chinese locale until the program is run with
308:: java -Dfile.encoding=UTF-8 <ReadXMLUTF8FileSAX>, so for GS3 this will be passed in to tomcat
309:: in build.xml
310::
311:: https://stackoverflow.com/questions/37071353/how-to-check-if-a-variable-exists-in-a-batch-file
312rem if "x%JAVA_TOOL_OPTIONS%"=="x" (
313rem set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
314rem ) else (
315rem set JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS% -Dfile.encoding=UTF-8
316rem )
Note: See TracBrowser for help on using the repository browser.