Pass flags to allow domain undefine with NVRAM
[apex.git] / build / build_quagga.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2017 Tim Rozet (Red Hat) and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -xe
12
13 ARTIFACT=None
14
15 # Builds Quagga, Zebra and other dependency RPMs for CentOS 7
16 # Install package dependencies
17 install_quagga_build_deps() {
18   sudo yum -y install automake bison flex libtool make readline-devel \
19                texinfo texi2html rpm-build libcap-devel groff net-snmp-devel pam-devel glib2 glib2-devel epel-release spectool \
20                wget git gcc-c++ openssl-devel boost-devel boost-static gtest zeromq-4.1.4 zeromq-devel-4.1.4 \
21                capnproto-devel capnproto-libs capnproto
22   sudo yum -y groupinstall "Development Tools"
23 }
24
25 display_usage ()
26 {
27 cat << EOF
28 $0 Builds Quagga/ZRPC and Dependency RPMs
29
30 usage: $0 [ [-a | --artifact] artifact ]
31
32 OPTIONS:
33   -a artifact to build (thrift, capnproto, quagga, zrpc). Default: All artifacts.
34   -c clean all build directories
35   -h help, prints this help text
36
37 Example:
38 build_quagga.sh -a thrift
39 EOF
40 }
41
42 parse_cmdline() {
43   while [ "${1:0:1}" = "-" ]
44   do
45     case "$1" in
46         -h|--help)
47                 display_usage
48                 exit 0
49             ;;
50         -a|--artifact)
51                 ARTIFACT=${2}
52                 shift 2
53             ;;
54         -c|--clean)
55                 CLEAN="True"
56                 shift 1
57             ;;
58         *)
59                 display_usage
60                 exit 1
61             ;;
62     esac
63   done
64
65 }
66
67 # Removes build directory folder and re-creates RPM DIRs to use
68 function quagga_clean(){
69   rm -rf ${QUAGGA_BUILD_DIR}
70   sudo yum remove -y zrpc* quagga* thrift* c-capnproto*
71 }
72
73 # Build Thrift RPM
74 function build_thrift(){
75   rm -rf thrift
76   git clone https://git-wip-us.apache.org/repos/asf/thrift.git
77   pushd thrift
78   git checkout 0.10.0
79   wget https://issues.apache.org/jira/secure/attachment/12840511/0002-THRIFT-3986-using-autoreconf-i-fails-because-of-miss.patch
80   wget https://issues.apache.org/jira/secure/attachment/12840512/0001-THRIFT-3987-externalise-declaration-of-thrift-server.patch
81   patch -p1 < 0002-THRIFT-3986-using-autoreconf-i-fails-because-of-miss.patch
82   patch -p1 < 0001-THRIFT-3987-externalise-declaration-of-thrift-server.patch
83   autoreconf -i
84   ./configure --without-qt4 --without-qt5 --without-csharp --without-java \
85     --without-erlang --without-nodejs --without-perl --without-python \
86     --without-php --without-php_extension --without-dart --without-ruby \
87     --without-haskell --without-go --without-haxe --without-d
88   # Hack somehow the testing file of php is not there
89   # We will disable php anyhow later on.
90   touch lib/php/src/ext/thrift_protocol/run-tests.php
91   make dist
92   pushd contrib/
93   spectool -g -R thrift.spec
94   mv ../thrift-*.tar.gz $rpmbuild/SOURCES/
95   rpmbuild --define "_topdir $rpmbuild" -ba thrift.spec --define "without_ruby 1" --define "without-php 1"
96   popd > /dev/null
97   popd > /dev/null
98 }
99
100 # c-capnproto RPM
101 # This is a library for capnproto in C. Not to be confused with
102 # the capnproto provided by the repos
103 function build_capnproto(){
104   rm -rf c-capnproto
105   git clone https://github.com/opensourcerouting/c-capnproto
106   pushd c-capnproto
107   git checkout 332076e52257
108   autoreconf -i
109   ./configure --without-gtest
110   make dist
111
112   cp ${BUILD_ROOT}/rpm_specs/c_capnproto.spec $rpmbuild/SPECS/
113   cp c-capnproto-*.tar.gz $rpmbuild/SOURCES/
114   rpmbuild --define "_topdir $rpmbuild" -ba $rpmbuild/SPECS/c_capnproto.spec
115   popd > /dev/null
116 }
117
118 build_quagga(){
119   # Build Quagga
120   rm -rf quagga
121   sudo yum -y install $rpmbuild/RPMS/x86_64/*.rpm
122   git clone https://github.com/6WIND/quagga.git
123   pushd quagga > /dev/null
124   # checkout the parent of the bellow patch.
125   # Once the issue addressed by the patch is fixed
126   # these two lines can be removed.
127   git checkout 95bb0f4a
128   patch -p1 < ${PATCHES_DIR}/fix_quagga_make_dist.patch
129   autoreconf -i
130   ./configure --with-zeromq --with-ccapnproto --enable-user=quagga \
131     --enable-group=quagga --enable-vty-group=quagga \
132     --disable-doc --enable-multipath=64
133
134   # Quagga RPM
135   make dist
136   cp ${BUILD_ROOT}/rpm_specs/quagga.spec $rpmbuild/SPECS/
137   cp quagga*.tar.gz $rpmbuild/SOURCES/
138   cat > $rpmbuild/SOURCES/bgpd.conf <<EOF
139 hostname bgpd
140 password sdncbgpc
141 service advanced-vty
142 log stdout
143 line vty
144  exec-timeout 0 0
145 debug bgp
146 debug bgp updates
147 debug bgp events
148 debug bgp fsm
149 EOF
150   rpmbuild --define "_topdir $rpmbuild" -ba $rpmbuild/SPECS/quagga.spec
151   popd > /dev/null
152 }
153
154 # Build ZPRC
155 build_zrpc(){
156   sudo yum -y install $rpmbuild/RPMS/x86_64/*.rpm
157   rm -rf zrpcd
158   git clone https://github.com/6WIND/zrpcd.git
159   pushd zrpcd > /dev/null
160   touch NEWS README
161   export QUAGGA_CFLAGS='-I/usr/include/quagga/'
162   # checkout the parent of the bellow patch.
163   # Once the issue addressed by the patch is fixed
164   # these two lines can be removed.
165   git checkout 9bd1ee8e
166   patch -p1 < ${PATCHES_DIR}/fix_zrpcd_make_dist.patch
167   patch -p1 < ${PATCHES_DIR}/zrpcd_hardcoded_paths.patch
168   autoreconf -i
169
170   # ZRPC RPM
171   ./configure --enable-zrpcd \
172    --enable-user=quagga --enable-group=quagga \
173    --enable-vty-group=quagga --with-thrift-version=4
174   make dist
175
176   cat > $rpmbuild/SOURCES/zrpcd.service <<EOF
177 [Unit]
178 Description=ZRPC daemon for quagga
179 After=network.service
180
181 [Service]
182 ExecStart=/usr/sbin/zrpcd
183 Type=simple
184 ExecStartPre=-/usr/bin/mkdir /var/run/quagga/
185 ExecStartPre=/usr/bin/chown -R quagga:quagga /var/run/quagga/
186 PIDFile=/var/run/zrpcd.pid
187
188 [Install]
189 WantedBy=default.target
190 EOF
191   cp zrpcd-*.tar.gz $rpmbuild/SOURCES/
192   cp ${BUILD_ROOT}/rpm_specs/zrpc.spec $rpmbuild/SPECS/
193   rpmbuild --define "_topdir $rpmbuild" -ba $rpmbuild/SPECS/zrpc.spec
194 }
195
196 # Main
197 parse_cmdline "$@"
198
199 # Check env vars
200 if [ -z "$QUAGGA_BUILD_DIR" ]; then
201   echo "ERROR: You must set QUAGGA_BUILD_DIR env variable as the location to build!"
202   exit 1
203 elif [ -z "$QUAGGA_RPMS_DIR" ]; then
204   echo "WARN: QUAGGA_RPMS_DIR env var is not set, will default to QUAGGA_BUILD_DIR/rpmbuild"
205   rpmbuild=${QUAGGA_BUILD_DIR}/rpmbuild
206 else
207   rpmbuild=${QUAGGA_RPMS_DIR}
208 fi
209
210 if [ -z "$BUILD_ROOT" ]; then
211   echo "WARN: BUILD_ROOT env var not set, will default to $(pwd)"
212   BUILD_ROOT=$(pwd)
213 fi
214
215 if [ -z "$PATCHES_DIR" ]; then
216   echo "WARN: PATCHES_DIR env var not set, will default to ${BUILD_ROOT}/patches"
217   PATCHES_DIR=${BUILD_ROOT}/patches
218 fi
219
220 if [ -n "$CLEAN" ]; then
221   quagga_clean
222 fi
223
224 install_quagga_build_deps
225
226 mkdir -p ${QUAGGA_BUILD_DIR}
227 mkdir -p $rpmbuild $rpmbuild/SOURCES $rpmbuild/SPECS $rpmbuild/RPMS
228 pushd $QUAGGA_BUILD_DIR > /dev/null
229
230 case "$ARTIFACT" in
231         thrift)
232           build_thrift
233           ;;
234         capnproto)
235           build_capnproto
236           ;;
237         quagga)
238           build_quagga
239           ;;
240         zrpc)
241           build_zrpc
242           ;;
243         *)
244           build_thrift
245           build_capnproto
246           build_quagga
247           build_zprc
248           ;;
249 esac
250
251 popd > /dev/null