OPNFV KVM4NFV CICD: Scripts for creating Rpms & Debians for Kernel, Qemu
[kvmfornfv.git] / ci / build_rpm / qemu_rpm_build.sh
1 #!/bin/bash
2
3 qemu_src_dir=qemu
4 workspace=/root
5 rpmbuild_dir=$workspace/rpmbuild
6 artifact_rpms=$rpmbuild_dir/RPMS
7 artifact_dir=$artifact_rpms/x86_64
8 scripts_dir=ci/build_rpm
9 output_dir="$1"
10 VERSION=`grep -m 1 "VERSION"  ${qemu_src_dir}/config-host.mak | cut -d= -f2-`
11
12 usage () {
13     echo "usage: ${0} output_dir"
14     exit 1
15 }
16
17 if [[ -z "$@" ]]; then
18     usage
19 fi
20
21 if [ ! -d ${output_dir} -o ! -w ${output_dir} ] ; then
22     echo "${0}: Output directory '${output_dir}' does not exist or cannot \
23           be written"
24     exit 1
25 fi
26
27 if [ ! -d ${qemu_src_dir} ] ; then
28     echo "${0}: Directory '${qemu_src_dir}' does not exist, run this script \
29           from the root of kvmfornfv source tree"
30     exit 1
31 fi
32
33 echo
34 echo "Build"
35 echo
36
37 qemu_rpm_build() {
38     cp  -r ${qemu_src_dir}  ${qemu_src_dir}-$VERSION
39     tar -zcvf ${qemu_src_dir}-$VERSION.tar.gz ${qemu_src_dir}-$VERSION
40     mv ${qemu_src_dir}-$VERSION.tar.gz ${rpmbuild_dir}/SOURCES/
41
42     #create a spec file for rpm creation.
43     (cd ${scripts_dir}; ./mkspec $VERSION > qemu.spec)
44     cp ${scripts_dir}/qemu.spec ${rpmbuild_dir}/SPECS/
45
46     #build the qemu rpm with spec file developed
47     rpmbuild -ba ${rpmbuild_dir}/SPECS/qemu.spec
48     if [ ${?} -ne 0 ] ; then
49         echo "${0}: qemu build failed"
50         exit 1
51     fi
52     rm -rf ${qemu_src_dir}-$VERSION
53     rm -rf ${rpmbuild_dir}/SOURCES/${qemu_src_dir}-$VERSION.tar.gz
54 }
55
56 if [ ! -d ${rpmbuild_dir} ] ; then
57     yum install rpm-build -y
58     mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
59     mv rpmbuild $workspace
60 fi
61
62 qemu_rpm_build
63 latest_qemu_build=`ls -rt $artifact_dir | grep qemu-2.6* | tail -1`
64 cp $artifact_dir/$latest_qemu_build build_output