File chrony.spec of Package chrony

%define realname chrony
%define realver  3.5
%define srcext   tar.gz

%if 0%{?suse_version} >= 1230 || 0%{?rhel} >= 7
%bcond_without systemd
%else
%bcond_with systemd
%endif

# turn off the generation of debuginfo rpm  (RH9) ??
%global debug_package %{nil}

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       GPL-2.0
Group:         Productivity/Networking/Other
URL:           http://chrony.tuxfamily.org/
Summary:       A software package for maintaining the accuracy of computer system clocks

# Use systemd on systems supporting it
%if %{with systemd}
Requires:      systemd
BuildRequires: systemd-devel
%endif

# Install-time parameters
Provides:      ntp-daemon

# Build-time parameters
BuildRequires: pkg-config
%if 0%{?suse_version} >= 1310
BuildRequires: makeinfo
%endif
%if 0%{?suse_version} >= 1310 || 0%{?rhel} >= 7
BuildRequires: libseccomp-devel
%endif
BuildRequires: readline-devel ncurses-devel libcap-devel
BuildRequires: pkgconfig(nettle)
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       http://download.tuxfamily.org/chrony/%{realname}-%{realver}%{?extraver}.%{srcext}
Source11:      chronyd.init
Source12:      chronyd.service

%description
Chrony is a pair of programs which are used to maintain the accuracy of the
system clock on a computer. The two programs are called chronyd and chronyc.

Chronyd is a daemon which runs in background on the system. It obtains
measurements via the network of the system clocks offset relative to time
servers on other systems and adjusts the system time accordingly. For isolated
systems, the user can periodically enter the correct time by hand
(using Chronyc). In either case, Chronyd determines the rate at which the
computer gains or loses time, and compensates for this. Chronyd implements
the NTP protocol and can act as either a client or a server.

Chronyc provides a user interface to Chronyd for monitoring its performance
and configuring various settings. It can do so while running on the same
computer as the Chronyd instance it is controlling or a different computer.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}

%build
export CFLAGS="%{optflags} $(pkg-config --cflags libseccomp) %{?gcc_lto} -fPIE"
export LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,-z,now -Wl,-z,relro %{?gcc_lto} -pie"
./configure \
 --prefix=%{_prefix} \
 --disable-static \
%if 0%{?suse_version} >= 1310 || 0%{?rhel} >= 7
 --enable-scfilter \
%endif
 --with-user=ntp \
%if 0%{?_rundir:1}
 --with-pidfile=%{_rundir}/chrony/chronyd.pid \
 --chronyrundir=%{_rundir}/chrony \
%endif
%if 0%{?suse_version}
 --docdir=%{_defaultdocdir}/%{name}
%else
 --docdir=%{_defaultdocdir}/%{name}-%{version}
%endif
%{__make} %{?_smp_mflags}

%install
%{__make} install DESTDIR=%{buildroot}
# Install default config file
%{__install} -D -m644 examples/chrony.conf.example2 %{buildroot}%{_sysconfdir}/chrony.conf
echo "1 password" > %{buildroot}%{_sysconfdir}/chrony.keys
# Create required directories
%{__install} -d -m755 %{buildroot}/var/log/chrony
%{__install} -d -m755 %{buildroot}/var/lib/chrony
# Install logrotate config
%{__install} -D -m644 examples/chrony.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/chrony
# NetworkManager dispatcher
%if 0%{?suse_version} >= 1230 || 0%{?rhel} >= 7
%{__install} -D -m755 examples/chrony.nm-dispatcher %{buildroot}%{_sysconfdir}/NetworkManager/dispatcher.d/chrony
%endif
# Install init script(s)/unit file(s)
%if 0%{?_unitdir:1}
%{__install} -D -m644 %{S:12} %{buildroot}%{_unitdir}/chronyd.service
%{__install} -d -m750 %{buildroot}%{_tmpfilesdir}
echo 'd %{_rundir}/chrony 0750 ntp ntp' > %{buildroot}%{_tmpfilesdir}/chrony.conf
%else
%{__install} -D -m755 %{S:11} %{buildroot}%{_initrddir}/chronyd
%{__install} -d -m750 %{buildroot}/var/run/chrony
# Create SUSE-specific rc-script symlink(s)
%if "%{expand:%_vendor}" == "suse"
[ -x %{buildroot}%{_initrddir}/chronyd ] && %{__ln_s} %{_initrddir}/chronyd %{buildroot}%{_sbindir}/rcchronyd
%endif
%endif

%clean
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}

%files
%defattr(-,root,root)
%doc COPYING FAQ NEWS README
%config(noreplace) %{_sysconfdir}/chrony.conf
%config(noreplace) %attr(0640,ntp,ntp) %{_sysconfdir}/chrony.keys
%config(noreplace) %{_sysconfdir}/logrotate.d/chrony
%if 0%{?_unitdir:1}
%{_unitdir}/chronyd.service
%{_tmpfilesdir}/chrony.conf
%dir %ghost %{_rundir}/chrony
%else
%{_initrddir}/chronyd
%dir %attr(0750,ntp,ntp) /var/run/chrony
%endif
%if 0%{?suse_version} >= 1230 || 0%{?rhel} >= 7
%dir %{_sysconfdir}/NetworkManager/dispatcher.d
%dir %{_sysconfdir}/NetworkManager
%{_sysconfdir}/NetworkManager/dispatcher.d/chrony
%endif
%{_bindir}/chronyc
%{_sbindir}/*
%dir %attr(0755,ntp,ntp) /var/log/chrony
%dir %attr(0755,ntp,ntp) /var/lib/chrony
%doc %{_mandir}/man1/*
%doc %{_mandir}/man5/*
%doc %{_mandir}/man8/*

%if "%{expand:%_vendor}" == "suse"

%if 0%{?_unitdir:1}

%pre
/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 || :
%{service_add_pre chronyd.service}

%post
%{fillup_only chronyd}
%{tmpfiles_create %{_tmpfilesdir}/chrony.conf}
%{service_add_post chronyd.service}

%preun
%{service_del_preun chronyd.service}

%postun
%{service_del_postun chronyd.service}

%else

%pre
/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 || :

%post
%{fillup_and_insserv chronyd}

%preun
%{stop_on_removal chronyd}

%postun
%{restart_on_update chronyd}
%{insserv_cleanup}

%endif

%else

%pre
/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 || :

%endif

%changelog
openSUSE Build Service is sponsored by