1 | @echo off
|
---|
2 | SETLOCAL
|
---|
3 |
|
---|
4 | set serverlang=en
|
---|
5 | set java_min_version=1.4.0_00
|
---|
6 | set PROGNAME="gs2-server"
|
---|
7 | pushd "%CD%"
|
---|
8 | CD /D "%~dp0"
|
---|
9 |
|
---|
10 | echo Greenstone 2 Server
|
---|
11 | echo Copyright (C) 2009, New Zealand Digital Library Project, University Of Waikato
|
---|
12 | echo This software comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
|
---|
13 | echo This is free software, and you are welcome to redistribute it
|
---|
14 |
|
---|
15 | :: -------- Run the Greenstone 2 Server --------
|
---|
16 |
|
---|
17 | :: ---- Determine GSDLHOME ----
|
---|
18 | set gsdl2path=
|
---|
19 |
|
---|
20 | :: Some users may set the above line manually
|
---|
21 | if "%gsdl2path%" == "" (
|
---|
22 | set GSDLHOME=%CD%
|
---|
23 | set gsdl2path=%CD%
|
---|
24 | )
|
---|
25 | echo GS2 Home: %GSDLHOME%
|
---|
26 |
|
---|
27 | :: Setup Greenstone2, unless it has already been done
|
---|
28 | :: If either GSDLHOME or GSDLOS is not set, need to run setup.bat first
|
---|
29 | :: OR operations in an IF stmt: http://fixunix.com/ms-dos/21057-how-implement-if-condition-batch-file.html
|
---|
30 | for %%i in ("%GSDLOS%" "%GSDLHOME%") do if %%i == "" set OR=True
|
---|
31 | if "%OR%" == "True" (
|
---|
32 | pushd "%gsdl2path%"
|
---|
33 | call setup.bat
|
---|
34 | :: echo **** GSDLOS: %GSDLOS% and GSDLHOME: %GSDLHOME%
|
---|
35 | popd
|
---|
36 | )
|
---|
37 |
|
---|
38 |
|
---|
39 | :: First test that there is actually something that can be run...
|
---|
40 | :: Exit if the apache-httpd folder doesn't exist for some reason
|
---|
41 | :: (The errors reported when the apache webserver does not exist
|
---|
42 | :: in the correct location are not at all helpful).
|
---|
43 |
|
---|
44 | :: "You cannot use the if command to test directly for a directory, but
|
---|
45 | :: the null (NUL) device does exist in every directory. As a result, you
|
---|
46 | :: can test for the null device to determine whether a directory exists."
|
---|
47 | ::echo %GSDLHOME%\apache-httpd\nul
|
---|
48 | if not exist %GSDLHOME%\apache-httpd\nul (
|
---|
49 | echo.
|
---|
50 | echo UNABLE TO CONTINUE: There is no apache-httpd directory.
|
---|
51 | echo It does not look like the local apache webserver has been installed.
|
---|
52 | echo Exiting...
|
---|
53 | echo.
|
---|
54 | goto exit
|
---|
55 | )
|
---|
56 | :: exit 1
|
---|
57 |
|
---|
58 |
|
---|
59 | :: If there's no llssite.cfg file, copy from the template
|
---|
60 | if exist "%GSDLHOME%\llssite.cfg" goto cfgfile
|
---|
61 | if exist "%GSDLHOME%\llssite.cfg.in" (
|
---|
62 | copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
|
---|
63 | ) else (
|
---|
64 | echo Warning: could not find llssite.cfg.in to create llssite.cfg from.
|
---|
65 | )
|
---|
66 |
|
---|
67 | :cfgfile
|
---|
68 | :: ---- Determine GSDLHOME ----
|
---|
69 | :: JRE_HOME or JAVA_HOME must be set correctly to run this program
|
---|
70 | bin\windows\search4j -m %java_min_version% > nul
|
---|
71 | echo.
|
---|
72 | :: In Java code, '...getResourceAsStream("build.properties")'
|
---|
73 | :: needs up to be in the right directory when run
|
---|
74 | if %ERRORLEVEL% equ 0 pushd %GSDL2PATH%
|
---|
75 |
|
---|
76 | :: http://ss64.com/nt/call.html (and leave in trailing slash)
|
---|
77 | call :isinpath %GSDLHOME%\lib\java
|
---|
78 |
|
---|
79 | :: After the call, we come back here
|
---|
80 | goto chkjava
|
---|
81 |
|
---|
82 | :isinpath
|
---|
83 | :: http://ss64.com/nt/syntax-replace.html and http://ss64.com/nt/syntax-args.html
|
---|
84 | :: (Does not work: section "Finding items within the PATH environment variable")
|
---|
85 | :: Instead, we expand the filepath of parameter 1 to its full path and
|
---|
86 | :: try to subtract it from the classpath.
|
---|
87 | ::call set test_cpath=%%CLASSPATH:%~f1=%%
|
---|
88 | call set test_cpath=%%CLASSPATH:%1=%%
|
---|
89 |
|
---|
90 | :: If there IS a difference in the classpath before and after,
|
---|
91 | :: then the filepath was already on the classpath
|
---|
92 | if not "%CLASSPATH%" == "%test_cpath%" (
|
---|
93 | echo - CLASSPATH already correct
|
---|
94 | echo %CLASSPATH%
|
---|
95 | goto :eof
|
---|
96 | )
|
---|
97 |
|
---|
98 | :: If there was NO difference in the classpath before and after,
|
---|
99 | :: then the filepath needs to be added to the classpath
|
---|
100 | set CLASSPATH=%GSDLHOME%\lib\java;%CLASSPATH%
|
---|
101 |
|
---|
102 | :: http://ss64.com/nt/for_r.html and (for call) http://ss64.com/nt/for.html
|
---|
103 | :: http://ss64.com/nt/syntax-args.html
|
---|
104 | FOR /R "%GSDLHOME%\lib\java" %%G IN (*.jar) DO call :putinpath %%G
|
---|
105 | echo - Adjusted CLASSPATH
|
---|
106 | echo.
|
---|
107 | ::echo CLASSPATH:& echo %CLASSPATH%
|
---|
108 | goto :eof
|
---|
109 |
|
---|
110 |
|
---|
111 | :putinpath
|
---|
112 | echo jarfile: %1
|
---|
113 | set CLASSPATH=%CLASSPATH%;%1
|
---|
114 | goto :eof
|
---|
115 |
|
---|
116 | :: ---- Check Java ----
|
---|
117 | :chkjava
|
---|
118 | :: call the script with source, so that we have the variables it sets ($javapath)
|
---|
119 | set exit_status=0
|
---|
120 | :: Need to find Java. If found, JAVA_EXECUTABLE will be set
|
---|
121 | :: call findjava.bat %serverlang% %PROGNAME%
|
---|
122 | call "%GSDLHOME%\findjava.bat"
|
---|
123 | if "%JAVA_EXECUTABLE%" == "" echo **** No Java executable found& goto exit
|
---|
124 |
|
---|
125 |
|
---|
126 | :: ---- Run the Greenstone Server Interface ----
|
---|
127 | echo.
|
---|
128 | "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" %*
|
---|
129 | ::echo ******* Second argument to gs2-server.bat is: %2
|
---|
130 | :: The 1st argument to gs2-server.bat (if any) would be --config, the 2nd is the config
|
---|
131 | :: filename if it is glisite.cfg, then this script was launched through GLI and would
|
---|
132 | :: have opened a DOS console. Need to exit from this script then to close the console.
|
---|
133 | if "%2" == "%GSDLHOME%\glisite.cfg" goto quitcmd
|
---|
134 | goto exit
|
---|
135 |
|
---|
136 | :: Exit the batch script (close the console)
|
---|
137 | :quitcmd
|
---|
138 | popd
|
---|
139 | ENDLOCAL
|
---|
140 | exit 0
|
---|
141 |
|
---|
142 | :: Just end the script without closing the console
|
---|
143 | :exit
|
---|
144 | popd
|
---|
145 | ENDLOCAL
|
---|