ca0fea1d75f8c1dd666e39eba12b78fe2287d6ab
[kvmfornfv.git] / ci / installer_build.sh
1 #!/bin/bash
2
3 output_dir="$1"
4 installer_type="$2"
5 function checkout_commit() {
6 build_dir=/opt/kvmfornfv/
7 mkdir -p /tmp/kvmfornfv
8 SRC=/tmp/kvmfornfv
9 if [[ "$installer_type" == "apex" ]];then
10    source ${build_dir}/ci/apex.conf
11 else
12    source ${build_dir}/ci/compass.conf
13 fi
14 #Cloning into /tmp/kvmfornfv
15 cd $SRC
16 if [[ "$branch" == "master" ]] || [[ "$branch" == *"danube"* ]];then
17    echo "Cloning the repository of $branch given"
18    git clone -b $branch https://gerrit.opnfv.org/gerrit/kvmfornfv.git /tmp/kvmfornfv
19    git branch
20    echo "Commit-id is ${commit_id}"
21    git checkout -f ${commit_id}
22    if [ $? -ne 0 ];then
23       echo "Please check the commit-id provided in installer conf file"
24       exit 1
25    fi
26 fi
27 mkdir ${output_dir}
28 }
29
30 checkout_commit
31
32 kernel_src_dir=$SRC/kernel
33 config_file="${kernel_src_dir}/arch/x86/configs/opnfv.config"
34 cp -f ${config_file} "${kernel_src_dir}/.config"
35
36 usage () {
37     echo "usage: ${0} output_dir"
38     exit 1
39 }
40
41 if [[ -z "$@" ]]; then
42     usage
43 fi
44
45 if [ ! -d ${output_dir} -o ! -w ${output_dir} ] ; then
46     echo "${0}: Output directory '${output_dir}' does not exist or cannot \
47           be written"
48     exit 1
49 fi
50
51 if [ ! -d ${kernel_src_dir} ] ; then
52     echo "${0}: Directory '${kernel_src_dir}' does not exist, run this script \
53           from the root of kvmfornfv source tree"
54     exit 1
55 fi
56
57 if [ ! -f ${config_file} ] ; then
58     echo "${0}: ${config_file} does not exist"
59     exit 1
60 fi
61
62 echo
63 echo "Build"
64 echo
65
66 function apex_rpm_build (){
67 rpmbuild_dir=$SRC/kvmfornfv_rpmbuild.$$
68 artifact_dir=${rpmbuild_dir}/RPMS/x86_64
69 mkdir -p $artifact_dir
70
71 # Make timestamp part of version string for automated kernel boot verification
72 date "+-%y%m%d%H%M" > "${kernel_src_dir}/localversion-zzz"
73
74 (cd ${kernel_src_dir}; make RPMOPTS="--define '_topdir ${rpmbuild_dir}'" rpm-pkg)
75 if [ ${?} -ne 0 ] ; then
76     echo "${0}: Kernel build failed"
77     rm -rf ${rpmbuild_dir}
78     exit 1
79 fi
80
81 cp -f ${artifact_dir}/* ${output_dir}
82 mv ${output_dir}/* ${build_dir}/build_output/
83
84 rm -rf ${rpmbuild_dir}
85 #cleaning the /tmp
86 rm -rf ${SRC}
87 }
88
89 function compass_deb_build(){
90 cd ${kernel_src_dir}
91 make oldconfig
92
93 quirks(){
94    #
95    # Apply out of tree patches
96    #
97    echo "Inside quirks"
98    for i in $SRC/kvmfornfv/patches/$1/*.patch
99    do
100       if [ -f "$i" ]
101       then
102          echo "Applying: $i"
103          patch -p1 <$i
104       fi
105    done
106    echo "end quirks"
107 }
108 quirks kernel
109
110 echo "SRC is:$SRC"
111 echo "kernel_src_dir is : $kernel_src_dir"
112
113 VERSION="1.0.OPNFV"
114 # Configure the kernel
115 cd $kernel_src_dir
116
117 # Workaround build bug on Ubuntu 14.04
118 cat <<EOF > arch/x86/boot/install.sh
119 #!/bin/sh
120 cp -a -- "\$2" "\$4/vmlinuz-\$1"
121 EOF
122
123 # Build the kernel debs
124 make-kpkg clean
125 fakeroot make-kpkg --initrd --revision=$VERSION kernel_image kernel_headers kernel_debug -j$(nproc)
126 make
127
128 echo "list the debians built"
129 ls -lrth $SRC
130 mv $SRC/linux-* $build_dir/build_output
131 }
132
133 if [[ "$installer_type" == "apex" ]];then
134    apex_rpm_build
135 else
136    compass_deb_build
137 fi
138