beab65cedd779683749b551b41ec63ae35688563
[gentoo.git] / net-dns / pdnsd / pdnsd-1.2.9a-r2.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit systemd
7
8 DESCRIPTION="Proxy DNS server with permanent caching"
9 HOMEPAGE="http://members.home.nl/p.a.rombouts/pdnsd/"
10 SRC_URI="http://members.home.nl/p.a.rombouts/pdnsd/releases/${P}-par.tar.gz"
11
12 LICENSE="GPL-3"
13 SLOT="0"
14 KEYWORDS="~alpha ~amd64 ~arm ~ia64 ~ppc ~s390 ~sparc ~x86"
15 IUSE="debug ipv6 isdn +urandom test"
16 RESTRICT="!test? ( test )"
17
18 RDEPEND="
19         acct-group/pdnsd
20         acct-user/pdnsd
21 "
22 DEPEND="test? ( net-dns/bind-tools )"
23
24 src_configure() {
25         local myeconfargs=(
26                 --sysconfdir="${EPREFIX}"/etc/pdnsd
27                 --with-cachedir="${EPREFIX}"/var/cache/pdnsd
28                 --with-default-id=pdnsd
29                 $(use_enable ipv6)
30                 $(use_enable ipv6 ipv6-startup)
31                 $(use_enable isdn)
32                 $(usex debug '--with-debug=3' '')
33                 $(usex urandom "--with-random-device=${EPREFIX}/dev/urandom" '')
34         )
35
36         econf "${myeconfargs[@]}"
37 }
38
39 src_install() {
40         local DOCS=( AUTHORS ChangeLog* NEWS README THANKS TODO README.par )
41         default
42
43         docinto contrib
44         dodoc contrib/{README,dhcp2pdnsd,pdnsd_dhcp.pl}
45
46         docinto html
47         dodoc doc/html/*
48         docinto txt
49         dodoc doc/txt/*
50         newdoc doc/pdnsd.conf pdnsd.conf.sample
51
52         newinitd "${FILESDIR}/pdnsd.rc8" pdnsd
53         newconfd "${FILESDIR}/pdnsd.confd" pdnsd
54         newinitd "${FILESDIR}/pdnsd.online.2" pdnsd-online
55         newconfd "${FILESDIR}/pdnsd-online.confd" pdnsd-online
56         systemd_newtmpfilesd "${FILESDIR}/pdnsd.tmpfiles" pdnsd.conf
57         systemd_dounit "${FILESDIR}/pdnsd.service"
58 }
59
60 src_test() {
61         fail_kill() {
62                 kill -9 $(<"${T}"/pid)
63                 die "$1"
64         }
65
66         mkdir "${T}/pdnsd" || die
67         echo -n -e "pd12\0\0\0\0" > "${T}/pdnsd/pdnsd.cache"
68         IPS="$(grep ^nameserver /etc/resolv.conf | sed -e 's/nameserver \(.*\)/\tip=\1;/g' | xargs)"
69         sed -e "s/\tip=/${IPS}/" -e "s:cache_dir=:cache_dir=${T}/pdnsd:" "${FILESDIR}/pdnsd.conf.test" \
70                 > "${T}/pdnsd.conf.test"
71         src/pdnsd -c "${T}/pdnsd.conf.test" -g -s -d -p "${T}/pid" || die "couldn't start daemon"
72         sleep 3
73
74         find "${T}" -ls
75         [ -s "${T}/pid" ] || die "empty or no pid file created"
76         [ -S "${T}/pdnsd/pdnsd.status" ] || fail_kill "no socket created"
77         src/pdnsd-ctl/pdnsd-ctl -c "${T}/pdnsd" server all up || fail_kill "failed to start the daemon"
78         src/pdnsd-ctl/pdnsd-ctl -c "${T}/pdnsd" status || fail_kill "failed to communicate with the daemon"
79         sleep 3
80
81         dig @127.0.0.1 -p 33455 localhost > "${T}"/dig.output 2>&1
82         cat "${T}"/dig.output || die
83         fgrep -q "status: NOERROR" "${T}"/dig.output || fail_kill "www.gentoo.org lookup failed"
84
85         kill $(<"${T}/pid") || fail_kill "failed to terminate daemon"
86 }
87
88 pkg_postinst() {
89         elog
90         elog "Add pdnsd to your default runlevel - rc-update add pdnsd default"
91         elog ""
92         elog "Add pdnsd-online to your online runlevel."
93         elog "The online interface will be listed in /etc/conf.d/pdnsd-online"
94         elog ""
95         elog "Sample config file in /etc/pdnsd/pdnsd.conf.sample"
96
97         # The tmpfiles.d configuration does not come into effect before the
98         # next reboot so create the cachedir now.
99         local cachedir="${EPREFIX}/var/cache/pdnsd"
100         if [[ ! -d "${cachedir}" ]] ; then
101                 mkdir "${cachedir}" || eerror "Failed to create cache"
102         fi
103         chown pdnsd:pdnsd "${cachedir}" \
104                 || eerror "Failed to set ownership for cachedir"
105         chmod 0750 "${cachedir}" \
106                 || eerror "Failed to set permissions for cachedir"
107 }