source: other-projects/nightly-tasks/diffcol/trunk/task@ 27557

Last change on this file since 27557 was 27557, checked in by ak19, 11 years ago

Beginnings of changes to make the diffcol task use a standalone Greenstone. At present still only has support for GS2. Mails with reports as attachments are now being sent to the greenstone mailing address without any noticeable code changes there.

File size: 9.0 KB
Line 
1#!/bin/bash
2
3if [ "x$TASK_HOME" == "x" ]; then
4 TASK_HOME=`pwd`;
5fi
6
7export DATA_DIR=$TASK_HOME/diffcol-data
8export UPLOAD_DIR=$TASK_HOME/diffcol-reports
9export [email protected]
10
11# control if an existing compiled greenstone is used
12# or, if one should be checked out, which revision to checkout from svn
13SVN_OPT_R="-r head"
14#export GSDLHOME=
15#export GSDL3SRCHOME=
16
17#check key environment vars are set
18if [ "$UPLOAD_DIR" == "" ]; then
19 echo "Please set a UPLOAD_DIR for the test in an environment.sh file"
20 exit
21fi
22if [ "$DATA_DIR" == "" ]; then
23 echo "Please set a DATA_DIR for the test in an environment.sh file"
24 exit
25fi
26if [ "$MONITOR_EMAIL" == "" ]; then
27 echo "Please set a MONITOR_EMAIL for the test in an environment.sh file"
28 exit
29fi
30
31
32if [ "$DATA_DIR" == "/" ]; then
33 echo "DATA_DIR should not be the fs root"
34 exit
35fi
36
37echo "DATA_DIR: $DATA_DIR"
38echo "UPLOAD_DIR: $UPLOAD_DIR"
39
40#create an id for this test
41dateid=`date +'%Y-%m-%d'`
42
43echo "Starting test '$dateid'"
44
45#set classpath
46CLASSPATH=
47for file in $TASK_HOME/lib/*.jar; do
48 CLASSPATH=$file:$CLASSPATH
49done
50export CLASSPATH
51
52#set the location of the full report
53xmlout=$DATA_DIR'/full-report-'$dateid'.xml'
54
55# the toplevel folder of the greenstone installation being used
56greenstone_home=
57# gsdl is the checkout folder and can be greenstone2 or greenstone3
58gsdl=greenstone2
59
60
61# Check if using existing compiled-up greenstone installation
62# and set the greenstone_home location accordingly
63if [ "x$GSDL3SRCHOME" != "x" -o "x$GSDLHOME" != "x" ]; then
64 echo "Found existing Greenstone home, will use that instead"
65 greenstone_home=$GSDLHOME
66else
67 greenstone_home="$DATA_DIR/$gsdl";
68fi
69
70
71
72function setup_greenstone() {
73
74 #clean up from previous tests
75 echo -n "about to clean up any old tests (Ctrl-C to cancel)"
76 for i in x x x x x; do sleep 1; echo -n .; done
77 echo
78
79 echo "cleaning up previous tests"
80 rm -rf $DATA_DIR
81
82 echo "creating the data dir"
83 mkdir -p $DATA_DIR || exit
84
85 cd $DATA_DIR
86
87
88 # use existing compiled-up greenstone installation
89 if [ "x$GSDL3SRCHOME" != "x" -o "x$GSDLHOME" != "x" ]; then
90 echo "Found existing Greenstone home, will use that instead"
91 return;
92 fi
93
94 # Else checkout a GS from svn into DATA_DIR
95
96
97 #svn checkout of main gsdl directory
98 echo "checkout $gsdl:"
99 svn co $SVN_OPT_REV http://svn.greenstone.org/main/trunk/greenstone2 $gsdl
100 echo "done"
101
102 cd $DATA_DIR/$gsdl
103
104
105 # since this is a bash script, we're on linux/darwin, need gnome-lib
106 # for the correct architecture. Assume all darwin is intel, not ppc
107 echo "setting up gnome-lib-minimal for compilation"
108
109# http://stackoverflow.com/questions/394230/detect-the-os-from-a-bash-script
110 os='linux';
111 gl_suffix=$os;
112 if [[ "$OSTYPE" == "darwin"* ]]; then
113 os='darwin';
114 gl_suffix=$os'-intel';
115 else
116 # linux, work out the bit architecture
117 arch=`uname -m`
118 if [[ "$arch" == *"64"* ]]; then
119 arch='64';
120 gl_suffix=$gl_suffix'-x64';
121 else
122 arch='32';
123 fi
124 fi
125
126
127 #svn checkout gnome-lib for this linux/darwin
128 cd $DATA_DIR/$gsdl/ext
129
130# svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-linux-x64.tar.gz gl.tar.gz
131 svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-$gl_suffix.tar.gz gl.tar.gz
132 tar xvzf gl.tar.gz
133 cd gnome-lib-minimal
134 source devel.bash
135
136 cd ../..
137
138
139 #configure
140 echo "configure $gsdl: "
141 echo "<configure>" >> $xmlout
142 ./configure 2>> $DATA_DIR/compilation-errors
143 echo "</configure>" >> $xmlout
144 echo "done"
145
146 #make
147 echo "make $gsdl: "
148 echo "<make>" >> $xmlout
149 make 2>> $DATA_DIR/compilation-errors
150 echo "</make>" >> $xmlout
151 echo "done"
152
153 #make install
154 echo "make install $gsdl: "
155 echo "<make-install>" >> $xmlout
156 make install $DATA_DIR/compilation-errors
157 echo "</make-install>" >> $xmlout
158 echo "done"
159
160 # set the path to the greenstone_home variable
161 greenstone_home=$DATA_DIR/$gsdl
162}
163
164
165function run_test() {
166
167 #perform the requested subcommands, outputting xml information
168 echo '<test time="'$dateid'" id="'$dateid'">' > $xmlout
169
170 # go to whichever greenstone_home we're using
171 cd $greenstone_home
172
173 #get svn info
174 echo "getting svn info: "
175 echo "<svn-info>" >> $xmlout
176 svn info >> $xmlout
177 echo "</svn-info>" >> $xmlout
178 echo "done"
179
180 #set up the gsdl environment with the setup.bash script
181 echo "setting up $gsdl environment: "
182 export GSDLHOME=
183 source setup.bash
184 echo "done"
185
186 #make two copies of the model-collect directory in gsdl
187 #one to be rebuild and one as the basis for comparison
188 #strip both of all .svn directories
189
190 #copy the model collections to the collect folder to be rebuilt
191 echo -n "installing test collections and model collections to new $gsdl installation... "
192
193 #clean up
194 rm -rf collect
195 rm -rf model-collect
196
197 #copy to collect and strip
198 cp -r $TASK_HOME/model-collect collect
199 find collect -type d -name .svn -exec rm -rf {} \;
200
201 #make the model copy
202 cp -r collect model-collect
203
204 echo "done"
205
206 #for each collection, import, build and diff with its model counterpart
207 for collection in collect/*; do
208
209 #escape the filename (in case of space)
210 collection=`echo $collection | sed 's@ @\\\ @g'`
211
212 #get just the basename
213 collection=`basename $collection`
214
215 echo '<collection-test name="'$collection'">' >> $xmlout
216
217 #import
218 #Ensure the OIDtype for importing is hash_on_full_filename
219 # "to make document identifiers more stable across
220 # upgrades of the software, although it means that
221 # duplicate documents contained in the collection are no
222 # longer detected automatically."
223 echo $collection' - Importing:'
224 echo "<import>" >> $xmlout
225 import.pl -OIDtype hash_on_full_filename $collection -removeold
226 echo "</import>" >> $xmlout
227 echo "done"
228
229 #build
230 echo $collection' - Building:'
231 echo "<build>" >> $xmlout
232 buildcol.pl $collection -removeold
233 echo "</build>" >> $xmlout
234 echo "done"
235
236 #rename the intermediate 'building' directory 'index'
237 echo -n $collection' - Move "building" to "index"... "'
238 rm -rf collect/$collection/index
239 mv collect/$collection/building collect/$collection/index
240 echo "done"
241
242 #diffcol
243 echo $collection' - Diffing:'
244 cd $TASK_HOME/diffcol
245 ./diffcol.pl -output xml -verbosity 10 $collection >> $xmlout
246 cd $greenstone_home
247 echo "done"
248
249 echo "</collection-test>" >> $xmlout
250 done
251
252 echo "</test>" >> $xmlout
253
254 echo "done"
255
256}
257
258function upload() {
259 # ensure the upload directory exists
260 # before trying to transfer the xml and html files across
261 # if it already existed, clear it of contents
262 if [ ! -d "$UPLOAD_DIR" ]; then
263 mkdir -p "$UPLOAD_DIR";
264# else
265# rm $UPLOAD_DIR/*
266 fi
267
268 scp $DATA_DIR/*.xml $DATA_DIR/*.html $UPLOAD_DIR
269}
270
271function mail_simple_message() {
272 # email out brief failure message if failed
273 echo "Checking if failed... "
274 result=`java org.apache.xalan.xslt.Process -IN "$xmlout" -XSL "$TASK_HOME/xsl/passed-or-not.xsl"`
275 echo "result: "$result
276 if [ "$result" != "yes" ]; then
277 echo 'gsdl regression test for '$dateid' failed' | mail -s 'Regression Test Failed' $MONITOR_EMAIL #$WEBMASTER_EMAIL
278 fi
279}
280
281
282function mail_with_report_attached() {
283 # http://stackoverflow.com/questions/17359/how-do-i-send-a-file-as-an-email-attachment-using-linux-command-line
284
285 #echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- [email protected]
286
287
288 # email out with report attached, if the tests failed
289 echo "Checking if failed... "
290 result=`java org.apache.xalan.xslt.Process -IN "$xmlout" -XSL "$TASK_HOME/xsl/passed-or-not.xsl"`
291 echo "result: "$result
292 if [ "$result" != "yes" ]; then
293 echo $gsdl' regression test for '$dateid' failed' | mutt -a $DATA_DIR'/report-'$dateid'.html' -s 'Regression Test Failed' -- $MONITOR_EMAIL
294 fi
295 echo "Sent mail with report attached."
296}
297
298function summarise() {
299
300 # make a summarised Xml report
301 echo -n "Summarizing the xml report... "
302 java org.apache.xalan.xslt.Process -IN $xmlout -XSL $TASK_HOME/xsl/xml-report.xsl -OUT $DATA_DIR/report-$dateid.xml
303 echo "done"
304
305 # make a summarised HTml report
306 echo -n "Creating an html summary report... "
307 java org.apache.xalan.xslt.Process -IN $DATA_DIR/report-$dateid.xml -XSL $TASK_HOME/xsl/html-report.xsl -OUT $DATA_DIR/report-$dateid.html
308 echo "done"
309
310}
311
312
313#parse arguments
314if [ "$1" == "" ]; then
315 action=all
316else
317 if [ "$1" == "setup_greenstone" ]; then
318 action=setup_greenstone
319 elif [ "$1" == "run_test" ]; then
320 action=run_test
321 elif [ "$1" == "summarise" ]; then
322 action=summarise
323 elif [ "$1" == "upload" ]; then
324 action=upload
325 elif [ "$1" == "all" ]; then
326 action=all
327 else
328 echo "bad subcommand"
329 exit
330 fi
331fi
332
333#do the requested action
334if [ "$action" == "setup_greenstone" ]; then
335 setup_greenstone
336elif [ "$action" == "run_test" ]; then
337 run_test
338# mail_simple_message
339elif [ "$action" == "summarise" ]; then
340 summarise
341elif [ "$action" == "upload" ]; then
342 upload
343 mail_simple_message
344 mail_with_report_attached
345elif [ "$action" == "all" ]; then
346 setup_greenstone
347 run_test
348 summarise
349 upload
350 mail_with_report_attached
351fi
352
Note: See TracBrowser for help on using the repository browser.