f12
[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 --lines=1000 $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 --lines=1000 ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT} ${BASE} on $(hostname)" $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} on $(hostname)" $MAILTO
161     fi
162     # XXX For some reason, we haven't been getting this email for successful builds. If this sleep
163     # doesn't fix the problem, I'll remove it -- Sapan.
164     sleep 5
165     exit 0
166 }
167
168 # run in the vserver - do not manage success/failure, will be done from the root ctx
169 function build () {
170     set -x
171     set -e
172
173     echo -n "============================== Starting $COMMAND:build on "
174     date
175
176     cd /build
177     show_env
178     
179     echo "Running make IN $(pwd)"
180     
181     # stuff our own variable settings
182     MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
183     MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
184     MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
185     MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
186     MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
187     MAKEVARS=("WEBPATH=${WEBPATH}" "${MAKEVARS[@]}")
188     MAKEVARS=("TESTBUILDURL=${TESTBUILDURL}" "${MAKEVARS[@]}")
189     MAKEVARS=("WEBROOT=${WEBROOT}" "${MAKEVARS[@]}")
190
191     MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
192
193     # stage1
194     make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true 
195     # store tests_svnpath
196     make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
197     # versions
198     make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
199     # actual stuff
200     make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
201
202 }
203
204 # this was formerly run in the myplc-devel chroot but now is run in the root context,
205 # this is so that the .ssh config gets done manually, and once and for all
206 function run_log () {
207     set -x
208     set -e
209     trap failure ERR INT
210
211     echo -n "============================== Starting $COMMAND:run_log on $(date)"
212
213     # where to find TESTS_SVNPATH
214     stamp=/vservers/$BASE/build/tests_svnpath
215     if [ ! -f $stamp ] ; then
216         echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
217         failure
218         exit 1
219     fi
220     TESTS_SVNPATH=$(cat $stamp)
221     # don't need the tests fulltree anymore
222     TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
223
224     ### the URL to the RPMS/<arch> location
225     # f12 now has everything in i686; try i386 first as older fedoras have both
226     url=""
227     for a in i386 i686 x86_64; do
228         archdir=/vservers/$BASE/build/RPMS/$a
229         if [ -d $archdir ] ; then
230             # where was that installed
231             url=$(echo $archdir | sed -e "s,/vservers/${BASE}/build,${WEBPATH}/${BASE},")
232             url=$(echo $url | sed -e "s,${WEBROOT},${TESTBUILDURL},")
233             break
234         fi
235     done
236
237     if [ -z "$url" ] ; then
238         echo "$COMMAND: Cannot locate arch URL for testing"
239         failure
240         exit 1
241     fi
242
243     testmaster_ssh="root@${TESTMASTER}"
244
245     # test directory name on test box
246     testdir=${BASE}
247     # clean it
248     ssh -n ${testmaster_ssh} rm -rf ${testdir}
249     # check it out 
250     ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
251 ###    # check out the entire tests/ module (with system/ duplicated) as a subdir - see fulltree above
252 ###    ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
253     # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
254     configs=""
255     for config in ${TESTCONFIG} ; do
256         configs="$configs --config $config"
257     done
258     test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
259
260     # need to proceed despite of set -e
261     success=true
262     ssh 2>&1 -n ${testmaster_ssh} ${testdir}/run_log --build ${build_SVNPATH} --url ${url} $configs $test_env $VERBOSE --all || success=
263
264     # gather logs in the vserver
265     mkdir -p /vservers/$BASE/build/testlogs
266     ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
267     # push them to the build web
268     chmod -R a+r /vservers/$BASE/build/testlogs/
269     rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
270
271     if [ -z "$success" ] ; then
272         failure
273     fi
274     
275     echo -n "============================== End $COMMAND:run_log on $(date)"
276 }
277
278 function in_root_context () {
279     rpm -q util-vserver > /dev/null 
280 }
281
282 # this part won't work with a remote(rsync) WEBPATH
283 function sign_node_packages () {
284
285     echo "Signing node packages"
286     
287     need_createrepo=""
288
289     repository=$WEBPATH/$BASE/RPMS/
290     # the rpms that need signing
291     new_rpms=
292     # and the corresponding stamps
293     new_stamps=
294
295     for package in $(find $repository/ -name '*.rpm') ; do
296         stamp=$repository/signed-stamps/$(basename $package).signed
297         # If package is newer than signature stamp
298         if [ $package -nt $stamp ] ; then
299             new_rpms="$new_rpms $package"
300             new_stamps="$new_stamps $stamp"
301         fi
302         # Or than createrepo database
303         [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
304     done
305
306     if [ -n "$new_rpms" ] ; then
307         # Create a stamp once the package gets signed
308         mkdir $repository/signed-stamps 2> /dev/null
309         
310         # Sign RPMS. setsid detaches rpm from the terminal,
311         # allowing the (hopefully blank) GPG password to be
312         # entered from stdin instead of /dev/tty.
313         echo | setsid rpm \
314             --define "_signature gpg" \
315             --define "_gpg_path $GPGPATH" \
316             --define "_gpg_name $GPGUID" \
317             --resign $new_rpms && touch $new_stamps
318     fi
319
320      # Update repository index / yum metadata. 
321     if [ -n "$need_createrepo" ] ; then
322         echo "Indexing node packages after signing"
323         if [ -f $repository/yumgroups.xml ] ; then
324             createrepo --quiet -g yumgroups.xml $repository
325         else
326             createrepo --quiet $repository
327         fi
328     fi
329 }
330
331 function show_env () {
332     set +x
333     echo FCDISTRO=$FCDISTRO
334     echo PLDISTRO=$PLDISTRO
335     echo PERSONALITY=$PERSONALITY
336     echo BASE=$BASE
337     echo build_SVNPATH=$build_SVNPATH
338     echo MAKEVARS="${MAKEVARS[@]}"
339     echo DRY_RUN="$DRY_RUN"
340     echo PLDISTROTAGS="$PLDISTROTAGS"
341     # this does not help, it's not yet set when we run show_env
342     #echo WEBPATH="$WEBPATH"
343     echo TESTBUILDURL="$TESTBUILDURL"
344     if in_root_context ; then
345         echo PLDISTROTAGS="$PLDISTROTAGS"
346     else
347         if [ -f /build/$PLDISTROTAGS ] ; then
348             echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
349             cat /build/$PLDISTROTAGS
350             echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
351         else
352             echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
353         fi
354     fi
355     set -x
356 }
357
358 function setupssh () {
359     base=$1; shift
360     sshkey=$1; shift
361     
362     if [ -f ${sshkey} ] ; then
363         SSHDIR=/vservers/${base}/root/.ssh
364         mkdir -p ${SSHDIR}
365         cp $sshkey ${SSHDIR}/thekey
366         (echo "host *"; \
367             echo "  IdentityFile ~/.ssh/thekey"; \
368             echo "  StrictHostKeyChecking no" ) > ${SSHDIR}/config
369         chmod 700 ${SSHDIR}
370         chmod 400 ${SSHDIR}/*
371     else 
372         echo "WARNING : could not find provided ssh key $sshkey - ignored"
373     fi
374 }
375
376 function usage () {
377     echo "Usage: $COMMAND [option] [var=value...] make-targets"
378     echo "This is $REVISION"
379     echo "Supported options"
380     echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
381     echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
382     echo " -p personality - defaults to $DEFAULT_PERSONALITY"
383     echo " -m mailto - no default"
384     echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
385     echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
386     echo " -b base - defaults to $DEFAULT_BASE"
387     echo "    @NAME@ replaced as appropriate"
388     echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
389     echo "    the -f/-d/-p/-m/-s/-t options are uneffective in this case"
390     echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
391     echo " -w webpath - defaults to $DEFAULT_WEBPATH"
392     echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
393     echo " -r webroot - defaults to $DEFAULT_WEBROOT - the fs point where testbuildurl actually sits"
394     echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
395     echo " -y - sign yum repo in webpath"
396     echo " -g gpg_path - to the gpg secring used to sign rpms.  Defaults to $DEFAULT_GPGPATH" 
397     echo " -u gpg_uid - email used in secring. Defaults to $DEFAULT_GPGUID"
398     echo " -K svnsshkey - specify key to use when svn+ssh:// URLs are used for SVNPATH"
399     echo " -S - do not publish source rpms"
400     echo " -B - run build only"
401     echo " -T - run test only"
402     echo " -n - dry-run: -n passed to make - vserver gets created though - no mail sent"
403     echo " -v - be verbose"
404     echo " -7 - uses weekday-@FCDISTRO@ as base"
405     echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
406     exit 1
407 }
408
409 function main () {
410
411     set -e
412
413     # parse arguments
414     MAKEVARS=()
415     MAKETARGETS=()
416     DRY_RUN=
417     DO_BUILD=true
418     DO_TEST=true
419     PUBLISH_SRPMS=true
420     SSH_KEY=""
421     SIGNYUMREPO=""
422     while getopts "f:d:p:m:s:t:b:o:c:w:W:r:M:yg:u:K:SBTnv7i:" opt ; do
423         case $opt in
424             f) FCDISTRO=$OPTARG ;;
425             d) PLDISTRO=$OPTARG ;;
426             p) PERSONALITY=$OPTARG ;;
427             m) MAILTO=$OPTARG ;;
428             s) build_SVNPATH=$OPTARG ;;
429             t) PLDISTROTAGS=$OPTARG ;;
430             b) BASE=$OPTARG ;;
431             o) OVERBASE=$OPTARG ;;
432             c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
433             w) WEBPATH=$OPTARG ;;
434             W) TESTBUILDURL=$OPTARG ;;
435             r) WEBROOT=$OPTARG ;;
436             M) TESTMASTER=$OPTARG ;;
437             y) SIGNYUMREPO=true ;;
438             g) GPGPATH=$OPTARG ;;
439             u) GPGUID=$OPTARG ;;
440             K) SSH_KEY=$OPTARG ;;
441             S) PUBLISH_SRPMS="" ;;
442             B) DO_TEST= ;;
443             T) DO_BUILD= ;;
444             n) DRY_RUN="-n" ;;
445             v) set -x ; VERBOSE="-v" ;;
446             7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
447             i) IFNAME=$OPTARG ;;
448             h|*) usage ;;
449         esac
450     done
451         
452     # preserve options for passing them again later, together with expanded base
453     declare -a options
454     toshift=$(($OPTIND - 1))
455     arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
456
457     # allow var=value stuff; 
458     for target in "$@" ; do
459         # check if contains '='
460         target1=$(echo $target | sed -e s,=,,)
461         if [ "$target" = "$target1" ] ; then
462             MAKETARGETS=(${MAKETARGETS[@]} "$target")
463         else
464             MAKEVARS=(${MAKEVARS[@]} "$target")
465         fi
466     done
467     
468     # set defaults
469     [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
470     [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
471     [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
472     [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
473     [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
474     [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
475     [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
476     [ -z "$WEBROOT" ] && WEBROOT="$DEFAULT_WEBROOT"
477     [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
478     [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
479     [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
480     [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
481     [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
482     [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
483
484     [ -n "$DRY_RUN" ] && MAILTO=""
485         
486     if [ -n "$OVERBASE" ] ; then
487         sedargs="-e s,@DATE@,${DATE},g"
488         BASE=$(echo ${OVERBASE} | sed $sedargs)
489     else
490         sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
491         BASE=$(echo ${BASE} | sed $sedargs)
492     fi
493
494     ### elaborate mail subject
495     if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
496         MAIL_SUBJECT="complete"
497     elif [ -n "$DO_BUILD" ] ; then
498         MAIL_SUBJECT="package-only"
499     elif [ -n "$DO_TEST" ] ; then
500         MAIL_SUBJECT="test-only"
501     fi
502     if [ -n "$OVERBASE" ] ; then
503         MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
504     else
505         MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
506     fi
507
508     if ! in_root_context ; then
509         # in the vserver
510         echo "==================== Within vserver BEG $(date)"
511         build
512         echo "==================== Within vserver END $(date)"
513
514     else
515         trap failure ERR INT
516         # we run in the root context : 
517         # (*) create or check for the vserver to use
518         # (*) copy this command in the vserver
519         # (*) invoke it
520         
521         if [ -n "$OVERBASE" ] ; then
522             ### Re-use a vserver (finish an unfinished build..)
523             if [ ! -d /vservers/${BASE} ] ; then
524                 echo $COMMAND : cannot find vserver $BASE
525                 exit 1
526             fi
527             # manage LOG - beware it might be a symlink so nuke it first
528             LOG=/vservers/${BASE}.log.txt
529             rm -f $LOG
530             exec > $LOG 2>&1
531             set -x
532             echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
533             # start in case e.g. we just rebooted
534             vserver ${BASE} start || :
535             # update build
536             [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY}
537             vserver ${BASE} exec svn update /build
538             # get environment from the first run 
539             FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
540
541             PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
542             PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
543             build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
544             PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
545             MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
546             WEBPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBPATH)
547             TESTBUILDURL=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +TESTBUILDURL)
548             WEBROOT=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBROOT)
549             show_env
550         else
551             # create vserver: check it does not exist yet
552             i=
553             while [ -d /vservers/${BASE}${i} ] ; do
554                 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
555                 [ -z ${i} ] && BASE=${BASE}-n
556                 i=$((${i}+1))
557                 if [ $i -gt 100 ] ; then
558                     echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
559                     exit 1
560                 fi
561             done
562             BASE=${BASE}${i}
563             # need update
564             # manage LOG - beware it might be a symlink so nuke it first
565             LOG=/vservers/${BASE}.log.txt
566             rm -f $LOG
567             exec > $LOG 2>&1 
568             set -x
569             echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
570             show_env
571
572             ### extract the whole build - much simpler
573             tmpdir=/tmp/$COMMAND-$$
574             svn export $build_SVNPATH $tmpdir
575             # Create vserver
576             cd $tmpdir
577             ./vbuild-init-vserver.sh $VERBOSE -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE} 
578             # cleanup
579             cd -
580             rm -rf $tmpdir
581             # Extract build again - in the vserver
582             [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY}
583             vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
584         fi
585         # install ssh key in vserver
586         echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
587
588         # The log inside the vserver contains everything
589         LOG2=/vservers/${BASE}/log.txt
590         (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
591          cat $LOG ; \
592          echo "==================== END VSERVER Transcript of vserver creation" ; \
593          echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
594         ### not too nice : nuke the former log, symlink it to the new one
595         rm $LOG; ln -s $LOG2 $LOG
596         LOG=$LOG2
597         # redirect log again
598         exec >> $LOG 2>&1 
599
600         sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
601         WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
602         mkdir -p ${WEBPATH}
603
604         # where to store the log for web access
605         WEBLOG=${WEBPATH}/${BASE}.log.txt
606         # compute the log URL - inserted in the mail messages for convenience
607         LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
608         TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
609     
610         if [ -n "$DO_BUILD" ] ; then 
611
612             # invoke this command into the build directory of the vserver
613             cp $COMMANDPATH /vservers/${BASE}/build/
614
615             # invoke this command in the vserver for building (-T)
616             vserver ${BASE} exec chmod +x /build/$COMMAND
617             vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
618         fi
619
620         # publish to the web so run_log can find them
621         rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
622         rsync --archive --delete $VERBOSE /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
623         [[ -n "$PUBLISH_SRPMS" ]] && rsync --archive --delete $VERBOSE /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
624         # publish myplc-release if this exists
625         release=/vservers/$BASE/build/myplc-release
626         [ -f $release ] && rsync $VERBOSE $release $WEBPATH/$BASE
627
628         # create yum repo and sign packages.
629         if [ -n "$SIGNYUMREPO" ] ; then
630             sign_node_packages
631         fi
632
633         if [ -n "$DO_TEST" ] ; then 
634             run_log
635         fi
636
637         success 
638         
639     fi
640
641 }  
642
643 ##########
644 main "$@"