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