diff --git a/0001-solve-the-compilation-error.patch b/0001-solve-the-compilation-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..b0460a0d6d43ed100b070147a2142b07e296224c --- /dev/null +++ b/0001-solve-the-compilation-error.patch @@ -0,0 +1,44 @@ +From 778108006c5cede66862f5e967c7e5345fd9ba8d Mon Sep 17 00:00:00 2001 +From: pangqing +Date: Thu, 10 Mar 2022 14:39:19 +0800 +Subject: [PATCH] Solve the compilation error + +Signed-off-by: pangqing +--- + examples/chrony.nm-dispatcher.dhcp | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp +index 6ea4c37..e36cc98 100644 +--- a/examples/chrony.nm-dispatcher.dhcp ++++ b/examples/chrony.nm-dispatcher.dhcp +@@ -11,16 +11,24 @@ action=$2 + + chronyc=/usr/bin/chronyc + default_server_options=iburst +-server_dir=/var/run/chrony-dhcp ++server_dir=/run/chrony-dhcp + + dhcp_server_file=$server_dir/$interface.sources + # DHCP4_NTP_SERVERS is passed from DHCP options by NetworkManager. + nm_dhcp_servers=$DHCP4_NTP_SERVERS + ++[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network ++[ -f /etc/sysconfig/network-scripts/ifcfg-"${interface}" ] && \ ++ . /etc/sysconfig/network-scripts/ifcfg-"${interface}" ++ + add_servers_from_dhcp() { + rm -f "$dhcp_server_file" ++ ++ # Don't add NTP servers if PEERNTP=no specified; return early. ++ [ "$PEERNTP" = "no" ] && return ++ + for server in $nm_dhcp_servers; do +- echo "server $server $default_server_options" >> "$dhcp_server_file" ++ echo "server $server ${NTPSERVERARGS:-$default_server_options}" >> "$dhcp_server_file" + done + $chronyc reload sources > /dev/null 2>&1 || : + } +-- +2.18.4 + diff --git a/chrony-4.2.tar.gz b/chrony-4.2.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..42b76edbc3468f0571bd78a81e4c04986635247b Binary files /dev/null and b/chrony-4.2.tar.gz differ diff --git a/chrony.dhclient b/chrony.dhclient new file mode 100644 index 0000000000000000000000000000000000000000..3fe9e92dc385d31c7cf307d6e3091f8c60e0efca --- /dev/null +++ b/chrony.dhclient @@ -0,0 +1,27 @@ +#!/bin/bash + +CHRONY_SOURCEDIR=/run/chrony-dhcp +SERVERFILE=$CHRONY_SOURCEDIR/$interface.sources + +chrony_config() { + # Disable modifications if called from a NM dispatcher script + [ -n "$NM_DISPATCHER_ACTION" ] && return 0 + + rm -f "$SERVERFILE" + if [ "$PEERNTP" != "no" ]; then + mkdir -p $CHRONY_SOURCEDIR + for server in $new_ntp_servers; do + echo "server $server ${NTPSERVERARGS:-iburst}" >> "$SERVERFILE" + done + /usr/bin/chronyc reload sources > /dev/null 2>&1 || : + fi +} + +chrony_restore() { + [ -n "$NM_DISPATCHER_ACTION" ] && return 0 + + if [ -f "$SERVERFILE" ]; then + rm -f "$SERVERFILE" + /usr/bin/chronyc reload sources > /dev/null 2>&1 || : + fi +} diff --git a/chrony.spec b/chrony.spec new file mode 100644 index 0000000000000000000000000000000000000000..e4c821860b04f5d0b4e5777366bfd8ae5d53aa81 --- /dev/null +++ b/chrony.spec @@ -0,0 +1,202 @@ +%define anolis_release 1 +%global _hardened_build 1 +%global clknetsim_ver 470b5e +%bcond_without debug +%bcond_without nts + +%ifarch x86_64 aarch64 +%bcond_without seccomp +%endif + +Name: chrony +Version: 4.2 +Release: %{anolis_release}%{?dist} +Summary: An NTP client/server + +License: GPLv2 +URL: https://chrony.tuxfamily.org +Source0: chrony-4.2.tar.gz +Source3: chrony.dhclient +# simulator for test suite +Source10: https://github.com/mlichvar/clknetsim/archive/%{clknetsim_ver}/clknetsim-%{clknetsim_ver}.tar.gz +%{?gitpatch:Patch0: chrony-%{version}%{?prerelease}-%{gitpatch}.patch.gz} + +# add distribution-specific bits to DHCP dispatcher +Patch1: 0001-solve-the-compilation-error.patch + +BuildRequires: libcap-devel libedit-devel nettle-devel pps-tools-devel +BuildRequires: gcc gcc-c++ make bison systemd gnupg2 +%{?with_nts:BuildRequires: gnutls-devel gnutls-utils} +%{?with_seccomp:BuildRequires: libseccomp-devel} + +Requires(pre): shadow-utils +%{?systemd_requires} + +# Old NetworkManager expects the dispatcher scripts in a different place +Conflicts: NetworkManager < 1.20 + +# suggest drivers for hardware reference clocks +Suggests: ntp-refclock + +%description +chrony is a versatile implementation of the Network Time Protocol (NTP). +It can synchronise the system clock with NTP servers, reference clocks +(e.g. GPS receiver), and manual input using wristwatch and keyboard. It +can also operate as an NTPv4 (RFC 5905) server and peer to provide a time +service to other computers in the network. + +%if 0%{!?vendorzone:1} +%global vendorzone %(source /etc/os-release && echo ${ID}.) +%endif + +%prep +%setup -q -n %{name}-%{version}%{?prerelease} -a 10 +%{?gitpatch:%patch0 -p1} +%patch1 -p1 -b .nm-dispatcher-dhcp + +%{?gitpatch: echo %{version}-%{gitpatch} > version.txt} + +# review changes in packaged configuration files and scripts +md5sum -c <<-EOF | (! grep -v 'OK$') + b40117b4aac846d31e4ad196dc44cda3 examples/chrony-wait.service + 2d01b94bc1a7b7fb70cbee831488d121 examples/chrony.conf.example2 + 96999221eeef476bd49fe97b97503126 examples/chrony.keys.example + 6a3178c4670de7de393d9365e2793740 examples/chrony.logrotate + a7054c9352c07384bd7ea0477e6e8a8c examples/chrony.nm-dispatcher.dhcp + 8f5a98fcb400a482d355b929d04b5518 examples/chrony.nm-dispatcher.onoffline + 677ad16d6439daa369da44a1b75d1772 examples/chronyd.service +EOF + +# don't allow packaging without vendor zone +test -n "%{vendorzone}" + +# use example chrony.conf as the default config with some modifications: +# - use our vendor zone (2.*pool.ntp.org names include IPv6 addresses) +# - enable leapsectz to get TAI-UTC offset and leap seconds from tzdata +# - enable keyfile +# - use NTP servers from DHCP +sed -e 's|^\(pool \)\(pool.ntp.org\)|\12.%{vendorzone}\2|' \ + -e 's|#\(leapsectz\)|\1|' \ + -e 's|#\(keyfile\)|\1|' \ + -e 's|^pool.*pool.ntp.org.*|&\n\n# Use NTP servers from DHCP.\nsourcedir /run/chrony-dhcp|' \ + < examples/chrony.conf.example2 > chrony.conf + +touch -r examples/chrony.conf.example2 chrony.conf + +# regenerate the file from getdate.y +rm -f getdate.c + +mv clknetsim-%{clknetsim_ver}* test/simulation/clknetsim + +%build +%configure \ +%{?with_debug: --enable-debug} \ + --enable-ntp-signd \ +%{?with_seccomp: --enable-scfilter} \ +%{!?with_nts: --disable-nts} \ + --chronyrundir=/run/chrony \ + --docdir=%{_docdir} \ + --with-ntp-era=$(date -d '1970-01-01 00:00:00+00:00' +'%s') \ + --with-user=chrony \ + --with-hwclockfile=%{_sysconfdir}/adjtime \ + --with-pidfile=/run/chrony/chronyd.pid \ + --with-sendmail=%{_sbindir}/sendmail +%make_build + +%install +%make_install + +rm -rf $RPM_BUILD_ROOT%{_docdir} + +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{sysconfig,logrotate.d} +mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/{lib,log}/chrony +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/dhcp/dhclient.d +mkdir -p $RPM_BUILD_ROOT%{_libexecdir} +mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/NetworkManager/dispatcher.d +mkdir -p $RPM_BUILD_ROOT{%{_unitdir},%{_prefix}/lib/systemd/ntp-units.d} + +install -m 644 -p chrony.conf $RPM_BUILD_ROOT%{_sysconfdir}/chrony.conf + +install -m 640 -p examples/chrony.keys.example \ + $RPM_BUILD_ROOT%{_sysconfdir}/chrony.keys +install -m 755 -p %{SOURCE3} \ + $RPM_BUILD_ROOT%{_sysconfdir}/dhcp/dhclient.d/chrony.sh +install -m 644 -p examples/chrony.logrotate \ + $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/chrony + +install -m 644 -p examples/chronyd.service \ + $RPM_BUILD_ROOT%{_unitdir}/chronyd.service +install -m 755 -p examples/chrony.nm-dispatcher.onoffline \ + $RPM_BUILD_ROOT%{_prefix}/lib/NetworkManager/dispatcher.d/20-chrony-onoffline +install -m 755 -p examples/chrony.nm-dispatcher.dhcp \ + $RPM_BUILD_ROOT%{_prefix}/lib/NetworkManager/dispatcher.d/20-chrony-dhcp +install -m 644 -p examples/chrony-wait.service \ + $RPM_BUILD_ROOT%{_unitdir}/chrony-wait.service + +cat > $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/chronyd < \ + $RPM_BUILD_ROOT%{_prefix}/lib/systemd/ntp-units.d/50-chronyd.list + +%check +# set random seed to get deterministic results +export CLKNETSIM_RANDOM_SEED=24505 +%make_build -C test/simulation/clknetsim +make quickcheck + +%pre +getent group chrony > /dev/null || /usr/sbin/groupadd -r chrony +getent passwd chrony > /dev/null || /usr/sbin/useradd -r -g chrony \ + -d %{_localstatedir}/lib/chrony -s /sbin/nologin chrony +: + +%post +# workaround for late reload of unit file (#1614751) +%{_bindir}/systemctl daemon-reload +# migrate from chrony-helper to sourcedir directive +if test -a %{_libexecdir}/chrony-helper; then + grep -qi 'sourcedir /run/chrony-dhcp$' %{_sysconfdir}/chrony.conf 2> /dev/null || \ + echo -e '\n# Use NTP servers from DHCP.\nsourcedir /run/chrony-dhcp' >> \ + %{_sysconfdir}/chrony.conf + mkdir -p /run/chrony-dhcp + for f in %{_localstatedir}/lib/dhclient/chrony.servers.*; do + sed 's|.*|server &|' < $f > /run/chrony-dhcp/"${f##*servers.}.sources" + done 2> /dev/null +fi +%systemd_post chronyd.service chrony-wait.service + +%preun +%systemd_preun chronyd.service chrony-wait.service + +%postun +%systemd_postun_with_restart chronyd.service + +%files +%{!?_licensedir:%global license %%doc} +%license COPYING +%doc FAQ NEWS README +%config(noreplace) %{_sysconfdir}/chrony.conf +%config(noreplace) %verify(not md5 size mtime) %attr(640,root,chrony) %{_sysconfdir}/chrony.keys +%config(noreplace) %{_sysconfdir}/logrotate.d/chrony +%config(noreplace) %{_sysconfdir}/sysconfig/chronyd +%{_sysconfdir}/dhcp/dhclient.d/chrony.sh +%{_bindir}/chronyc +%{_sbindir}/chronyd +%{_prefix}/lib/NetworkManager +%{_prefix}/lib/systemd/ntp-units.d/*.list +%{_unitdir}/chrony*.service +%{_mandir}/man[158]/%{name}*.[158]* +%dir %attr(750,chrony,chrony) %{_localstatedir}/lib/chrony +%ghost %attr(-,chrony,chrony) %{_localstatedir}/lib/chrony/drift +%ghost %attr(-,chrony,chrony) %{_localstatedir}/lib/chrony/rtc +%dir %attr(750,chrony,chrony) %{_localstatedir}/log/chrony + +%changelog +* Wed Mar 09 2022 pangqing - 4.2-1 +- Init for anolisOS 23 + diff --git a/clknetsim-470b5e.tar.gz b/clknetsim-470b5e.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..4bbf793573bbb443e8354ba2b15057ca0a76e21d Binary files /dev/null and b/clknetsim-470b5e.tar.gz differ