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