2 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
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
23 dist="fedora-19-x86_64"
24 pkg_dist_suffix="fc19"
25 mock_cmd='/usr/bin/mock'
32 if [ "$outstr" != "" ]; then
37 echo "Usage: `basename $0` [OPTION...]"
40 echo " --buildtype TYPE build type, either snapshot or release"
41 echo " --buildroot DIRECTORY build root path"
42 echo " --buildnumber NUMBER jenkins build number"
43 echo " --cleanroot clean buildroot directory before building"
44 echo " --dist DIST distribution"
45 echo " --getsource METHOD method for getting source clone|snapshot|buildroot"
48 echo " --release RELEASE release tag (not used yet)"
49 echo " --version VERSION version tag"
51 echo "Repo sync options:"
52 echo " --repourl REPOURL url of the repo, include http://"
53 echo " --repouser REPOUSER user for repo"
54 echo " --repopw REPOPW password for repo"
57 echo " -?, -h, --help Display this help and exit"
58 echo " --debug Enable bash debugging output"
62 # Make a snapshot version tag using the git hash and date
63 # shague: Modify to use ODL build numbering"
64 function mk_versionsnapsuffix {
65 if [ "$version" = "" ]; then
66 cd $buildroot/controller
67 versionsnapsuffix="snap.$(date +%F_%T | tr -d .:- | tr _ .).git.$(git log -1 --pretty=format:%h)"
69 versionsnapsuffix="snap.$version"
74 function clone_source {
75 git clone https://git.opendaylight.org/gerrit/p/controller.git $buildroot/controller
76 git clone https://git.opendaylight.org/gerrit/p/integration.git $buildroot/integration
79 # Copy the projects from snapshots.
80 # shague: Fill in with the nexus info.
81 function snapshot_source {
82 echo "$FUNCNAME: Not implemented yet."
85 # xz the source for later use by rpmbuild.
86 # shague: need another archive method for snapshot getsource builds since
87 # the source did not come from a git repo.
88 function mk_archives {
89 cd $buildroot/integration/packaging/rpm/fedora
90 git archive HEAD opendaylight-controller.sysconfig opendaylight-controller.systemd \
91 | xz > $buildroot/tmpbuild/opendaylight-controller-integration-$versionmajor.tar.xz
93 cd $buildroot/controller
94 git archive --prefix=opendaylight-controller-$versionmajor/ HEAD | \
95 xz > $buildroot/tmpbuild/opendaylight-controller-$versionmajor.tar.xz
98 # shague: Fill in with Nexus info.
100 echo "$FUNCNAME: Not implemented yet."
105 Building controller using:
107 buildtype: $buildtype
110 getsource: $getsource
111 buildroot: $buildroot
115 # Main function that builds the rpm's for snapshot's.
116 function build_snapshot {
117 cp -f $buildroot/integration/packaging/rpm/fedora/opendaylight-controller.spec \
122 cd $buildroot/tmpbuild
124 # append snap suffix to version
125 versionmajor="$( rpm -q --queryformat="%{version}\n" --specfile opendaylight-controller.spec | head -n 1 | awk '{print $1}').$versionsnapsuffix"
127 # test code to short circuit the controller build
129 sed -r -i -e '/^Version:/s/\s*$/'".$versionsnapsuffix/" opendaylight-controller.spec
133 cd $buildroot/tmpbuild
134 #name="$(rpm -q --queryformat="%{name}\n" --specfile *.spec | head -n 1)"
136 # Build the source RPM for use by mock later.
137 #rm -f SRPMS/*.src.rpm
138 rpmbuild -bs --define '%_topdir '"`pwd`" --define '%_sourcedir %{_topdir}' \
139 --define "%dist .$pkg_dist_suffix" opendaylight-controller.spec
142 echo "rpmbuild of controller.src.rpm failed."
147 echo "::::: building opendaylight-controller.rpm in mock"
150 resultdir="repo/controller.$pkg_dist_suffix.noarch.snap"
152 # Build the rpm using mock.
153 # Keep the build because we will need the controller.zip file for later
154 # when building the controller-dependencies.rpm.
155 eval $mock_cmd -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
156 -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
157 SRPMS/opendaylight-controller-$versionmajor-*.src.rpm
160 echo "mock of controller.src.rpm failed."
165 # versionmajor=0.1.0.snap.20131203.165045.git.c406e47
166 # versionsnapsuffix=snap.20131203.165045.git.c406e47
167 # resultdir="repo/controller.$pkg_dist_suffix.noarch.snap"
170 # Now build the dependencies RPM
172 # Copy the controller.zip for use in the dependencies.rpm.
173 eval $mock_cmd -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
174 -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
175 --copyout \"builddir/build/BUILD/opendaylight-controller-$versionmajor/opendaylight/distribution/opendaylight/target/distribution.opendaylight-osgipackage.zip\" \"$resultdir/opendaylight-controller-$versionmajor.zip\"
177 ln -sf $resultdir/opendaylight-controller-$versionmajor.zip \
180 cp -f $buildroot/integration/packaging/rpm/fedora/opendaylight-controller-dependencies.spec \
182 sed -r -i -e '/^Version:/s/\s*$/'".$versionsnapsuffix/" opendaylight-controller-dependencies.spec
183 rpmbuild -bs --define '%_topdir '"`pwd`" --define '%_sourcedir %{_topdir}' \
184 --define "%dist .$pkg_dist_suffix" opendaylight-controller-dependencies.spec
187 echo "rpmbuild of controller-dependencies.src.rpm failed."
192 echo "::::: building opendaylight-controller-dependencies.rpm in mock"
195 resultdir="repo/controller-dependencies.$pkg_dist_suffix.noarch.snap"
197 eval $mock_cmd -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
198 -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
199 SRPMS/opendaylight-controller-dependencies-$versionmajor-*.src.rpm
202 echo "mock of controller-dependencies.src.rpm failed."
209 # Main function that builds the rpm's for release's.
210 # shague: should be similar to snapshot but use a different version or tag.
211 function build_release {
212 echo "$FUNCNAME: Not implemented yet."
215 function parse_options {
223 shift; buildtype="$1"; shift;
224 if [ "$buildtype" != "snapshot" ] && [ "$buildtype" != "release" ]; then
225 usage 1 "Invalid build type.";
230 shift; buildroot="$1"; shift;
231 if [ "$buildroot" == "" ]; then
232 usage 1 "Missing build root.";
234 if [ ! -d "$buildroot" ]; then
235 usage 1 "Invalid build root path."
240 shift; buildnumber="$1"; shift;
241 if [ "$buildnumber" == "" ]; then
242 usage 1 "Missing build number.";
251 shift; getsource="$1"; shift;
252 if [ "$getsource" != "clone" ] && [ "$getsource" != "snapshot" ] && \
253 [ "$getsource" != "buildroot" ]; then
254 usage 1 "Invalid getsource method.";
259 shift; dist="$1"; shift;
260 if [ "$dist" == "" ]; then
261 usage 1 "Missing distribution.";
266 shift; release="$1"; shift;
267 if [ "$release" == "" ]; then
268 usage 1 "Missing release.";
273 shift; version="$1"; shift;
274 if [ "$version" == "" ]; then
275 usage 1 "Missing version.";
280 shift; repourl="$1"; shift;
281 if [ "$repourl" == "" ]; then
282 usage 1 "Missing repo url.";
287 shift; repouser="$1"; shift;
288 if [ "$repouser" == "" ]; then
289 usage 1 "Missing repo user.";
294 shift; repopw="$1"; shift;
295 if [ "$repopw" == "" ]; then
296 usage 1 "Missing repo pw.";
307 echo "Ignoring unknown option: $1"; shift;
313 #################### main ####################
317 # Some more error checking...
318 if [ $cleanroot = 1 ] && [ $getsource = "buildroot" ]; then
319 echo "Aborting. You probably do not want to clean the directory" \
320 "containing the source."
326 if [ $cleanroot = 1 ]; then
331 # Setup the temp build directory.
332 mkdir -p $buildroot/tmpbuild/repo
345 if [ ! -d "controller" ] || [ ! -d "integration" ]; then
346 echo "Problem with controller or integration projects in buildroot."
351 if [ "$buildtype" = "snapshot" ]; then
352 echo "Building a snapshot build"