*/*: Bump copyright on files touched this year
[gentoo.git] / net-misc / openntpd / openntpd-6.0_p1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5 inherit eutils systemd user
6
7 MY_P="${P/_p/p}"
8 DESCRIPTION="Lightweight NTP server ported from OpenBSD"
9 HOMEPAGE="http://www.openntpd.org/"
10 SRC_URI="mirror://openbsd/OpenNTPD/${MY_P}.tar.gz"
11
12 LICENSE="BSD GPL-2"
13 SLOT="0"
14 KEYWORDS="~alpha amd64 arm arm64 hppa ia64 ~mips ppc ppc64 s390 ~sh sparc x86"
15 IUSE="libressl selinux"
16
17 DEPEND="!<=net-misc/ntp-4.2.0-r2
18         !net-misc/ntp[-openntpd]
19         libressl? ( >=dev-libs/libressl-2.3.2 )"
20 RDEPEND="${DEPEND}
21         selinux? ( sec-policy/selinux-ntp )"
22
23 S="${WORKDIR}/${MY_P}"
24
25 pkg_setup() {
26         export NTP_HOME="${NTP_HOME:=/var/lib/openntpd/chroot}"
27         enewgroup ntp
28         enewuser ntp -1 -1 "${NTP_HOME}" ntp
29
30         # make sure user has correct HOME as flipping between the standard ntp pkg
31         # and this one was possible in the past
32         if [[ $(egethome ntp) != ${NTP_HOME} ]]; then
33                 ewarn "From this version on, the homedir of the ntp user cannot be changed"
34                 ewarn "dynamically after the installation. For homedir different from"
35                 ewarn "/var/lib/openntpd/chroot set NTP_HOME in your make.conf and re-emerge."
36                 esethome ntp "${NTP_HOME}"
37         fi
38 }
39
40 src_prepare() {
41         # fix /run path
42         sed -i 's:/var/run/ntpd:/run/ntpd:g' src/ntpctl.8 src/ntpd.8 || die
43         sed -i 's:LOCALSTATEDIR "/run/ntpd:"/run/ntpd:' src/ntpd.h || die
44         # fix ntpd.drift path
45         sed -i 's:/var/db/ntpd.drift:/var/lib/openntpd/ntpd.drift:g' src/ntpd.8 || die
46         sed -i 's:"/db/ntpd.drift":"/openntpd/ntpd.drift":' src/ntpd.h || die
47         # fix default config to use gentoo pool
48         sed -i 's:servers pool.ntp.org:#servers pool.ntp.org:' ntpd.conf || die
49         printf "\n# Choose servers announced from Gentoo NTP Pool\nservers 0.gentoo.pool.ntp.org\nservers 1.gentoo.pool.ntp.org\nservers 2.gentoo.pool.ntp.org\nservers 3.gentoo.pool.ntp.org\n" >> ntpd.conf || die
50 }
51
52 src_configure() {
53         econf --with-privsep-user=ntp --with-privsep-path=${NTP_HOME} $(use_enable libressl https-constraint)
54 }
55
56 src_install() {
57         default
58         rm -r "${ED}"/var
59
60         newinitd "${FILESDIR}/${PN}.init.d-20080406-r6" ntpd
61         newconfd "${FILESDIR}/${PN}.conf.d-20080406-r6" ntpd
62         keepdir "${NTP_HOME}"
63
64         systemd_newunit "${FILESDIR}/${PN}.service-20080406-r4" ntpd.service
65 }
66
67 pkg_postinst() {
68         # Clean up chroot localtime copy from older versions
69         if [ -d "${EROOT%/}${NTP_HOME}"/etc ] ; then
70                 if [ -f "${EROOT%/}${NTP_HOME}"/etc/localtime ] ; then
71                         rm -f "${EROOT%/}${NTP_HOME}"/etc/localtime
72                 fi
73
74                 rmdir "${EROOT%/}${NTP_HOME}"/etc ||
75                         ewarn "Unable to remove legacy ${EROOT%/}${NTP_HOME}/etc directory"
76         fi
77
78         # Fix permissions on home directory
79         chown root:root "${EROOT%/}${NTP_HOME}" || die
80
81         [[ -f ${EROOT}var/log/ntpd.log ]] && \
82                 ewarn "Logfile '${EROOT}var/log/ntpd.log' might be orphaned, please remove it if not in use via syslog."
83
84         if [[ -f ${EROOT}var/lib/ntpd.drift ]] ; then
85                 einfo "Moving ntpd.drift file to new location."
86                 mv "${EROOT}var/lib/ntpd.drift" "${EROOT}var/lib/openntpd/ntpd.drift"
87         fi
88 }