forked from PowerDNS/pdns
/
build-dnsdist-rpm
executable file
·223 lines (188 loc) · 5.87 KB
/
build-dnsdist-rpm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/sh
if [ "$0" != "./build-scripts/build-dnsdist-rpm" ]; then
echo "Please run me from the root checkout dir"
exit 1
fi
. build-scripts/functions.sh
TARBALLPREFIX=dnsdist
startup
set -e
set -x
cp_tarball_to_rpm_sources
# Some RPM platforms use systemd, others sysv, we default to systemd here
INIT_BUILDREQUIRES='BuildRequires: systemd-devel'
INIT_INSTALL='sed -i "s,/^\(ExecStart.*\)dnsdist\(.*\)\$,\1dnsdist -u dnsdist -g dnsdist\2," %{buildroot}/lib/systemd/system/dnsdist.service'
INIT_FILES='/lib/systemd/system/dnsdist*'
INIT_CONFIGURE='--enable-systemd --with-systemd=/lib/systemd/system \'
# CentOS 6 has protobuf, but not a modern enough boost. We default to with protobuf
PROTOBUF_CONFIGURE='--with-protobuf \'
PROTOBUF_BUILDREQUIRES='BuildRequires: protobuf-compiler
BuildRequires: protobuf-devel'
# CentOS 6 has a libsodium, but we use more modern functions
SODIUM_BUILDREQUIRES='BuildRequires: libsodium-devel'
SODIUM_CONFIGURE='--enable-libsodium \'
DNSCRYPT_CONFIGURE='--enable-dnscrypt \'
# CentOS 6 needs a more modern Boost
BOOST_BUILDREQUIRES='boost-devel'
BOOST_CONFIGURE=' \'
BOOST_MAKEENV=''
# SLES 12 SP1 does not have re2
RE2_BUILDREQUIRES='BuildRequires: re2-devel'
RE2_CONFIGURE='--enable-re2 \'
# nor snmp-devel
SNMP_BUILDREQUIRES='BuildRequires: net-snmp-devel'
SNMP_CONFIGURE='--with-net-snmp \'
# CentOS 6 has no luajit
LUA_BUILDREQUIRES='BuildRequires: luajit-devel'
LUA_CONFIGURE='--with-lua=luajit \'
# These two are the same for sysv and systemd (we don't install defaults files at the moment)
DEFAULTS_INSTALL=''
DEFAULTS_FILES=''
# The package containing groupadd is different on different OSs
SHADOW_REQUIRES='shadow-utils'
# On some older distro's *cough* centos 6 *cough* autosetup fails
SETUP="%autosetup -n %{name}-${TARBALLVERSION}"
# Some setups need rpmbuild in a 'special' env
RPMBUILD_COMMAND='rpmbuild -bb dnsdist.spec'
if [ -f /etc/os-release ]; then
TMP="$(cat /etc/os-release | grep PRETTY_NAME)"
# evillllll
eval $TMP
case "$PRETTY_NAME" in
SUSE\ Linux\ Enterprise\ Server\ 12\ SP1)
RE2_BUILDREQUIRES=''
RE2_CONFIGURE='--disable-re2 \'
PROTOBUF_BUILDREQUIRES=''
PROTOBUF_CONFIGURE='--without-protobuf \'
SHADOW_REQUIRES='shadow'
LUA_BUILDREQUIRES='BuildRequires: lua-devel'
LUA_CONFIGURE=' \'
SNMP_BUILDREQUIRES=''
SNMP_CONFIGURE='--without-net-snmp \'
;;
esac
fi
if [ -f /etc/redhat-release ]; then
OS="$(cat /etc/redhat-release)"
case "$OS" in
CentOS\ *\ 6*)
INIT_BUILDREQUIRES=''
INIT_INSTALL='install -d -m 755 %{buildroot}%{_sysconfdir}/init && install -m 644 contrib/dnsdist.upstart.conf %{buildroot}%{_sysconfdir}/init/%{name}.conf'
INIT_FILES='%{_sysconfdir}/init/dnsdist.conf'
DEFAULTS_INSTALL='install -d -m 755 %{buildroot}%{_sysconfdir}/default && install -m 644 contrib/dnsdist.default %{buildroot}%{_sysconfdir}/default/%{name}'
DEFAULTS_FILES='%{_sysconfdir}/default/%{name}'
INIT_CONFIGURE='\'
SODIUM_BUILDREQUIRES=''
SODIUM_CONFIGURE='--disable-libsodium \'
DNSCRYPT_CONFIGURE='--disable-dnscrypt \'
LUA_BUILDREQUIRES='BuildRequires: lua-devel'
LUA_CONFIGURE=' \'
SETUP="%setup -n %{name}-${TARBALLVERSION}"
RPMBUILD_COMMAND="scl enable devtoolset-3 -- ${RPMBUILD_COMMAND}"
BOOST_BUILDREQUIRES="boost148-devel"
BOOST_CONFIGURE='--with-boost=/usr/include/boost148 LIBRARY_PATH=/usr/lib64/boost148'
BOOST_MAKEENV='LIBRARY_PATH=/usr/lib64/boost148'
;;
CentOS\ Linux\ *\ 7*)
;;
*)
echo "No support for $OS (yet?)"
exit 1
;;
esac
fi
# Generate the specfile
cat > dnsdist.spec << EOF
Name: dnsdist
Version: ${VERSION}
Release: ${RELEASE}
Summary: Powerful and scriptable DNS loadbalancer
License: GPLv2
Vendor: PowerDNS.COM BV
Group: System/DNS
Source: dnsdist-${TARBALLVERSION}.tar.bz2
Requires(pre): ${SHADOW_REQUIRES}
BuildRequires: ${BOOST_BUILDREQUIRES}
BuildRequires: readline-devel
${SNMP_BUILDREQUIRES}
${LUA_BUILDREQUIRES}
${PROTOBUF_BUILDREQUIRES}
${RE2_BUILDREQUIRES}
${SODIUM_BUILDREQUIRES}
${INIT_BUILDREQUIRES}
%description
dnsdist is a high-performance DNS loadbalancer that is scriptable in Lua.
%prep
${SETUP}
# run as dnsdist user
sed -i '/^ExecStart/ s/dnsdist/dnsdist -u dnsdist -g dnsdist/' dnsdist.service.in
%build
%configure \
--sysconfdir=/etc/dnsdist \
${SNMP_CONFIGURE}
${LUA_CONFIGURE}
${RE2_CONFIGURE}
${SODIUM_CONFIGURE}
${DNSCRYPT_CONFIGURE}
${INIT_CONFIGURE}
${PROTOBUF_CONFIGURE}
${BOOST_CONFIGURE}
make ${BOOST_MAKEENV}
mv dnsdistconf.lua dnsdist.conf.sample
%check
make %{?_smp_mflags} check || (cat test-suite.log && false)
%install
%make_install
install -d %{buildroot}/%{_sysconfdir}/dnsdist
${INIT_INSTALL}
${DEFAULTS_INSTALL}
%pre
getent group dnsdist >/dev/null || groupadd -r dnsdist
getent passwd dnsdist >/dev/null || \
useradd -r -g dnsdist -d / -s /sbin/nologin \
-c "dnsdist user" dnsdist
exit 0
%post
%if 0%{?el6}
if [ -x /sbin/initctl ]; then
/sbin/initctl reload-configuration
fi
%elif 0%{?suse_version}
%service_add_post %{name}.service
%else
%systemd_post %{name}.service
%endif
%preun
%if 0%{?el6}
if [ \$1 -eq 0 ] ; then
# This is package removal, not upgrade
/sbin/stop %{name} >/dev/null 2>&1 || :
fi
%elif 0%{?suse_version}
%service_del_preun %{name}.service
%else
%systemd_preun %{name}.service
%endif
%postun
%if 0%{?el6}
if [ -x /sbin/initctl ] && /sbin/initctl status %{name} 2>/dev/null | grep -q 'running' ; then
/sbin/initctl stop %{name} > /dev/null 2>&1 || :
fi
%elif 0%{?suse_version}
%service_del_postun %{name}.service
%else
%systemd_postun_with_restart %{name}.service
%endif
%files
%{!?_licensedir:%global license %%doc}
%doc dnsdist.conf.sample
%doc README.md
%license COPYING
%{_bindir}/*
%{_mandir}/man1/*
%dir %{_sysconfdir}/dnsdist
${INIT_FILES}
%config(noreplace) ${DEFAULTS_FILES}
EOF
${RPMBUILD_COMMAND}
mv $HOME/rpmbuild/RPMS/x86_64/dnsdist*-${VERSION}-${RELEASE}.x86_64.rpm .