test defaults for princeton & onelab - oops, should have been committed with http...
[build.git] / vbuild-nightly.sh
1 #!/bin/bash
2 REVISION=$(echo '$Revision$' | sed -e 's,\$,,g' -e 's,^\w*:\s,,' )
3
4 COMMANDPATH=$0
5 COMMAND=$(basename $0)
6
7 # default values, tunable with command-line options
8 DEFAULT_FCDISTRO=centos5
9 DEFAULT_PLDISTRO=planetlab
10 DEFAULT_PERSONALITY=linux32
11 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
12 DEFAULT_build_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
13 DEFAULT_IFNAME=eth0
14
15 # default gpg path used in signing yum repo
16 DEFAULT_GPGPATH="/etc/planetlab"
17 # default email to use in gpg secring
18 DEFAULT_GPGUID="root@$( /bin/hostname )"
19
20 # web publishing results
21 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
22
23 # for the test part
24 x=$(hostname)
25 y=$(hostname|sed -e s,inria,,)
26 # INRIA defaults
27 if [ "$x" != "$y" ] ; then
28     DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
29     DEFAULT_TESTMASTER="testmaster.onelab.eu"
30     DEFAULT_TESTCONFIG="1default"
31 else
32     DEFAULT_TESTBUILDURL="http://build.planet-lab.org/"
33     ### xxx change as appropriate
34     DEFAULT_TESTMASTER="p-testmaster.onelab.eu"
35     DEFAULT_TESTCONFIG="pdefault"
36 fi    
37
38 ####################
39 # assuming vserver runs in UTC
40 DATE=$(date +'%Y.%m.%d')
41
42 # temporary - wrap a quick summary of suspicious stuff
43 # this is to focus on installation that go wrong
44 # use with care, a *lot* of other things can go bad as well
45 function summary () {
46     from=$1; shift
47     echo "******************** BEG SUMMARY" 
48     python - $from <<EOF
49 #!/usr/bin/env python
50 # read a full log and tries to extract the interesting stuff
51
52 import sys,re
53 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:runtest.*")
54 m_installing_any=re.compile('\r  (Installing:[^\]]*]) ')
55 m_installing_err=re.compile('\r  (Installing:[^\]]*])(..+)')
56 m_installing_end=re.compile('Installed:.*')
57 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
58 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
59
60 def summary (filename):
61
62     try:
63         if filename=="-":
64             filename="stdin"
65             f=sys.stdin
66         else:
67             f=open(filename)
68         echo=False
69         for line in f.xreadlines():
70             # first off : discard warnings related to doc
71             if m_installing_doc1.match(line):
72                 (begin,end)=m_installing_doc1.match(line).groups()
73                 line=begin+end
74             if m_installing_doc2.match(line):
75                 (begin,end)=m_installing_doc2.match(line).groups()
76                 line=begin+end
77             # unconditionnally show these lines
78             if m_show_line.match(line):
79                 print '>>>',line,
80             # an 'installing' line with messages afterwards : needs to be echoed
81             elif m_installing_err.match(line):
82                 (installing,error)=m_installing_err.match(line).groups()
83                 print '>>>',installing
84                 print '>>>',error
85                 echo=True
86             # closing an 'installing' section
87             elif m_installing_end.match(line):
88                 echo=False
89             # any 'installing' line
90             elif m_installing_any.match(line):
91                 if echo: 
92                     installing=m_installing_any.match(line).group(1)
93                     print '>>>',installing
94                 echo=False
95             # print lines when echo is true
96             else:
97                 if echo: print '>>>',line,
98         f.close()
99     except:
100         print 'Failed to analyze',filename
101
102 for arg in sys.argv[1:]:
103     summary(arg)
104 EOF
105     echo "******************** END SUMMARY" 
106 }
107
108
109 # Notify recipient of failure or success, manage various stamps 
110 function failure() {
111     set -x
112     # early stage ? - let's not create /build/@PLDISTRO@
113     if [ ! -d ${WEBPATH} ] ; then
114         WEBPATH=/tmp
115         WEBLOG=/tmp/vbuild-early.log.txt
116     fi
117     cp $LOG ${WEBLOG}
118     summary $LOG >> ${WEBLOG}
119     (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
120     if [ -n "$MAILTO" ] ; then
121         ( \
122             echo "See full build log at ${LOG_URL}" ; \
123             echo "and tail version at ${LOG_URL}.ko" ; \
124             echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
125             tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT} ${BASE}" $MAILTO
126     fi
127     exit 1
128 }
129
130 function success () {
131     set -x
132     # early stage ? - let's not create /build/@PLDISTRO@
133     if [ ! -d ${WEBPATH} ] ; then
134         WEBPATH=/tmp
135         WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
136     fi
137     cp $LOG ${WEBLOG}
138     summary $LOG >> ${WEBLOG}
139     if [ -n "$DO_TEST" ] ; then
140         ( \
141             echo "Successfully built and tested" ; \
142             echo "See full build log at ${LOG_URL}" ; \
143             echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
144             ) > ${WEBLOG}.pass
145         rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
146     else
147         ( \
148             echo "Successful package-only build, no test requested" ; \
149             echo "See full build log at ${LOG_URL}" ; \
150             ) > ${WEBLOG}.pkg-ok
151         rm -f ${WEBLOG}.ko
152     fi
153     if [ -n "$MAILTO" ] ; then
154         ( \
155             echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
156             echo "See full build log at ${LOG_URL}" ; \
157             [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
158             | mail -s "Success with ${MAIL_SUBJECT} ${BASE}" $MAILTO
159     fi
160     exit 0
161 }
162
163 # run in the vserver - do not manage success/failure, will be done from the root ctx
164 function build () {
165     set -x
166     set -e
167
168     echo -n "============================== Starting $COMMAND:build on "
169     date
170
171     cd /build
172     show_env
173     
174     echo "Running make IN $(pwd)"
175     
176     # stuff our own variable settings
177     MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
178     MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
179     MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
180     MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
181     MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
182
183     MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
184
185     # stage1
186     make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true 
187     # store tests_svnpath
188     make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
189     # versions
190     make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
191     # actual stuff
192     make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
193
194 }
195
196 # this was formerly run in the myplc-devel chroot but now is run in the root context,
197 # this is so that the .ssh config gets done manually, and once and for all
198 function runtest () {
199     set -x
200     set -e
201     trap failure ERR INT
202
203     echo -n "============================== Starting $COMMAND:runtest on $(date)"
204
205     # where to find TESTS_SVNPATH
206     stamp=/vservers/$BASE/build/tests_svnpath
207     if [ ! -f $stamp ] ; then
208         echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
209         failure
210         exit 1
211     fi
212     TESTS_SVNPATH=$(cat $stamp)
213     # xxx - Thierry - need to rework the test framework in tests/system so it can work
214     # with the entire tests/ module checked out, rather than only tests/system/ 
215     # ugly workaround for now
216     TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
217
218     ### the URL to the RPMS/<arch> location
219     url=""
220     for a in i386 x86_64; do
221         archdir=/vservers/$BASE/build/RPMS/$a
222         if [ -d $archdir ] ; then
223             url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
224             break
225         fi
226     done
227
228     if [ -z "$url" ] ; then
229         echo "$COMMAND: Cannot locate arch URL for testing"
230         failure
231         exit 1
232     fi
233
234     testmaster_ssh="root@${TESTMASTER}"
235
236     # test directory name on test box
237     testdir=${BASE}
238     # clean it
239     ssh -n ${testmaster_ssh} rm -rf ${testdir}
240     # check it out 
241     ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
242     # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
243     ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
244     # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
245     configs=""
246     for config in ${TESTCONFIG} ; do
247         configs="$configs --config $config"
248     done
249     test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
250
251     # need to proceed despite of set -e
252     success=true
253     ssh 2>&1 -n ${testmaster_ssh} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
254
255     # gather logs in the vserver
256     mkdir -p /vservers/$BASE/build/testlogs
257     ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
258     # push them to the build web
259     chmod -R a+r /vservers/$BASE/build/testlogs/
260     rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
261
262     if [ -z "$success" ] ; then
263         failure
264     fi
265     
266     echo -n "============================== End $COMMAND:runtest on $(date)"
267 }
268
269 function in_root_context () {
270     rpm -q util-vserver > /dev/null 
271 }
272
273 # this part won't work with a remote(rsync) WEBPATH
274 function sign_node_packages () {
275
276     echo "Signing node packages"
277     
278     need_createrepo=""
279
280     repository=$WEBPATH/$BASE/RPMS/
281     # the rpms that need signing
282     new_rpms=
283     # and the corresponding stamps
284     new_stamps=
285
286     for package in $(find $repository/ -name '*.rpm') ; do
287         stamp=$repository/signed-stamps/$(basename $package).signed
288         # If package is newer than signature stamp
289         if [ $package -nt $stamp ] ; then
290             new_rpms="$new_rpms $package"
291             new_stamps="$new_stamps $stamp"
292         fi
293         # Or than createrepo database
294         [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
295     done
296
297     if [ -n "$new_rpms" ] ; then
298         # Create a stamp once the package gets signed
299         mkdir $repository/signed-stamps 2> /dev/null
300         
301         # Sign RPMS. setsid detaches rpm from the terminal,
302         # allowing the (hopefully blank) GPG password to be
303         # entered from stdin instead of /dev/tty.
304         echo | setsid rpm \
305             --define "_signature gpg" \
306             --define "_gpg_path $GPGPATH" \
307             --define "_gpg_name $GPGUID" \
308             --resign $new_rpms && touch $new_stamps
309     fi
310
311      # Update repository index / yum metadata. 
312     if [ -n "$need_createrepo" ] ; then
313         echo "Indexing node packages after signing"
314         if [ -f $repository/yumgroups.xml ] ; then
315             createrepo --quiet -g yumgroups.xml $repository
316         else
317             createrepo --quiet $repository
318         fi
319     fi
320 }
321
322 function show_env () {
323     set +x
324     echo FCDISTRO=$FCDISTRO
325     echo PLDISTRO=$PLDISTRO
326     echo PERSONALITY=$PERSONALITY
327     echo BASE=$BASE
328     echo build_SVNPATH=$build_SVNPATH
329     echo MAKEVARS="${MAKEVARS[@]}"
330     echo DRY_RUN="$DRY_RUN"
331     echo PLDISTROTAGS="$PLDISTROTAGS"
332     # this does not help, it's not yet set when we run show_env
333     #echo WEBPATH="$WEBPATH"
334     echo TESTBUILDURL="$TESTBUILDURL"
335     if in_root_context ; then
336         echo PLDISTROTAGS="$PLDISTROTAGS"
337     else
338         if [ -f /build/$PLDISTROTAGS ] ; then
339             echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
340             cat /build/$PLDISTROTAGS
341             echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
342         else
343             echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
344         fi
345     fi
346     set -x
347 }
348
349 function usage () {
350     echo "Usage: $COMMAND [option] [var=value...] make-targets"
351     echo "This is $REVISION"
352     echo "Supported options"
353     echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
354     echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
355     echo " -p personality - defaults to $DEFAULT_PERSONALITY"
356     echo " -m mailto - no default"
357     echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
358     echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
359     echo " -b base - defaults to $DEFAULT_BASE"
360     echo "    @NAME@ replaced as appropriate"
361     echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
362     echo "    the -f/-d/-p/-m/-s/-t options are uneffective in this case"
363     echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
364     echo " -w webpath - defaults to $DEFAULT_WEBPATH"
365     echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
366     echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
367     echo " -y sign yum repo in webpath"
368     echo " -g path to gpg secring used to sign rpms.  Defaults to $DEFAULT_GPGPATH" 
369     echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
370     echo " -B : run build only"
371     echo " -T : run test only"
372     echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
373     echo " -v : be verbose"
374     echo " -7 : uses weekday-@FCDISTRO@ as base"
375     echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
376     exit 1
377 }
378
379 function main () {
380
381     set -e
382
383     # parse arguments
384     MAKEVARS=()
385     MAKETARGETS=()
386     DRY_RUN=
387     DO_BUILD=true
388     DO_TEST=true
389     SIGNYUMREPO=""
390     while getopts "f:d:p:m:s:t:b:o:c:w:W:M:yg:u:BTnv7i:" opt ; do
391         case $opt in
392             f) FCDISTRO=$OPTARG ;;
393             d) PLDISTRO=$OPTARG ;;
394             p) PERSONALITY=$OPTARG ;;
395             m) MAILTO=$OPTARG ;;
396             s) build_SVNPATH=$OPTARG ;;
397             t) PLDISTROTAGS=$OPTARG ;;
398             b) BASE=$OPTARG ;;
399             o) OVERBASE=$OPTARG ;;
400             c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
401             w) WEBPATH=$OPTARG ;;
402             W) TESTBUILDURL=$OPTARG ;;
403             M) TESTMASTER=$OPTARG ;;
404             y) SIGNYUMREPO=true ;;
405             g) GPGPATH=$OPTARG ;;
406             u) GPGUID=$OPTARG ;;
407             B) DO_TEST= ;;
408             T) DO_BUILD= ;;
409             n) DRY_RUN="-n" ;;
410             v) set -x ;;
411             7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
412             i) IFNAME=$OPTARG ;;
413             h|*) usage ;;
414         esac
415     done
416         
417     # preserve options for passing them again later, together with expanded base
418     declare -a options
419     toshift=$(($OPTIND - 1))
420     arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
421
422     # allow var=value stuff; 
423     for target in "$@" ; do
424         # check if contains '='
425         target1=$(echo $target | sed -e s,=,,)
426         if [ "$target" = "$target1" ] ; then
427             MAKETARGETS=(${MAKETARGETS[@]} "$target")
428         else
429             MAKEVARS=(${MAKEVARS[@]} "$target")
430         fi
431     done
432     
433     # set defaults
434     [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
435     [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
436     [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
437     [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
438     [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
439     [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
440     [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
441     [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
442     [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
443     [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
444     [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
445     [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
446     [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
447
448     [ -n "$DRY_RUN" ] && MAILTO=""
449         
450     if [ -n "$OVERBASE" ] ; then
451         sedargs="-e s,@DATE@,${DATE},g"
452         BASE=$(echo ${OVERBASE} | sed $sedargs)
453     else
454         sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
455         BASE=$(echo ${BASE} | sed $sedargs)
456     fi
457
458     ### elaborate mail subject
459     if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
460         MAIL_SUBJECT="complete"
461     elif [ -n "$DO_BUILD" ] ; then
462         MAIL_SUBJECT="package-only"
463     elif [ -n "$DO_TEST" ] ; then
464         MAIL_SUBJECT="test-only"
465     fi
466     if [ -n "$OVERBASE" ] ; then
467         MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
468     else
469         MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
470     fi
471
472     if ! in_root_context ; then
473         # in the vserver
474         echo "==================== Within vserver BEG $(date)"
475         build
476         echo "==================== Within vserver END $(date)"
477
478     else
479         trap failure ERR INT
480         # we run in the root context : 
481         # (*) create or check for the vserver to use
482         # (*) copy this command in the vserver
483         # (*) invoke it
484         
485         if [ -n "$OVERBASE" ] ; then
486             ### Re-use a vserver (finish an unfinished build..)
487             if [ ! -d /vservers/${BASE} ] ; then
488                 echo $COMMAND : cannot find vserver $BASE
489                 exit 1
490             fi
491             # manage LOG - beware it might be a symlink so nuke it first
492             LOG=/vservers/${BASE}.log.txt
493             rm -f $LOG
494             exec > $LOG 2>&1
495             set -x
496             echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
497             # start in case e.g. we just rebooted
498             vserver ${BASE} start || :
499             # update build
500             vserver ${BASE} exec svn update /build
501             # get environment from the first run 
502             FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
503
504             PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
505             PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
506             build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
507             PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
508             MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
509             show_env
510         else
511             # create vserver: check it does not exist yet
512             i=
513             while [ -d /vservers/${BASE}${i} ] ; do
514                 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
515                 [ -z ${i} ] && BASE=${BASE}-n
516                 i=$((${i}+1))
517                 if [ $i -gt 100 ] ; then
518                     echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
519                     exit 1
520                 fi
521             done
522             BASE=${BASE}${i}
523             # need update
524             # manage LOG - beware it might be a symlink so nuke it first
525             LOG=/vservers/${BASE}.log.txt
526             rm -f $LOG
527             exec > $LOG 2>&1 
528             set -x
529             echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
530             show_env
531
532             ### extract the whole build - much simpler
533             tmpdir=/tmp/$COMMAND-$$
534             svn export $build_SVNPATH $tmpdir
535             # Create vserver
536             cd $tmpdir
537             ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE} 
538             # cleanup
539             cd -
540             rm -rf $tmpdir
541             # Extract build again - in the vserver
542             vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
543         fi
544         echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
545
546         # The log inside the vserver contains everything
547         LOG2=/vservers/${BASE}/log.txt
548         (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
549          cat $LOG ; \
550          echo "==================== END VSERVER Transcript of vserver creation" ; \
551          echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
552         ### not too nice : nuke the former log, symlink it to the new one
553         rm $LOG; ln -s $LOG2 $LOG
554         LOG=$LOG2
555         # redirect log again
556         exec >> $LOG 2>&1 
557
558         sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
559         WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
560         mkdir -p ${WEBPATH}
561
562         # where to store the log for web access
563         WEBLOG=${WEBPATH}/${BASE}.log.txt
564         # compute the log URL - inserted in the mail messages for convenience
565         LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
566         TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
567     
568         if [ -n "$DO_BUILD" ] ; then 
569
570             cp $COMMANDPATH /vservers/${BASE}/build/
571
572             # invoke this command in the vserver for building (-T)
573             vserver ${BASE} exec chmod +x /build/$COMMAND
574             vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
575         fi
576
577         # publish to the web so runtest can find them
578         rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
579         rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
580         rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
581         # publish myplc-release
582         rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
583
584         # create yum repo and sign packages.
585         if [ -n "$SIGNYUMREPO" ] ; then
586             sign_node_packages
587         fi
588
589         if [ -n "$DO_TEST" ] ; then 
590             runtest
591         fi
592
593         success 
594         
595     fi
596
597 }  
598
599 ##########
600 main "$@"