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