%define	_bindir	%{_prefix}/sbin

Summary: Synchronizes system time using the Network Time Protocol (NTP).
Name: ntp
Version: 4.2.6p5
Release: 2%{?_dist_release}
License: distributable
Group: System Environment/Daemons
URL: http://www.ntp.org/
Source0: ftp://ftp.udel.edu/pub/ntp/ntp4/ntp-%{version}.tar.gz
Source1: ntp.conf
Source2: ntp.keys
Source3: ntpd.init
Source4: ntpd.sysconfig
Source5: ntpstat-0.2.tgz

Source100: ntpd-NM-dispatch
Source999: filter-requires-ntp.sh

# ntpbz #802
Patch1: ntp-4.2.6p1-sleep.patch
# add support for dropping root to ntpdate
Patch2: ntp-4.2.6p4-droproot.patch
# ntpbz #779
Patch3: ntp-4.2.6p3-bcast.patch
# align buffer for control messages
Patch4: ntp-4.2.6p1-cmsgalign.patch
# link ntpd with -ffast-math on ia64
# Patch5: ntp-4.2.6p1-linkfastmath.patch
# ntpbz #1134
# Patch6: ntp-4.2.6p5-tentative.patch
# ntpbz #2294
Patch6: ntp-4.2.6p5-fipsmd5.patch
# ntpbz #759
Patch7: ntp-4.2.6p1-retcode.patch
# ntpbz #992
Patch8: ntp-4.2.6p4-rtnetlink.patch
# fix script used to generate man pages
# Patch9: ntp-4.2.6p2-html2man.patch
# ntpbz #898
Patch10: ntp-4.2.6p4-htmldoc.patch
# fix precision calculation on fast CPUs
Patch12: ntp-4.2.4p7-getprecision.patch
# ntpbz #1408
Patch13: ntp-4.2.6p1-logdefault.patch
# add option -m to lock memory
Patch14: ntp-4.2.6p4-mlock.patch
# allow -u and -p options to be used twice (#639101)
Patch15: ntp-4.2.6p2-multiopts.patch
# ntpbz #1554
# Patch16: ntp-4.2.6p3-nosyspeer.patch
# ntpbz #1670
Patch17: ntp-4.2.6p3-broadcastdelay.patch
# ntpbz #1671
Patch18: ntp-4.2.6p5-delaycalib.patch
# ntpbz #1695
# Patch19: ntp-4.2.6p5-ntpdaterecv.patch

# handle unknown clock types
Patch50: ntpstat-0.2-clksrc.patch
# process first packet in multipacket response
Patch51: ntpstat-0.2-multipacket.patch
# use current system variable names
Patch52: ntpstat-0.2-sysvars.patch
# print synchronization distance instead of dispersion
Patch53: ntpstat-0.2-maxerror.patch
# fix error bit checking
Patch54: ntpstat-0.2-errorbit.patch

# workaround fix for glibc headers
Patch60: ntp-4.2.x_MOD_NANO.patch

# security
# Patch100: ntp-4.2.4_CVE-2009-0159.patch

Requires(pre): /sbin/chkconfig
# PreReq: /sbin/chkconfig
BuildRequires: openssl-devel, readline-devel
BuildRequires: libcap-devel
BuildRequires: autoconf
# ntpstat
BuildRequires: perl-HTML-Parser
#Conflicts: xntp3
Obsoletes: xntp3
BuildRoot: %{_tmppath}/%{name}-%{version}-root

# Working around perl dependency problem
%define __find_requires %{SOURCE999}

%description
The Network Time Protocol (NTP) is used to synchronize a computer's
time with another reference time source.  The ntp package contains
utilities and daemons which will synchronize your computer's time to
Coordinated Universal Time (UTC) via the NTP protocol and NTP servers.
The ntp package includes ntpdate (a program for retrieving the date
and time from remote machines via a network) and ntpd (a daemon which
continuously adjusts system time).

Install the ntp package if you need tools for keeping your system's
time synchronized via the NTP protocol.
#'

%package perl
Summary: NTP utilities written in perl
Group: Applications/System
Requires: %{name} = %{version}-%{release}

%description perl
This package contains perl scripts ntp-wait and ntptrace.

Packager: iwamoto
Vendor: Project Vine
Distribution: Vine Linux

%prep 
%setup -q -a 5

%patch1 -p1 -b .sleep
%patch2 -p1 -b .droproot
%patch3 -p1 -b .bcast
%patch4 -p1 -b .cmsgalign
%ifarch ia64
# %patch5 -p1 -b .linkfastmath
%endif
# %patch6 -p1 -b .tentative
%patch6 -p1 -b .fipsmd5
%patch7 -p1 -b .retcode
%patch8 -p1 -b .rtnetlink
# %patch9 -p1 -b .html2man
%patch10 -p1 -b .htmldoc
%patch12 -p1 -b .getprecision
%patch13 -p1 -b .logdefault
%patch14 -p1 -b .mlock
%patch15 -p1 -b .multiopts
# %patch16 -p1 -b .nosyspeer
%patch17 -p1 -b .broadcastdelay
%patch18 -p1 -b .delaycalib
# %patch19 -p1 -b .ntpdaterecv

# set default path to sntp KoD database
sed -i 's|/var/db/ntp-kod|%{_localstatedir}/lib/ntp/sntp-kod|' sntp/{sntp.1,main.c}

# ntpstat patches
%patch50 -p1 -b .clksrc
%patch51 -p1 -b .multipacket
%patch52 -p1 -b .sysvars
%patch53 -p1 -b .maxerror
%patch54 -p1 -b .errorbit

%patch60 -p0 -b .NANO

# security
# %patch100 -p1 -b .CVE-2009-0159

%build
# autoconf
autoreconf -vfi

# XXX work around for anal ntp configure
# %define	_target_platform	%{nil}
# %configure
# CFLAGS="-g -DDEBUG" ./configure --prefix=/usr

CFLAGS="-g" ./configure         \
	     --prefix=/usr      \
	     --with-openssl-libdir=%{_libdir} \
	     --with-lineeditlibs=readline

%undefine	_target_platform

%__make %{?_smp_mflags}
%__make %{?_smp_mflags} -C ntpstat-0.2 CFLAGS="$CFLAGS"

pushd html
../scripts/html2man
# remove adjacent blank lines
sed -i 's/^[\t\ ]*$//;/./,/^$/!d' man/man*/*.[58]
popd 

%install
rm -rf $RPM_BUILD_ROOT

%makeinstall

{ pushd $RPM_BUILD_ROOT

  mkdir -p .%{_sysconfdir}/{ntp,rc.d/init.d,sysconfig}
  mkdir -p .%{_sysconfdir}/NetworkManager/dispatcher.d
  install -m644 $RPM_SOURCE_DIR/ntp.conf .%{_sysconfdir}/ntp.conf
  touch .%{_sysconfdir}/ntp/drift
  install -m600 $RPM_SOURCE_DIR/ntp.keys .%{_sysconfdir}/ntp/keys
  touch .%{_sysconfdir}/ntp/step-tickers
  install -m755 $RPM_SOURCE_DIR/ntpd.init .%{_sysconfdir}/rc.d/init.d/ntpd
  install -m644 %{SOURCE4} .%{_sysconfdir}/sysconfig/ntpd
  install -m755 %{SOURCE100} .%{_sysconfdir}/NetworkManager/dispatcher.d/06-ntpd

  strip .%{_bindir}/* || :
  popd
}

mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8
pushd html/man/man8
install -m 644 ntp-wait.8 $RPM_BUILD_ROOT%{_mandir}/man8/
install -m 644 ntptrace.8 $RPM_BUILD_ROOT%{_mandir}/man8/
popd

pushd ntpstat-0.2
mkdir -p $RPM_BUILD_ROOT%{_bindir}
install -m 755 ntpstat $RPM_BUILD_ROOT%{_bindir}
install -m 644 ntpstat.1 $RPM_BUILD_ROOT%{_mandir}/man8/ntpstat.8
popd

%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/chkconfig --add ntpd

%preun
if [ $1 = 0 ]; then
    service ntpd stop > /dev/null 2>&1
    /sbin/chkconfig --del ntpd
fi

%postun
if [ "$1" -ge "1" ]; then
# service ntpd condrestart > /dev/null 2>&1
  service ntpd condrestart
fi

%files
%defattr(-,root,root)
%doc html/* NEWS TODO 

%{_sbindir}/ntp-keygen
%{_sbindir}/ntpd
%{_sbindir}/ntpdate
%{_sbindir}/ntpdc
%{_sbindir}/ntpq
%{_sbindir}/ntpstat
%{_sbindir}/ntptime
%{_sbindir}/sntp
%{_sbindir}/tickadj

%config				%{_sysconfdir}/rc.d/init.d/ntpd
%config(noreplace)		%{_sysconfdir}/ntp.conf
%dir				%{_sysconfdir}/ntp/
%ghost %config(missingok)	%{_sysconfdir}/ntp/drift
%config(noreplace)		%{_sysconfdir}/ntp/keys
%ghost %config(missingok)	%{_sysconfdir}/ntp/step-tickers
%config(noreplace)		%{_sysconfdir}/sysconfig/ntpd
%{_sysconfdir}/NetworkManager/dispatcher.d/*
%{_mandir}/man1/*
%{_mandir}/man8/ntpstat*

%files perl
%defattr(-,root,root)
%{_sbindir}/ntp-wait
%{_sbindir}/ntptrace
%{_mandir}/man8/ntp-wait.8*
%{_mandir}/man8/ntptrace.8*

%changelog
* Sat Nov  3 2012 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.6p5-1
- new upstream release
- update patches from fc18
- fix changelog typo....

* Sun Jan 16 2011 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.6p3-2
- add config options to use openssl libs, readline libs
- add BR: libcap-devel, perl-HTML-Parser (Thanks to Take-san)

* Sat Jan 15 2011 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.6p3-1
- new upstream release
- built with openssl 1.0.0c
- perl scripts are separated to -perl package

* Sat Dec 12 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.4p8-1
- new upstream release with security fix (CVE-2009-3563)

* Fri Aug 21 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.4p7-3
- add NetworkManager/dispatcher.d/06-ntpd for NM
- fix changelog typo...

* Wed May 20 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.4p7-2
- turn on daemon restart message

* Wed May 20 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.4p7-1
- new upstream release with security fix (CVE-2009-0159,1252)
- drop pacth100 (included in new release)
- update patch5 to fit p7 release

* Mon Apr 27 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.4p6-2
- add patch100 for fix CVE-2009-0159 (ntpq)
- run autoreconf instead of autoconf

* Sun Jan 11 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.2.4p6-1
- new upstream release with security fix (CVE-2009-0021)

* Mon Apr 28 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.2.4p4-1
- new upstream release

* Sun Aug  5 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.2.4p3-0vl2
- rebuilt

* Thu Jul 26 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.2.4p3-0vl1
- new upstream release
- updated Patch5

* Mon Nov 20 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 4.2.0-0vl7
- rebuild for Vine Seed

* Mon Nov 20 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 4.2.0-0vl6
- add Patch5 to skip checking md5.h

* Mon Nov 20 2006 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 4.2.0-0vl5
- rebuilt without libelf-devel (ppc.rpm linked with libelf.so.0)

* Fri Aug 18 2006 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 4.2.0-0vl4
- rebuild with readline-5.1
- add BuildRequires: openssl-devel, readline-devel

* Fri Apr 09 2004 Tomoya TAKA <taka@vinelinux.org> 4.2.0-0vl3
- rebuild with openssl-0.9.7d
- add config_crypto.patch for alpha (Patch4)

* Wed Mar  3 2004 NISHIMURA Daisuke <nishi@graco.c.u-tokyo.ac.jp> 4.2.0-0vl2
- ntp.conf (Source1): authenticate command has been disappeared.
- ntpd.init (Source3): remove RedHat's firewall-related codes.
- remove obsolete patches (Patch0, Patch1)

* Mon Feb 16 2004 IWAI, Masaharu <iwai@alib.jp> 4.2.0-0vl1
- update to 4.2.0
- update ntpd.init (Source3): from Fedora ntp-4.2.0-5
- add ntpd.sysconfig (Source4)
- stop patching vsnprintf patch (Patch1)

* Mon Sep  1 2003 IWAI, Masaharu <iwai@alib.jp> 4.1.2-0vl1
- update to 4.1.2
- update URL tag
- update vsnprintf.patch (Patch1)

* Tue May 06 2003 Tomoya TAKA <taka@vinelinux.org> 4.1.1-0vl2
- rebuild with new toolchain

* Fri Mar 01 2002 Toru Sagami <sagami@vinelinux.org> 4.1.1-0vl1
- update to 4.1.1

* Tue Sep 04 2001 Jiro Yamada <jiro@fd.catv.ne.jp>
- update to 4.1.0

* Mon Apr 09 2001 akira yamada <akira@vinelinux.org>
- new upstream version 4.0.99k23.

* Thu Apr 05 2001 akira yamada <akira@vinelinux.org>
- fixed buffer overrun (imported from debian).
- imported from rawhide.

* Mon Mar  5 2001 Preston Brown <pbrown@redhat.com>
- allow comments in /etc/ntp/step-tickers file (#28786).
- need patch0 (glibc patch) on ia64 too

* Tue Feb 13 2001 Florian La Roche <Florian.LaRoche@redhat.de>
- also set prog=ntpd in initscript

* Tue Feb 13 2001 Florian La Roche <Florian.LaRoche@redhat.de>
- use "$prog" instead of "$0" for the init script

* Thu Feb  8 2001 Preston Brown <pbrown@redhat.com>
- i18n-neutral .init script (#26525)

* Tue Feb  6 2001 Preston Brown <pbrown@redhat.com>
- use gethostbyname on addresses in /etc/ntp.conf for ntptime command (#26250)

* Mon Feb  5 2001 Preston Brown <pbrown@redhat.com>
- start earlier and stop later (#23530)

* Mon Feb  5 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- i18nize init script (#26078)

* Sat Jan  6 2001 Jeff Johnson <jbj@redhat.com>
- typo in ntp.conf (#23173).

* Mon Dec 11 2000 Karsten Hopp <karsten@redhat.de>
- rebuilt to fix permissions of /usr/share/doc/ntp-xxx

* Thu Nov  2 2000 Jeff Johnson <jbj@redhat.com>
- correct mis-spellings in ntpq.htm (#20007).

* Thu Oct 19 2000 Jeff Johnson <jbj@redhat.com>
- add %ghost /etc/ntp/drift (#15222).

* Wed Oct 18 2000 Jeff Johnson <jbj@redhat.com>
- comment out default values for keys, warn about starting with -A (#19316).
- take out -A from ntpd startup as well.
- update to 4.0.99k.

* Wed Aug 23 2000 Jeff Johnson <jbj@redhat.com>
- use vsnprintf rather than vsprintf (#16676).

* Mon Aug 14 2000 Jeff Johnson <jbj@redhat.com>
- remove Conflicts: so that the installer is happy.

* Tue Jul 25 2000 Jeff Johnson <jbj@redhat.com>
- workaround glibc-2.1.90 lossage for now.

* Thu Jul 20 2000 Bill Nottingham <notting@redhat.com>
- move initscript back

* Wed Jul 12 2000 Prospector <bugzilla@redhat.com>
- automatic rebuild

* Mon Jun 26 2000 Preston Brown <pbrown@redhat.com>
- move and update init script, update post/preun/postun scripts

* Wed Jun 21 2000 Preston Brown <pbrown@redhat.com>
- noreplace ntp.conf,keys files

* Mon Jun 12 2000 Jeff Johnson <jbj@redhat.com>
- Create 4.0.99j package.
- FHS packaging.
