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