%define _initdir %{_sysconfdir}/rc.d/init.d

Summary: Daemon that provides on demand IP links via SLIP or PPP.
Name: diald
Version: 1.0
Release: 0vl4
License: distributable
Group: System Environment/Daemons
URL: http://diald.sourceforge.net/
Source0: http://download.sourceforge.net/diald/diald-%{version}.tar.gz
Source1: diald.init
Source2: diald.conf.sample
Source3: phone.filter
Source4: connect.diald
Patch0: diald-1.0-Makefile.patch
Patch1: diald-route-0.99.4.patch
Patch2: diald-1.0-glibc22.patch
Requires: ppp
PreReq: chkconfig
BuildRoot: %{_tmppath}/%{name}-root

%description
Diald is a daemon that provides on demand IP links via SLIP or PPP. The
purpose of diald is to make it transparently appear that you have a
permanent connection to a remote site. Diald sets up a "proxy" device which
stands in for the physical connection to a remote site. It then monitors the
proxy, waiting for packets to arrive. When interesting packets arrive it
will attempt to establish the physical link to the remote site using either
SLIP or PPP, and if it succeeds it will forward traffic from the proxy to
the physical link. As well, diald will monitor traffic once the physical
link is up, and when it has determined that the link is idle, the remote
connection is terminated. The criteria for bringing the link up and taking
it down are configurable at run time, and are based upon the type of traffic
passing over the link.

%prep
%setup -q
%patch0 -p1 -b .orig
%patch1 -p0 -b .route
%patch2 -p1 -b .glibc22

%build
%configure --localstatedir=/var
make

%install
rm -rf $RPM_BUILD_ROOT
%makeinstall

cp -p config/dynamic.filter $RPM_BUILD_ROOT%{_libdir}/diald/
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/diald
mknod -m 0660 $RPM_BUILD_ROOT%{_sysconfdir}/diald/diald.ctl p
mkdir -p $RPM_BUILD_ROOT%{_initdir}
install -p -m755 %{SOURCE1} $RPM_BUILD_ROOT%{_initdir}/diald 

# Source 2,3,4
cp -p %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/diald.conf 
cp -p %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/diald 
cp -p %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/diald/connect 

# eliminate excessive executable bit
find contrib/ -type f -perm +111 | xargs chmod -x
find %{buildroot}%{_libdir}/diald -type f -perm +111 | xargs chmod -x

%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/chkconfig --add diald

%preun
if [ $1 = 0 ]; then
   /sbin/chkconfig --del diald
fi

%files
%defattr(-,root,root)
%doc BUGS CHANGES LICENSE NOTES README* THANKS TODO TODO.budget
%doc doc/diald-faq.txt contrib
%config %{_initdir}/diald
%config(noreplace) %{_sysconfdir}/diald.conf
%config(noreplace) %{_sysconfdir}/diald/connect
%config(noreplace) %{_sysconfdir}/diald/phone.filter
%{_sysconfdir}/diald/diald.ctl
%{_bindir}/dctrl
%{_sbindir}/diald
%{_libdir}/diald
%{_mandir}/man1/dctrl.1*
%{_mandir}/man5/diald-control.5*
%{_mandir}/man5/diald-examples.5*
%{_mandir}/man5/diald-monitor.5*
%{_mandir}/man8/diald.8*

%changelog
* Wed Jan 30 2002 Toru Sagami <sagami@vinelinux.org> 1.0-0vl4
- added adhoc patch to build on glibc22 system

* Wed Aug 08 2001 <sagami@vinelinux.org>
- 1.0-0vl3: fix again to handle pid file correctly

* Fri Aug 03 2001 <sagami@vinelinux.org>
- 1.0-0vl2: fix initscript to handle pid file correctly

* Sun Jun 17 2001 <sagami@vinelinux.org>
- 1.0-0vl0

* Fri Jun 15 2001 <sagami@vinelinux.org>
- 0.99.4-0vl2: %%{_mandir}

* Wed Mar 01 2000 Toru Sagami <czs14350@nifty.ne.jp>
- 0.99.4
- add contrib to docdir
- fix diald.init

* Fri Feb 18 2000 Toru Sagami <czs14350@nifty.ne.jp>
- handle RPM_OPT_FLAGS
- add noreplace to configutation files

* Fri Feb 11 2000 Toru Sagami <czs14350@nifty.ne.jp>
- added diald-twoway.diff(it fixes diald_won't_redial problem?)
- changed Group from Networking/Daemons to System Environment/Daemons
- enabled %post and %preun

* Fri Jan 28 2000 Toru Sagami <czs14350@nifty.ne.jp>
- freshen URL Source tags

* Fri Jan 14 2000 Toru Sagami <czs14350@nifty.ne.jp>
- 0.99.3

* Wed Dec 01 1999 Toru Sagami <czs14350@nifty.ne.jp>
- build 0.99.2
- include diald.conf.sample