Fixes RPM build problem. Use correct copr repo. Fix some version number parsing
[ovsnfv.git] / build / build_ovs_rpm.sh
1 #!/bin/bash
2
3 # Copyright (c) 2016 Open Platform for NFV Project, Inc. and its contributors
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License");
6 #    you may not use this file except in compliance with the License.
7 #    You may obtain a copy of the License at
8 #
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS,
12 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #    See the License for the specific language governing permissions and
14 #    limitations under the License.
15
16 set -e
17
18 echo "==============================="
19 echo executing $0 $@
20 echo executing on machine `uname -a`
21
22 usage() {
23     echo run BuildAndTestOVS -h for help
24 }
25
26 function delrpm() {
27     set +e
28     rpm -q $1
29     if [ $? -eq 0 ]; then
30         sudo rpm -e --allmatches $1
31     fi
32     set -e
33 }
34 function cleanrpms() {
35     delrpm openvswitch
36     delrpm dpdk-devel
37     delrpm dpdk-tools
38     delrpm dpdk-examples
39     delrpm dpdk
40 }
41
42 while getopts "cdg:hkp:u:v" opt; do
43     case "$opt" in
44         c)
45             setnocheck="--without check"
46             ;;
47         d)
48             DPDK="yes"
49             ;;
50         g)
51             TAG=${OPTARG}
52             ;;
53         h|\?)
54             usage
55             exit 1
56             ;;
57         k)
58             kmod="yes"
59             ;;
60         p)
61             OVS_PATCH=${OPTARG}
62             ;;
63         u)
64             OVS_REPO_URL=${OPTARG}
65             ;;
66         v)
67             verbose="yes"
68             ;;
69     esac
70 done
71
72 HOME=`pwd`
73 TOPDIR=$HOME
74 TMPDIR=$TOPDIR/ovsrpm
75
76 echo "---------------------------------------"
77 echo Clean out old working dir
78 echo
79 if [ -d $TMPDIR ]
80 then
81     rm -rf $TMPDIR
82 fi
83
84 echo "----------------------------------------"
85 echo Install pre-reqs.
86 echo
87 sudo yum -y install gcc make python-devel openssl-devel kernel-devel graphviz \
88        kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
89        libtool python-twisted-core desktop-file-utils groff PyQt4
90
91 VERSION=2.3.90
92 os_type=fedora
93 kernel_version=$(uname -a | awk '{print $3}')
94
95 RPMDIR=$HOME/rpmbuild
96
97 echo "---------------------------------------"
98 echo Clean out old reminents of old rpms and rpm _topdir.
99 echo
100
101 rm openvswitch*.rpm || true
102 if [  -d $RPMDIR ]; then
103     rm -rf $RPMDIR
104 fi
105
106 echo "---------------------------------------"
107 echo Create new rpm _topdir.
108 echo
109 mkdir -p $HOME/rpmbuild/RPMS
110 mkdir -p $HOME/rpmbuild/SOURCES
111 mkdir -p $HOME/rpmbuild/SPECS
112 mkdir -p $HOME/rpmbuild/SRPMS
113
114
115 mkdir -p $TMPDIR
116
117 cd $TMPDIR
118
119 if [ ! -z $DPDK ]; then
120     echo "----------------------------------"
121     echo "Build OVS for dpdk. Use Fedora copr repo"
122     echo
123     echo "----------------------------------"
124     echo "Clone Fedora copr repo and copy files."
125     echo
126     git clone http://copr-dist-git.fedorainfracloud.org/cgit/pmatilai/dpdk-snapshot/openvswitch.git
127     cp $TMPDIR/openvswitch/openvswitch.spec $RPMDIR/SPECS
128     cp $TMPDIR/openvswitch/* $RPMDIR/SOURCES
129     snapgit=`grep "define snapver" $TMPDIR/openvswitch/openvswitch.spec | cut -c26-33`
130     echo "-------------------------------------------"
131     echo "Remove old dpdk, ovs and dpdk development rpms"
132     echo
133     cleanrpms
134
135     if [ -z $DPDK_VERSION ]; then
136         DPDK_VERSION=16.04.0
137     fi
138     echo "-------------------------------------------"
139     echo "Install dpdk and dpdk development rpms for version $DPDK_VERSION"
140     echo
141     sudo rpm -ivh $HOME/dpdk-${DPDK_VERSION:0:1}*.rpm
142     sudo rpm -ivh $HOME/dpdk-devel*.rpm
143     echo "----------------------------------------"
144     echo "Copy DPDK RPM to SOURCES"
145     echo
146     cp $HOME/*.rpm $RPMDIR/SOURCES
147     echo "--------------------------------------------"
148     echo "Get commit from $snapgit User Space OVS version $TAG"
149     echo
150     cd $TMPDIR
151     git clone $OVS_REPO_URL
152     cd $TMPDIR/ovs
153     git checkout $snapgit
154     echo "--------------------------------------------"
155     echo "Creating snapshot, $archive with name same as in spec file."
156     echo
157     snapser=`git log --pretty=oneline | wc -l`
158     basever=`grep AC_INIT configure.ac | cut -d' ' -f2 | cut -d, -f1`
159     prefix=openvswitch-${basever}
160     archive=${prefix}-${snapser}.git${snapgit}.tar.gz
161     git archive --prefix=${prefix}-${snapser}.git${snapgit}/ HEAD  | gzip -9 > $RPMDIR/SOURCES/${archive}
162     cd $TMPDIR/openvswitch
163     echo "--------------------------------------------"
164     echo "Build openvswitch RPM"
165     echo
166 else
167     echo "-------------------------------------------------"
168     echo "Build OVS without DPDK:"
169     echo "Use spec files for $os_type in OVS distribution."
170     echo
171     if [[ "$TAG" =~ "master" ]]; then
172         git clone $OVS_REPO_URL
173         cd ovs
174
175         if [[ ! "$OVS_PATCH" =~ "no" ]]; then
176             echo "Apply patches from $OVS_PATCH"
177         fi
178         basever=`grep AC_INIT configure.ac | cut -d' ' -f2 | cut -d, -f1`
179         export VERSION=$basever
180
181         echo "--------------------------------------------"
182         echo making distribution tarball for Open vswitch version $VERSION
183         echo
184         ./boot.sh
185         ./configure
186         make dist
187
188         echo cp openvswitch-*.tar.gz $HOME/rpmbuild/SOURCES
189         cp openvswitch-*.tar.gz $HOME/rpmbuild/SOURCES
190     else
191         export VERSION=${TAG}
192         echo "---------------------------------------------"
193         echo "Get openvswith-${VERSION}.tar.gz"
194         echo
195         curl --silent --output $HOME/rpmbuild/SOURCES/openvswitch-${VERSION}.tar.gz http://openvswitch.org/releases/openvswitch-${VERSION}.tar.gz
196     fi
197
198     if [ ! -z $kmod ]; then
199         echo "--------------------------------------------"
200         echo "Building openvswitch kernel module RPM"
201         echo
202         rpmbuild -bb -D "kversion $kernel_version" -D "kflavors default" --define "_topdir `echo $RPMDIR`" $setnocheck rhel/openvswitch-kmod-${os_type}.spec
203     fi
204     echo "--------------------------------------------"
205     echo "Build openvswitch RPM"
206     echo
207 fi
208 rpmbuild -bb --define "_topdir `echo $RPMDIR`" $setnocheck openvswitch.spec
209
210 cp $RPMDIR/RPMS/x86_64/*.rpm $HOME
211
212 exit 0