File ntp.spec of Package ntp.10574

# spec file for package ntp
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

Name:           ntp
%if 0%{?suse_version} > 1010
BuildRequires:  autoconf
BuildRequires:  fdupes
BuildRequires:  libcap-devel
BuildRequires:  libtool
BuildRequires:  openssl-devel
BuildRequires:  readline-devel
# to allow the postinst script to succeed
BuildRequires:  pwdutils
%if 0%{?suse_version} >= 1140
BuildRequires:  pkgconfig(systemd)
%if %{undefined _ntpunitsdir}
%global _ntpunitsdir /usr/lib/systemd/ntp-units.d

%define ntpfaqversion 3.4
Version:        4.2.8p13
Release:        0
Summary:        Network Time Protocol daemon (version 4)
# main source
License:        (MIT AND BSD-3-Clause AND BSD-4-Clause) AND GPL-2.0-only
Group:          Productivity/Networking/Other
# configuration
Source1:        conf.logrotate.ntp
Source2:        conf.ntp.conf
Source3:        conf.ntpd.service
Source4:        conf.sysconfig.ntp
Source5:        conf.sysconfig.syslog-ntp
Source6:        conf.ntp.reg
Source7:        %name.firewall
Source8:        conf.start-ntpd
Source9:        conf.ntp-wait.service
# documentation
Source10:       NTP-FAQ-%{ntpfaqversion}.tar.bz2
Source12:       README.SUSE
Source13:       ntptime.8.gz
Source14:       ntp.xml
Patch16:        MOD_NANO.diff
Patch18:        bnc#574885.diff
Patch19:        ntp-ENOBUFS.patch
Patch20:        ntp-sntp-dst.patch
Patch21:        ntp-speedup-ntpq.patch
Patch24:        ntp-daemonize.patch
Patch27:        ntp-netlink.patch
Patch29:        ntp-pathfind.patch
Patch30:        ntp-move-kod-file.patch
Patch33:        ntp-sntp-libevent.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Provides:       ntp-daemon
Provides:       xntp = %version
Provides:       xntp3 = %version
Obsoletes:      xntp < %version
Obsoletes:      xntp3 < %version
Conflicts:      openntpd
PreReq:         pwdutils %fillup_prereq /usr/bin/diff /usr/bin/grep /sbin/chkconfig
Suggests:       logrotate
Requires:       timezone

The Network Time Protocol (NTP) is used to synchronize the time of a
computer client or server to another server or reference time source,
such as a radio, satellite receiver, or modem.

Ntpd is an operating system daemon that sets and maintains the system
time-of-day synchronized with Internet standard time servers.

%package doc
Provides:       ntpdoc = %version
Provides:       xntp-doc = %version
Provides:       xntpdoc = %version
Obsoletes:      ntpdoc < %version
Obsoletes:      xntp-doc < %version
Obsoletes:      xntpdoc < %version
Summary:        Additional Package Documentation for ntp
Group:          Documentation/Other

%description doc
The complete set of documentation for building and configuring an NTP
server or client. The documentation is in the form of HTML files
suitable for browsing and contains links to additional documentation at
various web sites.

What about NTP? Understanding and using the Network Time Protocol (A
first try on a non-technical Mini-HOWTO and FAQ on NTP). Edited by
Ulrich Windl and David Dalton.

%setup -q -n ntp-%{version}
# unpack ntp-faq
tar -x -C html -j -f %{S:10}
cp %{S:12} .
%patch19 -p1
%patch20 -p1

# fix DOS line breaks
sed -i 's/\r//g' html/scripts/{footer.txt,style.css}
# new automake 1.13 has removed old macro

%if 0%{?suse_version} && 0%{?suse_version} < 1141
%if 0%{?suse_version} > 1010
autoreconf -fi
export RPM_OPT_FLAGS="$RPM_OPT_FLAGS -W -DOPENSSL_LOAD_CONF -Wall -Wstrict-prototypes -Wpointer-arith -Wno-unused-parameter -fno-strict-aliasing -fstack-protector"
%ifarch alpha s390x
%ifarch ia64
export LDFLAGS="-pie"
%configure \
	--with-binsubdir=bin \
	--bindir=%{_sbindir} \
	--docdir=%{_docdir}/%{name}-doc \
	--enable-parse-clocks \
	--enable-all-clocks \
	--enable-linuxcaps \
	--enable-ipv6 \
	--with-sntp \
	--enable-ntp-signd \
	--disable-listen-read-drop \
	--with-lineeditlibs=readline \
	--with-crypto=openssl \
	--with-openssl-libdir=%{_libdir} \
	--with-openssl-incdir=%{_includedir} \
	--disable-thread-support \
	--without-threads \
	--enable-leap-smear \

make %{?_smp_mflags}

# Change permissions
chmod 644 html/pic/neoclock4x.gif
%if 0%{?suse_version} > 1010
%fdupes -s html
# default configuration
%__install -d %{buildroot}/var/lib/ntp/{drift,etc,var/{lib,run/ntp},dev}
%__install -d %{buildroot}/var/run
ln -s ../.. %{buildroot}/var/lib/ntp/var/lib/ntp
ln -s /usr/sbin/service %buildroot/usr/sbin/rcntpd
ln -s /usr/sbin/service %buildroot/usr/sbin/rcntp-wait
%__install -m 644 -D %{S:1} %{buildroot}/etc/logrotate.d/ntp
%__install -m 600 -D %{S:2} %{buildroot}/etc/ntp.conf
%__install -m 600 -D %{S:2} %{buildroot}/var/lib/ntp/etc/ntp.conf.iburst
# boot scripts
%__install -m 0644 -D %{S:3} %{buildroot}/%{_unitdir}/ntpd.service
%__install -m 0644 -D %{S:9} %{buildroot}/%{_unitdir}/ntp-wait.service
%__install -d %{buildroot}/usr/sbin
%__install -m 755 -D %{S:8} %{buildroot}/usr/sbin/start-ntpd
%__install -d %{buildroot}/usr/lib/initscripts/legacy-actions/ntpd
for f in ntptimeset addserver; do
	cat >$F <<-EOF
		exec /usr/sbin/start-ntpd $f "\$@"
	chmod 755 $F
# fillup sysconfig.ntp
%__install -m 644 -D %{S:4} %{buildroot}/var/adm/fillup-templates/sysconfig.ntp
%__install -m 644 -D %{S:5} %{buildroot}/var/adm/fillup-templates/sysconfig.syslog-ntp
# install SLP reg file
%__install -m 644 -D %{S:6} %{buildroot}/etc/slp.reg.d/ntp.reg
# man pages
%__install -m 644 %{S:13} %{buildroot}/%{_mandir}/man8
# firewall
%__install -d %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/
%__install -m 644 %{S:7} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
# Logfile
%__install -d %{buildroot}/var/log/
touch %{buildroot}/var/log/ntp
# service xml
install -d %{buildroot}/usr/share/omc/svcinfo.d/
install -m 644 %{S:14} %{buildroot}/usr/share/omc/svcinfo.d/
install -m 755 scripts/ntp-wait/ntp-wait %{buildroot}/usr/sbin/
install -d %{buildroot}/var/lib
install -m 644 /dev/null %{buildroot}/var/lib/ntp/kod

%if %{defined _ntpunitsdir}
%__install -d %{buildroot}%{_ntpunitsdir}
echo ntpd.service > %{buildroot}%{_ntpunitsdir}/50-ntp.list

%__rm -rf %{buildroot}

/usr/sbin/groupadd -r ntp 2> /dev/null || :
/usr/sbin/useradd -r -o -g ntp -u 74 -s /bin/false -c "NTP daemon" -d /var/lib/ntp ntp 2> /dev/null || :
/usr/sbin/usermod -g ntp ntp 2>/dev/null || :
test -L /var/run/ntp  || rm -rf /var/run/ntp && :
%service_add_pre ntp.service ntpd.service
%service_add_pre ntp-wait.service
if [ $FIRST_ARG -ne 1 -a ! -e "/var/lib/systemd/migrated/ntpd" -a -e /var/lib/systemd/sysv-convert/database ]; then
  sed -i -e 's,ntp\t,ntpd\t,g' /var/lib/systemd/sysv-convert/database

%service_del_preun ntpd.service
%service_del_preun ntp-wait.service

# no update? Then remove these files that aren't owned by the package
if [ ${FIRST_ARG:-0} -eq 0 ]; then
     test -e /var/lib/ntp/drift/ntp.drift  && rm -f /var/lib/ntp/drift/ntp.drift
     rm -f /var/lib/ntp/etc/* 2>/dev/null
     test -e /var/log/ntp  && rm -f /var/log/ntp

# Create ntp.keys file
if [ ! -f /etc/ntp.keys ]; then
  FILE=$(mktemp -p /etc)
  chmod 0640 $FILE
  chown root:ntp $FILE
  mv $FILE /etc/ntp.keys
# Make sure we have a key with ID 1, because it is needed
# by the startup scripts.
if awk '$1 == "1" {exit 1}' /etc/ntp.keys; then
  KEY=$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20)
  echo "1 SHA1 $KEY" >> /etc/ntp.keys
# Are we in update mode?
if [ -f /etc/sysconfig/ntp ]; then
	grep -q '^keys /etc/ntp.keys' /etc/ntp.conf || {
        echo "#
# Authentication stuff
keys /etc/ntp.keys              # path for keys file
trustedkey 1                    # define trusted keys
requestkey 1                    # key (7) for accessing server variables
" >> /etc/ntp.conf
if [ -f /etc/sysconfig/ntp ]; then
	grep -q '^controlkey ' /etc/ntp.conf || {
	echo "#
controlkey 1                    # key (6) for accessing server variables
	 " >> /etc/ntp.conf
# update from previous permissions
if [ -f /etc/ntp.conf ]; then
  chown root:ntp /etc/ntp.conf
if [ -f /etc/ntp.keys ]; then
  chown root:ntp /etc/ntp.keys
if [ -f /var/lib/ntp/etc/ntp.conf.iburst ]; then
  chown --from=ntp:root root:ntp /var/lib/ntp/etc/ntp.conf.iburst
%{fillup_only -n ntp }
%{fillup_only -n syslog }
if [ ! -f /var/log/ntp ]; then
	touch /var/log/ntp
	chmod 644 /var/log/ntp
%service_add_post ntpd.service
%service_add_post ntp-wait.service
if [ ! -e "/var/lib/systemd/migrated/ntpd" ]; then
  touch /var/lib/systemd/migrated/ntpd

%service_del_postun ntpd.service
%service_del_postun ntp-wait.service

%attr(0640,root,ntp) %config(noreplace) %{_sysconfdir}/ntp.conf
%dir %{_sysconfdir}/slp.reg.d
%if %{defined _ntpunitsdir}
%config(noreplace) %{_sysconfdir}/slp.reg.d/ntp.reg
%config %{_sysconfdir}/logrotate.d/ntp
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/ntp
%attr(0640,root,ntp) %config(noreplace) /var/lib/ntp/etc/ntp.conf.iburst
%attr(0755,ntp,ntp) %dir /var/lib/ntp/drift
%attr(0755,ntp,root) /var/lib/ntp/var/run/ntp
%ghost %config(noreplace) /var/log/ntp

%files doc
%doc	%{_docdir}/%{name}-doc

openSUSE Build Service is sponsored by