## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Generated by rust2rpm 26
%bcond_without check

Name:           ntpd-rs
Version:        1.3.0
Release:        %autorelease
Summary:        Full-featured implementation of NTP with NTS support

SourceLicense:  Apache-2.0 OR MIT
# Apache-2.0 OR BSL-1.0
# Apache-2.0 OR ISC OR MIT
# Apache-2.0 OR MIT
# BSD-3-Clause
# ISC
# ISC AND MIT AND OpenSSL
# MIT
# MIT OR Apache-2.0
License:        BSD-3-Clause AND ISC AND MIT AND OpenSSL AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR ISC OR MIT) AND (Apache-2.0 OR MIT)

URL:            https://github.com/pendulum-project/ntpd-rs
Source0:        %{url}/archive/v%{version}/ntpd-rs-%{version}.tar.gz

# sysusers.d configuration
Source1:        ntpd-rs.sysusers
# tmpfiles.d configuration
Source2:        ntpd-rs.tmpfiles

# move default ntpd-rs-observe socket from obsolete /var/run to /run
Patch:          0001-Move-default-socket-path-from-var-run-to-run.patch

# use correct names for conflicting with ntpd.service and chronyd.service
Patch:          0002-Fix-names-of-conflicting-systemd-services.patch

BuildRequires:  cargo-rpm-macros >= 24
BuildRequires:  systemd-rpm-macros

Requires(pre):  systemd-sysusers
Requires(pre):  systemd-tmpfiles

%global _description %{expand:
Full-featured implementation of NTP with NTS support.}

%description %{_description}

%prep
%autosetup -p1
%cargo_prep

%generate_buildrequires
%cargo_generate_buildrequires

%build
%cargo_build
%{cargo_license_summary}
%{cargo_license} > LICENSE.dependencies

%install
# install binaries
install -Dpm0755 target/rpm/ntp-ctl -t %{buildroot}/%{_bindir}
install -Dpm0755 target/rpm/ntp-daemon -t %{buildroot}/%{_bindir}
install -Dpm0755 target/rpm/ntp-metrics-exporter -t %{buildroot}/%{_bindir}

# install manual pages
install -Dpm0644 docs/precompiled/man/*.5 -t %{buildroot}/%{_mandir}/man5
install -Dpm0644 docs/precompiled/man/*.8 -t %{buildroot}/%{_mandir}/man8

# install default ntpd-rs configuration file
install -Dpm0644 docs/examples/conf/ntp.toml.default -t %{buildroot}/%{_pkgdocdir}/
install -Dpm0644 docs/examples/conf/ntp.toml.default %{buildroot}/%{_sysconfdir}/ntpd-rs/ntp.toml

# install systemd services
install -Dpm0644 docs/examples/conf/ntpd-rs.service -t %{buildroot}/%{_unitdir}
install -Dpm0644 docs/examples/conf/ntpd-rs-metrics.service -t %{buildroot}/%{_unitdir}

# install sysusers.d configuration
install -Dpm0644 %{SOURCE1} %{buildroot}/%{_sysusersdir}/ntpd-rs.conf
# install tmpfiles.d configuration
install -Dpm0644 %{SOURCE2} %{buildroot}/%{_tmpfilesdir}/ntpd-rs.conf

# create runtime directories
mkdir -p %{buildroot}/%{_sharedstatedir}/ntpd-rs
mkdir -p %{buildroot}/%{_sharedstatedir}/ntpd-rs-observe
mkdir -p %{buildroot}/%{_rundir}/ntpd-rs

%if %{with check}
%check
# * limit parallelism to avoid tests failing due to resource limits or timeouts
# * skip tests that fails to panic in release mode
# * skip tests that fails in containerized environments
%cargo_test -- -- --test-threads 2 --skip algorithm::kalman::peer::tests::test_offset_steering_and_measurements --skip hwtimestamp::tests::get_hwtimestamp --skip socket::tests::test_send_timestamp --skip daemon::ntp_source::tests::test_deny_stops_poll --skip daemon::ntp_source::tests::test_timeroundtrip
%endif

%pre
%sysusers_create_package ntpd-rs %{SOURCE1}
%tmpfiles_create_package ntpd-rs %{SOURCE2}

%post
%systemd_post ntpd-rs.service

%preun
%systemd_preun ntpd-rs.service

%postun
%systemd_postun_with_restart ntpd-rs.service

%files
%license COPYRIGHT
%license LICENSE-APACHE
%license LICENSE-MIT
%license LICENSE.dependencies

%doc CHANGELOG.md
%doc README.md
%doc SECURITY.md

%dir %{_sysconfdir}/ntpd-rs
%config(noreplace) %{_sysconfdir}/ntpd-rs/ntp.toml

%{_bindir}/ntp-ctl
%{_bindir}/ntp-daemon
%{_bindir}/ntp-metrics-exporter

%{_mandir}/man5/ntp.toml.5*
%{_mandir}/man8/ntp-{ctl,daemon,metrics-exporter}.8*

%{_unitdir}/ntpd-rs.service
%{_unitdir}/ntpd-rs-metrics.service
%{_sysusersdir}/ntpd-rs.conf
%{_tmpfilesdir}/ntpd-rs.conf
%{_pkgdocdir}/ntp.toml.default

%ghost %dir %attr(0700, ntpd-rs, ntpd-rs) %{_sharedstatedir}/ntpd-rs
%ghost %dir %attr(0700, ntpd-rs-observe, ntpd-rs-observe) %{_sharedstatedir}/ntpd-rs-observe
%ghost %dir %attr(0700, ntpd-rs-observe, ntpd-rs-observe) %{_rundir}/ntpd-rs

%changelog
## START: Generated by rpmautospec
* Sun Oct 20 2024 Fabio Valentini <decathorpe@gmail.com> - 1.3.0-2
- Limit parallelism to avoid tests failing due to resource limits or
  timeouts

* Sun Oct 20 2024 Fabio Valentini <decathorpe@gmail.com> - 1.3.0-1
- Update to version 1.3.0; Fixes RHBZ#2298814

* Thu Jul 18 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Tue Jul 16 2024 Fabio Valentini <decathorpe@gmail.com> - 1.2.0-1
- Update to version 1.2.0; Fixes RHBZ#2295635

* Thu May 23 2024 Fabio Valentini <decathorpe@gmail.com> - 1.1.2-2
- Rebuild with Rust 1.78 to fix incomplete debuginfo and backtraces

* Thu Mar 14 2024 Fabio Valentini <decathorpe@gmail.com> - 1.1.2-1
- Update to version 1.1.2; Fixes RHBZ#2260296

* Thu Jan 25 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sun Jan 21 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sat Jan 06 2024 Fabio Valentini <decathorpe@gmail.com> - 1.1.0-1
- Update to version 1.1.0

* Sat Jan 06 2024 Fabio Valentini <decathorpe@gmail.com> - 1.0.0-1
- Initial import (#2246730)
## END: Generated by rpmautospec