0ea75a0e43e131407a9d5a9e62eda75de575ecfd
[kvmfornfv.git] / fuel-plugin / build_kvm.sh
1 #!/bin/bash
2
3 KVM_COMMIT="0e68cb048bb8aadb14675f5d4286d8ab2fc35449"
4 OVS_COMMIT="4ff6642f3c1dd8949c2f42b3310ee2523ee970a6"
5 KEEP=no
6
7 quirks() {
8
9         #
10         # Apply out of tree patches
11         #
12         for i in $SRC/kvmfornfv/patches/$1/*.patch
13         do
14                 if [ -f "$i" ]
15                 then
16                         echo "Applying: $i"
17                         patch -p1 <$i
18                 fi
19         done
20 }
21
22 for i
23 do
24         case $i in
25
26         -k)     KEEP=yes
27                 shift
28                 ;;
29
30         -c)     KVM_COMMIT=$2
31                 shift;shift
32                 ;;
33
34         -o)     OVS_COMMIT=$2
35                 shift;shift
36                 ;;
37
38         esac
39 done
40
41 SRC=${1:-/root}
42 CONFIG=${2:-arch/x86/configs/opnfv.config}
43 VERSION=${3:-1.0.OPNFV}
44
45 # Check for necessary build tools
46 if ! type git >/dev/null 2>/dev/null
47 then
48         echo "Build tools missing, run the command
49
50 apt-get install git fakeroot build-essential ncurses-dev xz-utils kernel-package automake
51
52 as root and try again"
53         exit 1
54 fi
55
56 # Make sure the source dir exists
57 if [ ! -d $SRC ]
58 then
59         echo "$SRC: no such directory"
60         exit 1
61 fi
62
63 (
64         cd $SRC
65
66         # Get the Open VSwitch sources
67         if [ ! -d ovs ]
68         then
69                 git clone https://github.com/openvswitch/ovs.git
70         fi
71
72         # Get the KVM for NFV kernel sources
73         if [ ! -d kvmfornfv ]
74         then
75                 git clone https://gerrit.opnfv.org/gerrit/kvmfornfv
76         fi
77         cd kvmfornfv
78         git pull
79         if [ x$KVM_COMMIT != x ]
80         then
81                 git checkout $KVM_COMMIT
82         else
83                 git reset --hard
84         fi
85         cd kernel
86
87         # Workaround build bug on Ubuntu 14.04
88         cat <<EOF > arch/x86/boot/install.sh
89 #!/bin/sh
90 cp -a -- "\$2" "\$4/vmlinuz-\$1"
91 EOF
92
93         quirks kernel
94
95         # Configure the kernel
96         cp $CONFIG .config
97
98         make oldconfig </dev/null
99
100         # Build the kernel debs
101         if [ $KEEP = no ]
102         then
103                 make-kpkg clean
104         fi
105         fakeroot make-kpkg --initrd --revision=$VERSION kernel_image kernel_headers
106         git checkout arch/x86/boot/install.sh
107         git checkout fs/xfs/xfs_super.c
108
109         # Build OVS kernel modules
110         cd ../../ovs
111         if [ x$OVS_COMMIT != x ]
112         then
113                 git checkout $OVS_COMMIT
114         else
115                 git reset --hard
116         fi
117
118         quirks ovs
119
120         ./boot.sh
121         ./configure --with-linux=$SRC/kvmfornfv/kernel
122         make
123
124         # Add OVS kernel modules to kernel deb
125         dpkg-deb -x $SRC/kvmfornfv/linux-image*.deb ovs.$$
126         dpkg-deb --control $SRC/kvmfornfv/linux-image*.deb ovs.$$/DEBIAN
127         cp datapath/linux/*.ko ovs.$$/lib/modules/*/kernel/net/openvswitch
128         depmod -b ovs.$$ -a `ls ovs.$$/lib/modules`
129         dpkg-deb -b ovs.$$ $SRC/kvmfornfv/linux-image*.deb
130         rm -rf ovs.$$
131 )
132
133 mv $SRC/kvmfornfv/*.deb .