app-emulation/runc: Add new snapshot
[gentoo.git] / net-misc / dhcp / dhcp-4.3.4.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils systemd toolchain-funcs user
8
9 MY_PV="${PV//_alpha/a}"
10 MY_PV="${MY_PV//_beta/b}"
11 MY_PV="${MY_PV//_rc/rc}"
12 MY_PV="${MY_PV//_p/-P}"
13 MY_P="${PN}-${MY_PV}"
14 DESCRIPTION="ISC Dynamic Host Configuration Protocol (DHCP) client/server"
15 HOMEPAGE="http://www.isc.org/products/DHCP"
16 SRC_URI="ftp://ftp.isc.org/isc/dhcp/${MY_P}.tar.gz
17         ftp://ftp.isc.org/isc/dhcp/${MY_PV}/${MY_P}.tar.gz"
18
19 LICENSE="ISC BSD SSLeay GPL-2" # GPL-2 only for init script
20 SLOT="0"
21 KEYWORDS="~alpha amd64 arm ~arm64 hppa ia64 ~m68k ~mips ppc ppc64 ~s390 ~sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
22 IUSE="+client ipv6 kernel_linux ldap libressl selinux +server ssl vim-syntax"
23
24 DEPEND="
25         client? (
26                 kernel_linux? (
27                         ipv6? ( sys-apps/iproute2 )
28                         sys-apps/net-tools
29                 )
30         )
31         ldap? (
32                 net-nds/openldap
33                 ssl? (
34                         !libressl? ( dev-libs/openssl:0 )
35                         libressl? ( dev-libs/libressl )
36                 )
37         )"
38 RDEPEND="${DEPEND}
39         selinux? ( sec-policy/selinux-dhcp )
40         vim-syntax? ( app-vim/dhcpd-syntax )"
41
42 S="${WORKDIR}/${MY_P}"
43
44 src_unpack() {
45         unpack ${A}
46         # handle local bind hell
47         cd "${S}"/bind
48         unpack ./bind.tar.gz
49 }
50
51 PATCHES=(
52         # Gentoo patches - these will probably never be accepted upstream
53         # Fix some permission issues
54         "${FILESDIR}/${PN}-3.0-fix-perms.patch"
55
56         # Enable dhclient to equery NTP servers
57         "${FILESDIR}/${PN}-4.3.4-dhclient-ntp.patch"
58         "${FILESDIR}/${PN}-4.3.1-dhclient-resolvconf.patch"
59
60         # Stop downing the interface on Linux as that breaks link daemons
61         # such as wpa_supplicant and netplug
62         "${FILESDIR}/${PN}-3.0.3-dhclient-no-down.patch"
63
64         # Enable dhclient to get extra configuration from stdin
65         "${FILESDIR}/${PN}-4.2.2-dhclient-stdin-conf.patch"
66         "${FILESDIR}/${PN}-4.2.2-nogateway.patch" #265531
67         "${FILESDIR}/${PN}-4.2.4-quieter-ping.patch" #296921
68         "${FILESDIR}/${PN}-4.2.4-always-accept-4.patch" #437108
69         "${FILESDIR}/${PN}-4.2.5-iproute2-path.patch" #480636
70         "${FILESDIR}/${PN}-4.2.5-bindtodevice-inet6.patch" #471142
71         "${FILESDIR}/${PN}-4.3.3-ldap-ipv6-client-id.patch" #559832
72 )
73
74 src_prepare() {
75         epatch "${PATCHES[@]}"
76
77         # Brand the version with Gentoo
78         sed -i \
79                 -e "/VERSION=/s:'$: Gentoo-${PR}':" \
80                 configure || die
81
82         # Change the hook script locations of the scripts
83         sed -i \
84                 -e 's,/etc/dhclient-exit-hooks,/etc/dhcp/dhclient-exit-hooks,g' \
85                 -e 's,/etc/dhclient-enter-hooks,/etc/dhcp/dhclient-enter-hooks,g' \
86                 client/scripts/* || die
87
88         # No need for the linux script to force bash #158540
89         sed -i -e 's,#!/bin/bash,#!/bin/sh,' client/scripts/linux || die
90
91         # Quiet the freebsd logger a little
92         sed -i -e '/LOGGER=/ s/-s -p user.notice //g' client/scripts/freebsd || die
93
94         # Remove these options from the sample config
95         sed -i -r \
96                 -e "/(script|host-name|domain-name) /d" \
97                 client/dhclient.conf.example || die
98
99         if use client && ! use server ; then
100                 sed -i -r \
101                         -e '/^SUBDIRS/s:\<(dhcpctl|relay|server)\>::g' \
102                         Makefile.in || die
103         elif ! use client && use server ; then
104                 sed -i -r \
105                         -e '/^SUBDIRS/s:\<client\>::' \
106                         Makefile.in || die
107         fi
108
109         # Only install different man pages if we don't have en
110         if [[ " ${LINGUAS} " != *" en "* ]]; then
111                 # Install Japanese man pages
112                 if [[ " ${LINGUAS} " == *" ja "* && -d doc/ja_JP.eucJP ]]; then
113                         einfo "Installing Japanese documention"
114                         cp doc/ja_JP.eucJP/dhclient* client
115                         cp doc/ja_JP.eucJP/dhcp* common
116                 fi
117         fi
118         # Now remove the non-english docs so there are no errors later
119         rm -rf doc/ja_JP.eucJP
120
121         # make the bind build work
122         binddir=${S}/bind
123         cd "${binddir}" || die
124         cat <<-EOF > bindvar.tmp
125         binddir=${binddir}
126         GMAKE=${MAKE:-gmake}
127         EOF
128         epatch "${FILESDIR}"/${PN}-4.3.4-bind-disable.patch
129         cd bind-*/
130         epatch "${FILESDIR}"/${PN}-4.2.2-bind-parallel-build.patch #380717
131         epatch "${FILESDIR}"/${PN}-4.2.2-bind-build-flags.patch
132 }
133
134 src_configure() {
135         # bind defaults to stupid `/usr/bin/ar`
136         tc-export AR BUILD_CC
137         export ac_cv_path_AR=${AR}
138
139         # this is tested for by the bind build system, and can cause trouble
140         # when cross-building; since dhcp itself doesn't make use of libcap,
141         # simply disable it.
142         export ac_cv_lib_cap_cap_set_proc=no
143
144         # Use FHS sane paths ... some of these have configure options,
145         # but not all, so just do it all here.
146         local e="/etc/dhcp" r="/var/run/dhcp" l="/var/lib/dhcp"
147         cat <<-EOF >> includes/site.h
148         #define _PATH_DHCPD_CONF     "${e}/dhcpd.conf"
149         #define _PATH_DHCLIENT_CONF  "${e}/dhclient.conf"
150         #define _PATH_DHCPD_DB       "${l}/dhcpd.leases"
151         #define _PATH_DHCPD6_DB      "${l}/dhcpd6.leases"
152         #define _PATH_DHCLIENT_DB    "${l}/dhclient.leases"
153         #define _PATH_DHCLIENT6_DB   "${l}/dhclient6.leases"
154         #define _PATH_DHCPD_PID      "${r}/dhcpd.pid"
155         #define _PATH_DHCPD6_PID     "${r}/dhcpd6.pid"
156         #define _PATH_DHCLIENT_PID   "${r}/dhcpclient.pid"
157         #define _PATH_DHCLIENT6_PID  "${r}/dhcpclient6.pid"
158         #define _PATH_DHCRELAY_PID   "${r}/dhcrelay.pid"
159         #define _PATH_DHCRELAY6_PID  "${r}/dhcrelay6.pid"
160         EOF
161
162         econf \
163                 --enable-paranoia \
164                 --enable-early-chroot \
165                 --sysconfdir=${e} \
166                 $(use_enable ipv6 dhcpv6) \
167                 $(use_with ldap) \
168                 $(use ldap && use_with ssl ldapcrypto || echo --without-ldapcrypto)
169
170         # configure local bind cruft.  symtable option requires
171         # perl and we don't want to require that #383837.
172         cd bind/bind-*/ || die
173         eval econf \
174                 $(sed -n '/^bindconfig =/,/^$/{:a;N;$!ba;s,^[^-]*,,;s,\\\s*\n\s*--,--,g;s, @[[:upper:]]\+@,,g;P;D}' ../Makefile.in) \
175                 --disable-symtable \
176                 --without-make-clean
177 }
178
179 src_compile() {
180         # build local bind cruft first
181         emake -C bind/bind-*/lib/export install
182         # then build standard dhcp code
183         emake AR="$(tc-getAR)"
184 }
185
186 src_install() {
187         default
188
189         dodoc README RELNOTES doc/{api+protocol,IANA-arp-parameters}
190         dohtml doc/References.html
191
192         if [[ -e client/dhclient ]] ; then
193                 # move the client to /
194                 dodir /sbin
195                 mv "${D}"/usr/sbin/dhclient "${D}"/sbin/ || die
196
197                 exeinto /sbin
198                 if use kernel_linux ; then
199                         newexe "${S}"/client/scripts/linux dhclient-script
200                 else
201                         newexe "${S}"/client/scripts/freebsd dhclient-script
202                 fi
203         fi
204
205         if [[ -e server/dhcpd ]] ; then
206                 if use ldap ; then
207                         insinto /etc/openldap/schema
208                         doins contrib/ldap/dhcp.*
209                         dosbin contrib/ldap/dhcpd-conf-to-ldap
210                 fi
211
212                 newinitd "${FILESDIR}"/dhcpd.init5 dhcpd
213                 newconfd "${FILESDIR}"/dhcpd.conf2 dhcpd
214                 newinitd "${FILESDIR}"/dhcrelay.init3 dhcrelay
215                 newconfd "${FILESDIR}"/dhcrelay.conf dhcrelay
216                 newinitd "${FILESDIR}"/dhcrelay.init3 dhcrelay6
217                 newconfd "${FILESDIR}"/dhcrelay6.conf dhcrelay6
218
219                 systemd_newtmpfilesd "${FILESDIR}"/dhcpd.tmpfiles dhcpd.conf
220                 systemd_dounit "${FILESDIR}"/dhcpd4.service
221                 systemd_dounit "${FILESDIR}"/dhcpd6.service
222                 systemd_dounit "${FILESDIR}"/dhcrelay4.service
223                 systemd_dounit "${FILESDIR}"/dhcrelay6.service
224                 systemd_install_serviced "${FILESDIR}"/dhcrelay4.service.conf
225                 systemd_install_serviced "${FILESDIR}"/dhcrelay6.service.conf
226
227                 sed -i "s:#@slapd@:$(usex ldap slapd ''):" "${ED}"/etc/init.d/* || die #442560
228         fi
229
230         # the default config files aren't terribly useful #384087
231         local f
232         for f in "${ED}"/etc/dhcp/*.conf.example ; do
233                 mv "${f}" "${f%.example}" || die
234         done
235         sed -i '/^[^#]/s:^:#:' "${ED}"/etc/dhcp/*.conf || die
236 }
237
238 pkg_preinst() {
239         enewgroup dhcp
240         enewuser dhcp -1 -1 /var/lib/dhcp dhcp
241
242         # Keep the user files over the sample ones.  The
243         # hashing is to ignore the crappy defaults #384087.
244         local f h
245         for f in dhclient:da7c8496a96452190aecf9afceef4510 dhcpd:10979e7b71134bd7f04d2a60bd58f070 ; do
246                 h=${f#*:}
247                 f="/etc/dhcp/${f%:*}.conf"
248                 if [ -e "${EROOT}"${f} ] ; then
249                         case $(md5sum "${EROOT}"${f}) in
250                                 ${h}*) ;;
251                                 *) cp -p "${EROOT}"${f} "${ED}"${f};;
252                         esac
253                 fi
254         done
255 }
256
257 pkg_postinst() {
258         if [[ -e "${ROOT}"/etc/init.d/dhcp ]] ; then
259                 ewarn
260                 ewarn "WARNING: The dhcp init script has been renamed to dhcpd"
261                 ewarn "/etc/init.d/dhcp and /etc/conf.d/dhcp need to be removed and"
262                 ewarn "and dhcp should be removed from the default runlevel"
263                 ewarn
264         fi
265 }