0f2889cf8bae3b4c199255a89b69ed68eaa11e4d
[gentoo.git] / net-misc / ntp / ntp-4.2.8_p13-r1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit autotools toolchain-funcs flag-o-matic user systemd
7
8 MY_P=${P/_p/p}
9 DESCRIPTION="Network Time Protocol suite/programs"
10 HOMEPAGE="http://www.ntp.org/"
11 SRC_URI="http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-${PV:0:3}/${MY_P}.tar.gz
12         https://dev.gentoo.org/~polynomial-c/${MY_P}-manpages.tar.xz"
13
14 LICENSE="HPND BSD ISC"
15 SLOT="0"
16 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~amd64-linux ~x86-linux ~m68k-mint"
17 IUSE="caps debug ipv6 libressl openntpd parse-clocks readline samba selinux snmp ssl +threads vim-syntax zeroconf"
18
19 CDEPEND="readline? ( >=sys-libs/readline-4.1:0= )
20         >=dev-libs/libevent-2.0.9:=[threads?]
21         kernel_linux? ( caps? ( sys-libs/libcap ) )
22         zeroconf? ( net-dns/avahi[mdnsresponder-compat] )
23         snmp? ( net-analyzer/net-snmp )
24         ssl? (
25                 !libressl? ( dev-libs/openssl:0= )
26                 libressl? ( dev-libs/libressl:0= )
27         )
28         parse-clocks? ( net-misc/pps-tools )"
29 DEPEND="${CDEPEND}
30         virtual/pkgconfig"
31 RDEPEND="${CDEPEND}
32         selinux? ( sec-policy/selinux-ntp )
33         vim-syntax? ( app-vim/ntp-syntax )
34         !net-misc/ntpsec
35         !openntpd? ( !net-misc/openntpd )
36 "
37 PDEPEND="openntpd? ( net-misc/openntpd )"
38
39 S="${WORKDIR}/${MY_P}"
40
41 PATCHES=(
42         "${FILESDIR}"/${PN}-4.2.8-ipc-caps.patch #533966
43         "${FILESDIR}"/${PN}-4.2.8-sntp-test-pthreads.patch #563922
44         "${FILESDIR}"/${PN}-4.2.8_p10-fix-build-wo-ssl-or-libressl.patch
45         "${FILESDIR}"/${PN}-4.2.8_p12-libressl-2.8.patch
46 )
47
48 pkg_setup() {
49         enewgroup ntp 123
50         enewuser ntp 123 -1 /dev/null ntp
51 }
52
53 src_prepare() {
54         default
55         append-cppflags -D_GNU_SOURCE #264109
56         # Make sure every build uses the same install layout. #539092
57         find sntp/loc/ -type f '!' -name legacy -delete || die
58         eautoreconf #622754
59         # Disable pointless checks.
60         touch .checkChangeLog .gcc-warning FRC.html html/.datecheck
61 }
62
63 src_configure() {
64         # avoid libmd5/libelf
65         export ac_cv_search_MD5Init=no ac_cv_header_md5_h=no
66         export ac_cv_lib_elf_nlist=no
67         # blah, no real configure options #176333
68         export ac_cv_header_dns_sd_h=$(usex zeroconf)
69         export ac_cv_lib_dns_sd_DNSServiceRegister=${ac_cv_header_dns_sd_h}
70         # Increase the default memlimit from 32MiB to 128MiB.  #533232
71         local myeconfargs=(
72                 --with-lineeditlibs=readline,edit,editline
73                 --with-yielding-select
74                 --disable-local-libevent
75                 --docdir='$(datarootdir)'/doc/${PF}
76                 --htmldir='$(docdir)/html'
77                 --with-memlock=256
78                 $(use_enable caps linuxcaps)
79                 $(use_enable parse-clocks)
80                 $(use_enable ipv6)
81                 $(use_enable debug debugging)
82                 $(use_with readline lineeditlibs readline)
83                 $(use_enable samba ntp-signd)
84                 $(use_with snmp ntpsnmpd)
85                 $(use_with ssl crypto)
86                 $(use_enable threads thread-support)
87         )
88         econf "${myeconfargs[@]}"
89 }
90
91 src_install() {
92         default
93         # move ntpd/ntpdate to sbin #66671
94         dodir /usr/sbin
95         mv "${ED%/}"/usr/bin/{ntpd,ntpdate} "${ED%/}"/usr/sbin/ || die "move to sbin"
96
97         dodoc INSTALL WHERE-TO-START
98         doman "${WORKDIR}"/man/*.[58]
99
100         insinto /etc
101         doins "${FILESDIR}"/ntp.conf
102         use ipv6 || sed -i '/^restrict .*::1/d' "${ED%/}"/etc/ntp.conf #524726
103         newinitd "${FILESDIR}"/ntpd.rc-r1 ntpd
104         newconfd "${FILESDIR}"/ntpd.confd ntpd
105         newinitd "${FILESDIR}"/ntp-client.rc ntp-client
106         newconfd "${FILESDIR}"/ntp-client.confd ntp-client
107         newinitd "${FILESDIR}"/sntp.rc sntp
108         newconfd "${FILESDIR}"/sntp.confd sntp
109         if ! use caps ; then
110                 sed -i "s|-u ntp:ntp||" "${ED%/}"/etc/conf.d/ntpd || die
111         fi
112         sed -i "s:/usr/bin:/usr/sbin:" "${ED%/}"/etc/init.d/ntpd || die
113
114         keepdir /var/lib/ntp
115         use prefix || fowners ntp:ntp /var/lib/ntp
116
117         if use openntpd ; then
118                 cd "${ED}" || die
119                 rm usr/sbin/ntpd || die
120                 rm -r var/lib || die
121                 rm etc/{conf,init}.d/ntpd || die
122                 rm usr/share/man/*/ntpd.8 || die
123         else
124                 systemd_newunit "${FILESDIR}"/ntpd.service-r2 ntpd.service
125                 if use caps ; then
126                         sed -i '/ExecStart/ s|$| -u ntp:ntp|' \
127                                 "${D%/}$(systemd_get_systemunitdir)"/ntpd.service \
128                                 || die
129                 fi
130                 systemd_enable_ntpunit 60-ntpd ntpd.service
131         fi
132
133         systemd_newunit "${FILESDIR}"/ntpdate.service-r2 ntpdate.service
134         systemd_install_serviced "${FILESDIR}"/ntpdate.service.conf
135         systemd_newunit "${FILESDIR}"/sntp.service-r3 sntp.service
136         systemd_install_serviced "${FILESDIR}"/sntp.service.conf
137 }
138
139 pkg_postinst() {
140         if grep -qs '^[^#].*notrust' "${EROOT}"/etc/ntp.conf ; then
141                 eerror "The notrust option was found in your /etc/ntp.conf!"
142                 ewarn "If your ntpd starts sending out weird responses,"
143                 ewarn "then make sure you have keys properly setup and see"
144                 ewarn "https://bugs.gentoo.org/41827"
145         fi
146 }