Merge "update rpmbuild with latest versions and add opendove and lispflowmapping...
[integration.git] / packaging / rpm / buildrpm.sh
1 #!/bin/bash
2 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
3
4 # shague todo:
5 # - Add -r option for mock to choose the distribution
6 # - add option to pass in spec file name, maybe use spec.in template
7 # - add option to pass in version and release
8
9 #set -vx
10
11 buildtype="snapshot"
12 buildroot=""
13 buildtag=""
14 cleanroot=0
15 cleantmp=0
16 pushrpms=0
17 getsource="buildroot"
18 version=""
19 release=""
20 repourl=""
21 repouser=""
22 repopw=""
23 dist="fedora-19-x86_64"
24 pkg_dist_suffix="fc19"
25 mock_cmd="/usr/bin/mock"
26 vers_controller=""
27 vers_ovsdb=""
28 suff_controller=""
29 suff_ovsdb=""
30 mockdebug=""
31 mockinit=0
32 tmpbuild=""
33 mockmvn=""
34 timesuffix=""
35 shortcircuits=0
36 shortcircuite=0
37 listprojects=0
38
39 # Maven is not installed at the system wide level but at the Jenkins level
40 # We need to map our Maven call to the Jenkins installed version
41 mvn_cmd="$JENKINS_HOME/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.0.4/bin/mvn"
42
43 # Define our push repositories here. We do it in code since we can't
44 # use a POM file for the RPM pushes (we're doing "one-off" file pushes)
45 #
46 # Repositories will be of the form baseRepositoryId-$dist{-testing}
47 # -testing if it's a snapshot build (not using -snapshot as the name as
48 # -testing is the more common testing repo suffix for yum)
49 baseURL="http://nexus.opendaylight.org/content/repositories/opendaylight-yum-"
50 baseRepositoryId="opendaylight-yum-"
51
52 readonly RCSUCCESS=0
53 readonly RCERROR=64
54 readonly RCPARMSERROR=65
55 readonly RCRPMBUILDERROR=66
56 readonly RCRMOCKERROR=67
57
58 readonly LOGERROR=2
59 readonly LOGINFO=5
60 readonly LOGVERBOSE=7
61 loglevel=$LOGVERBOSE
62
63
64 function log {
65     local level=$1; shift;
66
67     if [ $level -le $loglevel ]; then
68         echo "buildrpm: $@"
69     fi
70 }
71
72 function usage {
73     local rc=$1
74     local outstr=$2
75
76     if [ "$outstr" != "" ]; then
77         echo "$outstr"
78         echo
79     fi
80
81     echo "Usage: `basename $0` [OPTION...]"
82     echo
83     echo "Build options:"
84     echo "  --buildtype TYPE       build type, either snapshot or release"
85     echo "  --buildroot DIRECTORY  build root path"
86     echo "  --buildtag             tag the tmpbuild directory, i.e. Jenkins build number"
87     echo "  --cleanroot            clean buildroot directory before building"
88     echo "  --cleantmp             clean tmpbuild directory before building"
89     echo "  --dist DIST            distribution"
90     echo "  --distsuffix SUFFIX    package distribution suffix"
91     echo "  --getsource METHOD     method for getting source clone|snapshot|buildroot"
92     echo
93     echo "Tag options:"
94     echo "  --release RELEASE      release tag (not used yet)"
95     echo "  --version VERSION      version tag"
96     echo
97     echo "Repo sync options:"
98     echo "  --repourl REPOURL      url of the repo, include http://"
99     echo "  --repouser REPOUSER    user for repo"
100     echo "  --repopw REPOPW        password for repo"
101     echo
102     echo "Deployment options:"
103     echo "  --pushrpms             push the built rpms to a maven repository"
104     echo "  --mvn_cmd              fully qualified path to where the mvn command"
105     echo "                         (defaults to Jenkins installation of Maven 3.0.4)"
106     echo "  --baseURL              base deployment URL. \$dist will be added to the end of this"
107     echo "                         If this is a snapshot build then -testing be added at the end"
108     echo "  --baseRepositoryId     base repository name. \$dist will be added to the end of this"
109     echo "                         If this is a snapshot build then -testing be added at the end"
110     echo
111     echo "Mock options:"
112     echo "  --mockinit             Run mock init"
113     echo "  --mockmvn              replace the maven command used within mock"
114     echo
115     echo "Help options:"
116     echo "  -?, -h, --help  Display this help and exit"
117     echo "  --debug         Enable bash debugging output"
118     echo "  --mockdebug     Enable mock debugging output"
119     echo
120     echo "Extras:"
121     echo "  --shortcircuits INDEX  Start build with project index"
122     echo "  --shortcircuite INDEX  End build with project index"
123     echo "  --listprojects         List the projects and indexes"
124     echo "  --timesuffix TIME      Set the time suffix to use for build output"
125
126     exit $rc
127 }
128
129 readonly PJ_FIRST=0
130 readonly PJ_INTEGRATION=0
131 readonly PJ_CONTROLLER=1
132 readonly PJ_OVSDB=2
133 readonly PJ_OPENFLOWJAVA=3
134 readonly PJ_OPENFLOWPLUGIN=4
135 readonly PJ_DEPENDENCIES=5
136 readonly PJ_DISTRIBUTION=6
137 readonly PJ_OPENDOVE=7
138 readonly PJ_LISPFLOWMAPPING=8
139 readonly PJ_LAST=8
140
141 projects[$PJ_INTEGRATION]="integration"
142 projects[$PJ_CONTROLLER]="controller"
143 projects[$PJ_OVSDB]="ovsdb"
144 projects[$PJ_OPENFLOWJAVA]="openflowjava"
145 projects[$PJ_OPENFLOWPLUGIN]="openflowplugin"
146 projects[$PJ_DEPENDENCIES]="controller-dependencies"
147 projects[$PJ_DISTRIBUTION]="distribution"
148 projects[$PJ_OPENDOVE]="opendove"
149 projects[$PJ_LISPFLOWMAPPING]="lispflowmapping"
150
151 versions[$PJ_INTEGRATION]=""
152 versions[$PJ_CONTROLLER]=""
153 versions[$PJ_OVSDB]=""
154 versions[$PJ_OPENFLOWJAVA]=""
155 versions[$PJ_OPENFLOWPLUGIN]=""
156 versions[$PJ_DEPENDENCIES]=""
157 versions[$PJ_DISTRIBUTION]=""
158 versions[$PJ_OPENDOVE]=""
159 versions[$PJ_LISPFLOWMAPPING]=""
160
161 suffix[$PJ_INTEGRATION]=""
162 suffix[$PJ_CONTROLLER]=""
163 suffix[$PJ_OVSDB]=""
164 suffix[$PJ_OPENFLOWJAVA]=""
165 suffix[$PJ_OPENFLOWPLUGIN]=""
166 suffix[$PJ_DEPENDENCIES]=""
167 suffix[$PJ_DISTRIBUTION]=""
168 suffix[$PJ_OPENDOVE]=""
169 suffix[$PJ_LISPFLOWMAPPING]=""
170
171 gitprojects="$PJ_INTEGRATION $PJ_CONTROLLER $PJ_OVSDB $PJ_OPENFLOWJAVA $PJ_OPENFLOWPLUGIN $PJ_OPENDOVE $PJ_LISPFLOWMAPPING"
172
173 # Clone the projects.
174 function clone_source {
175     for i in $gitprojects; do
176         # We only care about a shallow clone (no need to grab the entire project)
177         log $LOGINFO "Cloning ${projects[$i]} to $buildroot/${projects[$i]}"
178         git clone --depth 0 https://git.opendaylight.org/gerrit/p/${projects[$i]}.git $buildroot/${projects[$i]}
179     done
180 }
181
182 # Copy the projects from snapshots.
183 # shague: Fill in with the nexus info.
184 # Make mk_snapshot_archives that just sets up the version strings.
185 function snapshot_source {
186     log $LOGINFO "$FUNCNAME: Not implemented yet."
187 }
188
189 # Archive the projects to creates the SOURCES for rpmbuild:
190 # - xz the source for later use by rpmbuild.
191 # - get the version and git hashes to produce a versions and suffix for each project.
192 # - copy the archives to the SOURCES dir
193 # shague: need another archive method for snapshot getsource builds since
194 # the source did not come from a git repo.
195 function mk_git_archives {
196     local timesuffix=$1
197
198     for i in $gitprojects; do
199         if [ "$version" == "" ]; then
200             cd $buildroot/${projects[$i]}
201             suffix[$i]="snap.$timesuffix.git.$(git log -1 --pretty=format:%h)"
202         else
203             suffix[$i]="snap.$version"
204         fi
205
206         cd $buildroot/integration/packaging/rpm
207         # integration uses the controller.spec because there isn't an integration.spec to query.
208         if [ ${projects[$i]} == ${projects[$PJ_INTEGRATION]} ]; then
209             versions[$i]="$( rpm -q --queryformat="%{version}\n" --specfile opendaylight-${projects[$PJ_CONTROLLER]}.spec | head -n 1 | awk '{print $1}').${suffix[$i]}"
210         else
211             versions[$i]="$( rpm -q --queryformat="%{version}\n" --specfile opendaylight-${projects[$i]}.spec | head -n 1 | awk '{print $1}').${suffix[$i]}"
212         fi
213
214         log $LOGINFO "Building archive: $tmpbuild/opendaylight-${projects[$i]}-${versions[$i]}.tar.xz"
215         cd $buildroot/${projects[$i]}
216         git archive --prefix=opendaylight-${projects[$i]}-${versions[$i]}/ HEAD | \
217             xz > $tmpbuild/opendaylight-${projects[$i]}-${versions[$i]}.tar.xz
218
219     done
220
221     # Use the controller versions because these projects don't have a repo.
222     for i in `seq $PJ_DEPENDENCIES $PJ_DISTRIBUTION`; do
223         suffix[$i]=${suffix[$PJ_CONTROLLER]}
224         versions[$i]=${versions[$PJ_CONTROLLER]}
225     done
226
227     # Don't forget any patches.
228     cp $buildroot/integration/packaging/rpm/opendaylight-integration-fix-paths.patch $tmpbuild
229 }
230
231 # Pushes rpms to the specified Nexus repository
232 # This only happens if pushrpms is true
233 function push_rpms {
234     if [ $pushrpms = 1 ]; then
235         allrpms=`find $tmpbuild/repo -iname '*.rpm'`
236         echo
237         log $LOGINFO "RPMS found"
238         for i in $allrpms; do
239             log $LOGINFO $i
240         done
241
242         log $LOGINFO ":::::"
243         log $LOGINFO "::::: pushing RPMs"
244         log $LOGINFO ":::::"
245         for i in $allrpms; do
246             rpmname=`rpm -qp --queryformat="%{name}" $i`
247             rpmversion=`rpm -qp --queryformat="%{version}" $i`
248             distro=`echo $dist | tr - .`
249
250             if [ `echo $i | grep 'src.rpm'` ]; then
251                 rpmrelease=`rpm -qp --queryformat="%{release}.src" $i`
252                 groupId="srpm"
253             else
254                 rpmrelease=`rpm -qp --queryformat="%{release}.%{arch}" $i`
255                 groupId="rpm"
256             fi
257
258
259             if [ "$buildtype" == "snapshot" ]; then
260                 repositoryId="${baseRepositoryId}${dist}-testing"
261                 pushURL="${baseURL}${dist}-testing"
262             else
263                 repositoryId="${baseRepositoryId}${dist}"
264                 pushURL="${baseURL}${dist}"
265             fi
266
267             # Note version is the full version+release+{arch|src}
268             # if it is not configured this way on pushes then a download
269             # of the artifact will result in just the name-version.rpm
270             # instead of name-version-release.{arch|src}.rpm
271             $mvn_cmd org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy-file \
272                 -Dfile=$i -DrepositoryId=$repositoryId \
273                 -Durl=$pushURL -DgroupId=$groupId \
274                 -Dversion=$rpmversion-$rpmrelease -DartifactId=$rpmname \
275                 -Dtype=rpm
276         done
277     fi
278 }
279
280 function show_vars {
281      cat << EOF
282 Building controller using:
283 distribution: $dist
284 suffix:       $pkg_dist_suffix
285 buildtype:    $buildtype
286 release:      $release
287 version:      $version
288 getsource:    $getsource
289 buildroot:    $buildroot
290 buildtag:     $buildtag
291 tmpbuild:     $tmpbuild
292 mockmvn:      $mockmvn
293 mockinit:     $mockinit
294 time:         $timesuffix
295 EOF
296 }
297
298 # Build a single project.
299 function build_project {
300     local project="$1"
301     local versionmajor="$2"
302     local versionsnapsuffix="$3"
303
304     log $LOGINFO ":::::"
305     log $LOGINFO "::::: building opendaylight-$project.rpm"
306     log $LOGINFO ":::::"
307
308     cp -f $buildroot/integration/packaging/rpm/opendaylight-$project.spec \
309         $tmpbuild
310
311     cd $tmpbuild
312     # Find lines starting with Version: and replace the rest of the line with the versionsnapsuffix
313     sed -r -i -e '/^Version:/s/\s*$/'".$versionsnapsuffix/" opendaylight-$project.spec
314
315     # Set the write values in the spec files.
316     case "$project" in
317     ${projects[$PJ_CONTROLLER]})
318         # Set the version for the integration source.
319         # Find lines with opendaylight-integration-%{version} and replace %{version} with the version.
320         sed -r -i -e '/opendaylight-integration-\%\{version\}/s/\%\{version\}/'"${versions[$PJ_INTEGRATION]}"'/g' \
321             opendaylight-$project.spec
322         ;;
323
324     ${projects[$PJ_DEPENDENCIES]})
325         # Set the version for ovsdb in the dependencies spec.
326         # Find lines with opendaylight-ovsdb-%{version} and replace %{version} with the version.
327         sed -r -i -e '/opendaylight-ovsdb-\%\{version\}/s/\%\{version\}/'"${versions[$PJ_OVSDB]}"'/g' \
328             opendaylight-$project.spec
329         # Find lines with opendaylight-ovsdb-dependencies-%{version} and replace %{version} with the version.
330         sed -r -i -e '/opendaylight-ovsdb-dependencies-\%\{version\}/s/\%\{version\}/'"${versions[$PJ_OVSDB]}"'/g' \
331             opendaylight-$project.spec
332         ;;
333
334     *)
335         ;;
336     esac
337
338     # Rewrite the mvn command in the rpmbuild if the user requests it.
339     if [ "$mockmvn" != "" ]; then
340         # Find lines starting with export MAVEN_OPTS= and repalce the whole line with $mockmvn
341         sed -r -i -e '/^export MAVEN_OPTS=./c\ '"$mockmvn" opendaylight-$project.spec
342     fi
343
344     # Build the source RPM for use by mock later.
345     #rm -f SRPMS/*.src.rpm
346     log $LOGINFO "::::: building opendaylight-$project.src.rpm in rpmbuild"
347     rpmbuild -bs --define '%_topdir '"`pwd`" --define '%_sourcedir %{_topdir}' \
348        --define "%dist .$pkg_dist_suffix" opendaylight-$project.spec
349
350     rc=$?
351     if [ $rc != 0 ]; then
352         log $LOGERROR "rpmbuild of $project.src.rpm failed (rc=$rc)."
353         exit $RCRPMBUILDERROR
354     fi
355
356     log $LOGINFO "::::: building opendaylight-$project.rpm in mock"
357
358     resultdir="repo/$project.$pkg_dist_suffix.noarch.snap"
359
360     # Build the rpm using mock.
361     # Keep the build because we will need the distribution zip file for later
362     # when building the controller-dependencies.rpm.
363     eval $mock_cmd $mockdebug -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
364         -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
365         SRPMS/opendaylight-$project-$versionmajor-*.src.rpm
366
367     rc=$?
368     if [ $rc != 0 ]; then
369         log $LOGERROR "mock of $project.rpm failed (rc=$rc)."
370         exit $RCRMOCKERROR
371     fi
372
373     # Copy the distribution zip from the controller and ovsdb projects
374     # for use in the dependencies.rpm.
375     case "$project" in
376     controller)
377         log $LOGINFO "::::: Copying $project distribution.zip."
378         eval $mock_cmd $mockdebug -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
379             -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
380             --copyout \"builddir/build/BUILD/opendaylight-$project-$versionmajor/opendaylight/distribution/opendaylight/target/distribution.opendaylight-osgipackage.zip\" \"$resultdir/opendaylight-$project-$versionmajor.zip\"
381         rc1=$?
382         ln -sf $resultdir/opendaylight-$project-$versionmajor.zip $tmpbuild
383         rc2=$?
384         if [ ! -e $tmpbuild/opendaylight-$project-$versionmajor.zip ]; then
385             log $LOGERROR "cannot find $project distribution zip file (rc=$rc1:$rc2)."
386             exit $RCERROR
387         fi
388         ;;
389
390     ovsdb)
391         log $LOGINFO "::::: Copying $project distribution.zip."
392         # Grab the version from the pom.xml file.
393         # Get the lines between the parent tags, then get the line with the version tag and remove leading space and
394         # the tag itself, then remove the trailing tag to be left with the version.
395         pomversion=`sed -n -e '/<parent>/,/<\/parent>/p' "$buildroot"/ovsdb/pom.xml | sed -n -e '/<version>/s/.*<version>//p' | sed -n -e 's/<\/version>//p'`
396         eval $mock_cmd $mockdebug -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
397             -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
398             --copyout \"builddir/build/BUILD/opendaylight-$project-$versionmajor/distribution/opendaylight/target/distribution.$project-$pomversion-osgipackage.zip\" \"$resultdir/opendaylight-$project-$versionmajor.zip\"
399         rc1=$?
400         ln -sf $resultdir/opendaylight-$project-$versionmajor.zip $tmpbuild
401         rc2=$?
402         if [ ! -e $tmpbuild/opendaylight-ovsdb-$versionmajor.zip ]; then
403             log $LOGERROR "cannot find $project distribution zip file (rc=$rc1:$rc2)."
404             exit $RCERROR
405         fi
406         ;;
407
408     *)
409         ;;
410     esac
411 }
412
413 # Main function that builds the rpm's for snapshot's.
414 function build_snapshot {
415     mk_git_archives $timesuffix
416
417     # Initialize our mock build location (we'll be using --no-clean later)
418     # If we don't do the first init we can't build since the environment
419     # doesn't get setup correctly!
420     if [ $mockinit -eq 1 ]; then
421         eval $mock_cmd $mockdebug -r $dist --init
422     fi
423
424     start=$PJ_CONTROLLER
425     end=$PJ_LAST
426
427     if [ $shortcircuits -ne 0 ]; then
428         start=$shortcircuits
429     fi
430
431     if [ $shortcircuite -ne 0 ]; then
432         end=$shortcircuite
433     fi
434
435     echo "start:end = $start:$end"
436
437     for i in `seq $start $end`; do
438         build_project ${projects[$i]} ${versions[$i]} ${suffix[$i]}
439     done
440
441     log $LOGINFO ":::::"
442     log $LOGINFO "::::: All projects have been built"
443     log $LOGINFO ":::::"
444
445     push_rpms
446 }
447
448 # Main function that builds the rpm's for release's.
449 # shague: should be similar to snapshot but use a different version or tag.
450 # spec files should be updated with correct version. If so, do
451 function build_release {
452     log $LOGINFO "$FUNCNAME: Not implemented yet."
453 }
454
455 function parse_options {
456     while true ; do
457         case "$1" in
458         --debug)
459             set -vx; shift;
460             ;;
461
462         --mockdebug)
463             mockdebug="-v"; shift;
464             ;;
465
466         --buildtype)
467             shift; buildtype="$1"; shift;
468             if [ "$buildtype" != "snapshot" ] && [ "$buildtype" != "release" ]; then
469                 usage $RCPARMSERROR "Invalid build type.";
470             fi
471             ;;
472
473         --buildroot)
474             shift; buildroot="$1"; shift;
475             if [ "$buildroot" == "" ]; then
476                 usage $RCPARMSERROR "Missing build root.";
477             fi
478             if [ ! -d "$buildroot" ]; then
479                 usage $RCPARMSERROR "Invalid build root path."
480             fi
481             ;;
482
483         --buildtag)
484             shift; buildtag="$1"; shift;
485             if [ "$buildtag" == ""  ]; then
486                 usage $RCPARMSERROR "Missing build tag.";
487             fi
488             ;;
489
490         --cleanroot)
491             cleanroot=1; shift;
492             ;;
493
494         --cleantmp)
495             cleantmp=1; shift;
496             ;;
497
498         --getsource)
499             shift; getsource="$1"; shift;
500             if [ "$getsource" != "clone" ] && [ "$getsource" != "snapshot" ] && \
501                [ "$getsource" != "buildroot" ]; then
502                 usage $RCPARMSERROR "Invalid getsource method.";
503             fi
504             ;;
505
506         --dist)
507             shift; dist="$1"; shift;
508             if [ "$dist" == "" ]; then
509                 $RCPARMSERROR "Missing distribution.";
510             fi
511             ;;
512
513         --distsuffix)
514             shift; pkg_dist_suffix="$1"; shift;
515             if [ "$pkg_dist_suffix" == "" ]; then
516                 $RCPARMSERROR "Missing package distribution suffix.";
517             fi
518             ;;
519
520         --release)
521             shift; release="$1"; shift;
522             if [ "$release" == "" ]; then
523                 $RCPARMSERROR "Missing release.";
524             fi
525             ;;
526
527         --version)
528             shift; version="$1"; shift;
529             if [ "$version" == "" ]; then
530                 $RCPARMSERROR "Missing version.";
531             fi
532             ;;
533
534         --repourl)
535             shift; repourl="$1"; shift;
536             if [ "$repourl" == "" ]; then
537                 $RCPARMSERROR "Missing repo url.";
538             fi
539             ;;
540
541         --repouser)
542             shift; repouser="$1"; shift;
543             if [ "$repouser" == "" ]; then
544                 $RCPARMSERROR "Missing repo user.";
545             fi
546             ;;
547
548         --repopw)
549             shift; repopw="$1"; shift;
550             if [ "$repopw" == "" ]; then
551                 $RCPARMSERROR "Missing repo pw.";
552             fi
553             ;;
554
555         --pushrpms)
556             pushrpms=1; shift;
557             ;;
558
559         --timesuffix)
560             shift; timesuffix="$1"; shift;
561             if [ "$timesuffix" == ""  ]; then
562                 usage $RCPARMSERROR "Missing time suffix.";
563             fi
564             ;;
565
566         --mvn_cmd)
567             shift; mvn_cmd="$1"; shift;
568             if [ "$mvn_cmd" == "" ]; then
569                 $RCPARMSERROR "Missing mvn_cmd.";
570             fi
571             ;;
572
573         --mockinit)
574             mockinit=1; shift;
575             ;;
576
577         --mockmvn)
578             shift; mockmvn="$1"; shift;
579             if [ "$mockmvn" == "" ]; then
580                 $RCPARMSERROR "Missing mockmvn.";
581             fi
582             ;;
583
584         --baseURL)
585             shift; baseURL="$1"; shift;
586             if [ "$baseURL" == "" ]; then
587                 $RCPARMSERROR "Missing baseURL.";
588             fi
589             ;;
590
591         --baseRepositoryId)
592             shift; baseRepositoryId="$1"; shift;
593             if [ "$baseRepositoryId" == "" ]; then
594                 $RCPARMSERROR "Missing baseRepositoryId.";
595             fi
596             ;;
597
598         --shortcircuits)
599             shift; shortcircuits=$1; shift;
600             ;;
601
602         --shortcircuite)
603             shift; shortcircuite=$1; shift;
604             ;;
605
606         --listprojects)
607             listprojects=1; shift;
608             ;;
609
610         -? | -h | --help)
611             usage $RCSUCCESS
612             ;;
613         "")
614             break
615             ;;
616         *)
617             log $LOGINFO "Ignoring unknown option: $1"; shift;
618         esac
619     done
620 }
621
622
623 #################### main ####################
624
625 if [ "$timesuffix" == "" ]; then
626     timesuffix="$(date +%F_%T | tr -d .:- | tr _ .)"
627 fi
628 date_start=$(date +%s)
629
630 parse_options "$@"
631
632 if [ $listprojects -eq 1 ]; then
633     for i in `seq $PJ_FIRST $PJ_LAST`; do
634         echo "$i ${projects[$i]}"
635     done
636     exit $RCSUCCESS
637 fi
638
639 # Some more error checking...
640 if [ -z $buildroot ]; then
641     log $LOGERROR "Mising buildroot"
642     exit $RCPARMSERROR
643 fi
644
645 if [ $cleanroot -eq 1 ] && [ $getsource = "buildroot" ]; then
646     log $LOGERROR "Aborting. You probably do not want to clean the directory" \
647          "containing the source."
648     exit $RCPARMSERROR
649 fi
650
651 # Can change tmpbuild to be an index or other tag
652 if [ -n "$buildtag" ]; then
653     tmpbuild="$buildroot/bld_$buildtag"
654 else
655     tmpbuild="$buildroot/bld"
656 fi
657
658 show_vars
659
660 if [ $cleanroot -eq 1 ]; then
661     rm -rf $buildroot
662     mkdir -p $buildroot
663 fi
664
665 if [ $cleantmp -eq 1 ]; then
666     rm -rf $tmpbuild
667 fi
668
669 # Setup the temp build directory.
670 mkdir -p $tmpbuild/repo
671
672 # Get the source.
673 case "$getsource" in
674 clone)
675     clone_source;
676     ;;
677
678 snapshot)
679     snapshot_source;
680     exit $RCSUCCESS
681     ;;
682
683 buildroot)
684     cd $buildroot
685     for i in `seq $PJ_INTEGRATION $PJ_OPENFLOWPLUGIN`; do
686         if [ ! -d ${projects[$i]} ]; then
687             log $LOGERROR "Missing ${projects[$i]}"
688             exit $RCPARMSERROR
689         fi
690     done
691     ;;
692 esac
693
694 if [ "$buildtype" = "snapshot" ]; then
695     log $LOGINFO "Building a snapshot build"
696     build_snapshot
697 else
698     log $LOGINFO "Release builds are not supported yet."
699     build_release
700 fi
701
702 date_end=$(date +%s)
703 diff=$(($date_end - $date_start))
704 log $LOGINFO "Build took $(($diff / 3600 % 24)) hours $(($diff / 60 % 60)) minutes and $(($diff % 60)) seconds."
705
706 exit $RCSUCCESS