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 # We only care about a shallow clone (no need to grab the entire project)
76 git clone --depth 0 https://git.opendaylight.org/gerrit/p/controller.git $buildroot/controller
77 git clone --depth 0 https://git.opendaylight.org/gerrit/p/integration.git $buildroot/integration
80 # Copy the projects from snapshots.
81 # shague: Fill in with the nexus info.
82 function snapshot_source {
83 echo "$FUNCNAME: Not implemented yet."
86 # xz the source for later use by rpmbuild.
87 # shague: need another archive method for snapshot getsource builds since
88 # the source did not come from a git repo.
89 function mk_archives {
90 cd $buildroot/integration/packaging/rpm/fedora
91 git archive HEAD opendaylight-controller.sysconfig opendaylight-controller.systemd \
92 | xz > $buildroot/tmpbuild/opendaylight-controller-integration-$versionmajor.tar.xz
94 cd $buildroot/controller
95 git archive --prefix=opendaylight-controller-$versionmajor/ HEAD | \
96 xz > $buildroot/tmpbuild/opendaylight-controller-$versionmajor.tar.xz
99 # shague: Fill in with Nexus info.
101 echo "$FUNCNAME: Not implemented yet."
106 Building controller using:
108 buildtype: $buildtype
111 getsource: $getsource
112 buildroot: $buildroot
116 # Main function that builds the rpm's for snapshot's.
117 function build_snapshot {
118 cp -f $buildroot/integration/packaging/rpm/fedora/opendaylight-controller.spec \
123 cd $buildroot/tmpbuild
125 # append snap suffix to version
126 versionmajor="$( rpm -q --queryformat="%{version}\n" --specfile opendaylight-controller.spec | head -n 1 | awk '{print $1}').$versionsnapsuffix"
128 # test code to short circuit the controller build
130 sed -r -i -e '/^Version:/s/\s*$/'".$versionsnapsuffix/" opendaylight-controller.spec
134 cd $buildroot/tmpbuild
135 #name="$(rpm -q --queryformat="%{name}\n" --specfile *.spec | head -n 1)"
137 # Build the source RPM for use by mock later.
138 #rm -f SRPMS/*.src.rpm
139 rpmbuild -bs --define '%_topdir '"`pwd`" --define '%_sourcedir %{_topdir}' \
140 --define "%dist .$pkg_dist_suffix" opendaylight-controller.spec
143 echo "rpmbuild of controller.src.rpm failed."
148 echo "::::: building opendaylight-controller.rpm in mock"
151 resultdir="repo/controller.$pkg_dist_suffix.noarch.snap"
153 # Initialize our mock build location (we'll be using --no-clean later)
154 # If we don't do the first init we can't build since the environment
155 # doesn't get setup correctly!
156 eval $mock_cmd -r $dist --init
158 # Build the rpm using mock.
159 # Keep the build because we will need the controller.zip file for later
160 # when building the controller-dependencies.rpm.
161 eval $mock_cmd -v -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
162 -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
163 SRPMS/opendaylight-controller-$versionmajor-*.src.rpm
166 echo "mock of controller.src.rpm failed."
171 # versionmajor=0.1.0.snap.20131203.165045.git.c406e47
172 # versionsnapsuffix=snap.20131203.165045.git.c406e47
173 # resultdir="repo/controller.$pkg_dist_suffix.noarch.snap"
176 # Now build the dependencies RPM
178 # Copy the controller.zip for use in the dependencies.rpm.
179 eval $mock_cmd -v -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
180 -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
181 --copyout \"builddir/build/BUILD/opendaylight-controller-$versionmajor/opendaylight/distribution/opendaylight/target/distribution.opendaylight-osgipackage.zip\" \"$resultdir/opendaylight-controller-$versionmajor.zip\"
183 ln -sf $resultdir/opendaylight-controller-$versionmajor.zip \
186 cp -f $buildroot/integration/packaging/rpm/fedora/opendaylight-controller-dependencies.spec \
188 sed -r -i -e '/^Version:/s/\s*$/'".$versionsnapsuffix/" opendaylight-controller-dependencies.spec
189 rpmbuild -bs --define '%_topdir '"`pwd`" --define '%_sourcedir %{_topdir}' \
190 --define "%dist .$pkg_dist_suffix" opendaylight-controller-dependencies.spec
193 echo "rpmbuild of controller-dependencies.src.rpm failed."
198 echo "::::: building opendaylight-controller-dependencies.rpm in mock"
201 resultdir="repo/controller-dependencies.$pkg_dist_suffix.noarch.snap"
203 eval $mock_cmd -v -r $dist --no-clean --no-cleanup-after --resultdir \"$resultdir\" \
204 -D \"dist .$pkg_dist_suffix\" -D \"noclean 1\" \
205 SRPMS/opendaylight-controller-dependencies-$versionmajor-*.src.rpm
208 echo "mock of controller-dependencies.src.rpm failed."
215 # Main function that builds the rpm's for release's.
216 # shague: should be similar to snapshot but use a different version or tag.
217 function build_release {
218 echo "$FUNCNAME: Not implemented yet."
221 function parse_options {
229 shift; buildtype="$1"; shift;
230 if [ "$buildtype" != "snapshot" ] && [ "$buildtype" != "release" ]; then
231 usage 1 "Invalid build type.";
236 shift; buildroot="$1"; shift;
237 if [ "$buildroot" == "" ]; then
238 usage 1 "Missing build root.";
240 if [ ! -d "$buildroot" ]; then
241 usage 1 "Invalid build root path."
246 shift; buildnumber="$1"; shift;
247 if [ "$buildnumber" == "" ]; then
248 usage 1 "Missing build number.";
257 shift; getsource="$1"; shift;
258 if [ "$getsource" != "clone" ] && [ "$getsource" != "snapshot" ] && \
259 [ "$getsource" != "buildroot" ]; then
260 usage 1 "Invalid getsource method.";
265 shift; dist="$1"; shift;
266 if [ "$dist" == "" ]; then
267 usage 1 "Missing distribution.";
272 shift; release="$1"; shift;
273 if [ "$release" == "" ]; then
274 usage 1 "Missing release.";
279 shift; version="$1"; shift;
280 if [ "$version" == "" ]; then
281 usage 1 "Missing version.";
286 shift; repourl="$1"; shift;
287 if [ "$repourl" == "" ]; then
288 usage 1 "Missing repo url.";
293 shift; repouser="$1"; shift;
294 if [ "$repouser" == "" ]; then
295 usage 1 "Missing repo user.";
300 shift; repopw="$1"; shift;
301 if [ "$repopw" == "" ]; then
302 usage 1 "Missing repo pw.";
313 echo "Ignoring unknown option: $1"; shift;
319 #################### main ####################
323 # Some more error checking...
324 if [ $cleanroot = 1 ] && [ $getsource = "buildroot" ]; then
325 echo "Aborting. You probably do not want to clean the directory" \
326 "containing the source."
332 if [ $cleanroot = 1 ]; then
337 # Setup the temp build directory.
338 mkdir -p $buildroot/tmpbuild/repo
351 if [ ! -d "controller" ] || [ ! -d "integration" ]; then
352 echo "Problem with controller or integration projects in buildroot."
357 if [ "$buildtype" = "snapshot" ]; then
358 echo "Building a snapshot build"