5b8184076c3b986210806210e4b9fd3021eff492
[kvmfornfv.git] / ci / apex_build.sh
1 #!/bin/bash
2
3 function checkout_commit() {
4 build_dir=/opt/kvmfornfv/
5 mkdir -p /tmp/kvmfornfv
6 SRC=/tmp/kvmfornfv
7 source ${build_dir}/ci/apex.conf
8 cd $SRC
9 #Cloning into /tmp/kvmfornfv from local repository
10 git clone $build_dir $SRC
11 if [ "$branch" == "master" ] || [ "$branch" == "danube" ];then
12    echo "Checking out on $branch branch"
13    echo "Commit-id is ${commit_id}"
14    git checkout -f ${commit_id}
15 fi
16 mkdir ${output_dir}
17 }
18
19 output_dir="$1"
20 checkout_commit
21
22 kernel_src_dir=$SRC/kernel
23 rpmbuild_dir=$SRC/kvmfornfv_rpmbuild.$$
24 artifact_dir=${rpmbuild_dir}/RPMS/x86_64
25 mkdir -p $artifact_dir
26 config_file="${kernel_src_dir}/arch/x86/configs/opnfv.config"
27
28 usage () {
29     echo "usage: ${0} output_dir"
30     exit 1
31 }
32
33
34 if [[ -z "$@" ]]; then
35     usage
36 fi
37
38 if [ ! -d ${output_dir} -o ! -w ${output_dir} ] ; then
39     echo "${0}: Output directory '${output_dir}' does not exist or cannot \
40           be written"
41     exit 1
42 fi
43
44 if [ ! -d ${kernel_src_dir} ] ; then
45     echo "${0}: Directory '${kernel_src_dir}' does not exist, run this script \
46           from the root of kvmfornfv source tree"
47     exit 1
48 fi
49
50 if [ ! -f ${config_file} ] ; then
51     echo "${0}: ${config_file} does not exist"
52     exit 1
53 fi
54
55 echo
56 echo "Build"
57 echo
58
59 cp -f ${config_file} "${kernel_src_dir}/.config"
60
61 # Make timestamp part of version string for automated kernel boot verification
62 date "+-%y%m%d%H%M" > "${kernel_src_dir}/localversion-zzz"
63
64 (cd ${kernel_src_dir}; make RPMOPTS="--define '_topdir ${rpmbuild_dir}'" rpm-pkg)
65 if [ ${?} -ne 0 ] ; then
66     echo "${0}: Kernel build failed"
67     rm -rf ${rpmbuild_dir}
68     exit 1
69 fi
70
71 cp -f ${artifact_dir}/* ${output_dir}
72 mv ${output_dir}/* ${build_dir}/build_output/
73
74 rm -rf ${rpmbuild_dir}
75 #cleaning the /tmp
76 rm -rf ${SRC}