File leafnode.spec of Package leafnode2

%define commit 0433b24e5e9bcedad060bec4ec53899a1bceb074
%define shortcommit %(c=%{commit}; echo ${c:0:7})

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

Version: 2.0.0.alpha20140727b
Summary: Leaf site NNTP server
Summary(de): Ein offline-Newsserver
Name: leafnode
Release: 0.0.14.vcs%{shortcommit}%{?dist}
License: MIT
Group: Productivity/Networking/News/Servers
URL: http://www.dt.e-technik.uni-dortmund.de/~ma/leafnode/beta/
# Use checkout from the git repo at
# https://gitlab.com/leafnode-2/leafnode-2/
Source0: %{name}.tar.bz2
Source1: %{name}.xinetd
Source4: %{name}-hourly.cron
Source5: %{name}-daily.cron
# https://gitlab.com/leafnode-2/leafnode-2/merge_requests/1
Patch0:  Fixes-autotools-on-systemd-based-systems.patch
# https://gitlab.com/leafnode-2/leafnode-2/merge_requests/2
Patch1:  Convert-manpages-to-UTF8-and-mark-them-a-such.patch

%if %{with systemd}
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
BuildRequires: systemd
%else
Requires: xinetd
Requires(post): initscripts
%endif
BuildRequires: pam-devel, pcre-devel
BuildRequires:  automake intltool gettext libtool
%if 0%{?rhel} >= 7 || 0%{?fedora} >= 18
BuildRequires:  perl-podlators
%else
BuildRequires:  perl
%endif
%if 0%{?rhel} <= 6
BuildRequires:  autoconf >= 2.63
%else
BuildRequires:  autoconf >= 2.68
%endif
%if 0%{?rhel} >= 5 || 0%{?fedora} >= 18
BuildRequires: shadow-utils
Requires(pre): shadow-utils
%else
BuildRequires: shadow
Requires(pre): shadow
%endif
Requires(post): coreutils
%if %{with systemd}
Recommends: cron
%endif
%if 0%{?suse_version}
PreReq: permissions
%endif

%define spooldir    /var/spool/news
%define confdir     /etc/leafnode
%define runas_user  news
%define runas_group news

# Distribution: ${DISTRIBUTION}
%description
Leafnode is a small NNTP server for leaf sites without permanent
connection to the internet. It supports a subset of NNTP and is able to
automatically fetch the newsgroups the user reads regularly from the
newsserver of the ISP and additionally offer local (site-specific)
groups to a LAN.

%description -l de
Leafnode ist ein offline-Newsserver, der vor allem für den typischen
Einzelnutzer-Rechner ohne permanente Internetanbindung geeignet ist.
Leafnode bezieht automatisch die Newsgroups, die der oder die Nutzer
regelmäßig lesen, vom Newsserver des Providers. Weiter erlaubt es, lokale
(Standort-spezifische) Newsgruppen im LAN anzubieten.

%prep
%setup -q -n %{name}-2
%patch0 -p1
%patch1 -p1

autoreconf -v -i

%build
%configure \
 --disable-silent-rules \
 --enable-spooldir=%spooldir \
 --enable-runas-user=$(id -un) \
%if 0%{?suse_version}
 --sysconfdir=%{_fillupdir}/sysconfig.%{name} \
%else
 --sysconfdir=%{_sysconfdir}/leafnode \
%endif
 --with-pam
make

%check
make check

%install
# first clean out any prior aborted runs
rm -rf $RPM_BUILD_ROOT
make  DESTDIR=$RPM_BUILD_ROOT install

# We actually do not want filters to be installed in /etc/leafnode
%if 0%{?suse_version}
rm -vf $RPM_BUILD_ROOT/%{_fillupdir}/sysconfig.%{name}/filter*
%else
rm -vf $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/leafnode/filter*
%endif


%if %{with systemd}
mkdir -p $RPM_BUILD_ROOT/%{_unitdir}
install -p systemd/%{name}@.service $RPM_BUILD_ROOT/%{_unitdir}/
install -p systemd/%{name}.socket $RPM_BUILD_ROOT/%{_unitdir}/
%else
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/xinetd.d
install -p %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/xinetd.d/leafnode
%endif

# Templates for cronjobs
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/cron.hourly
install -p %{SOURCE4} $RPM_BUILD_ROOT/%{_sysconfdir}/cron.hourly/leafnode.cron
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/cron.daily
install -p %{SOURCE5} $RPM_BUILD_ROOT/%{_sysconfdir}/cron.daily/leafnode.cron

mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig
cat >$RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/leafnode << EOS
# Change the value of the following variable to "yes" to get hourly
# automatic fetching of all news from the configured sources
LEAFNODE_HOURLY="no"
# Change the value of the following variable to "no" to switch off daily
# maintenance of the leafnode spool (recommended: leave it as it is).
LEAFNODE_DAILY="yes"
EOS

for file in $RPM_BUILD_ROOT/%{_sysconfdir}/leafnode/*.example ; do
   NEWFN=$(basename $file .example);
   mv $file $RPM_BUILD_ROOT/%{_sysconfdir}/leafnode/$NEWFN
done

# When building without runas_user, then we need to set this
# parameter explicitly.
sed -i -e "s/^#\s*run_as_user.*\$/run_as_user = %{runas_user}/" \
    $RPM_BUILD_ROOT/%{_sysconfdir}/leafnode/config

touch $RPM_BUILD_ROOT/%{_sysconfdir}/leafnode/local.groups

%pre
%if 0%{?suse_version}
service_add_pre
%endif

%post
%if %{with systemd}
%if 0%{?suse_version}
%set_permissions %spooldir/leaf.node
service_add_post
%else
%systemd_post leafnode@.service
%endif
%else
service xinetd condrestart
%endif
if [ $1 -eq 1 ] ; then
    chown -R news:news %spooldir
    chmod -R 775 %spooldir
fi

%preun
%if %{with systemd}
%if 0%{?suse_version}
service_del_preun
%else
%systemd_preun leafnode@.service
%endif
%else
service xinetd condrestart
%endif

%postun
%if %{with systemd}
%if 0%{?suse_version}
service_del_postun
%else
%systemd_postun_with_restart leafnode@.service
%endif
%else
service xinetd condrestart
%endif


%files
%defattr(-,root,root)
%doc config.example filters.example COPYING COPYING.LGPL CREDITS
%doc DEBUGGING ENVIRONMENT FAQ.tex CHANGES-FROM-LEAFNODE-1 NEWS
%doc README-FQDN.tex TODO ChangeLog AUTHORS README-leaf.node README.html


%config %{_sysconfdir}/leafnode/
%config(noreplace) %attr(640,root,news) %{_sysconfdir}/leafnode/config
%if 0%{?suse_version}
%config(noreplace) %{_fillupdir}/sysconfig.%{name}
%else
%config(noreplace) %{_sysconfdir}/sysconfig/leafnode
%endif
%if %{with systemd}
%attr(644,root,root) %{_unitdir}/%{name}*
%else
%config(noreplace) %{_sysconfdir}/xinetd.d/leafnode
%endif
%config(noreplace) %attr(640,root,news) %{_sysconfdir}/leafnode/uucp
%config(noreplace) %attr(640,root,news) %{_sysconfdir}/leafnode/local.groups
%attr(751,root,root) %{_sysconfdir}/cron.*/leafnode.cron
%attr(755,root,root) %{_bindir}/leafnode-version
%attr(755,root,root) %{_bindir}/lsmac.pl
%attr(755,root,root) %{_bindir}/newsq
%attr(755,root,root) %{_sbindir}/applyfilter
%attr(755,root,root) %{_sbindir}/checkgroups
%attr(755,root,root) %{_sbindir}/fetchnews
%attr(755,root,root) %{_sbindir}/leafnode
%attr(755,root,root) %{_sbindir}/rnews
%attr(755,root,root) %{_sbindir}/sendbatch.bash
%attr(755,root,root) %{_sbindir}/texpire
%doc %{_mandir}/man1/*
%doc %{_mandir}/man5/*
%doc %{_mandir}/man8/*
%attr(755,%{runas_user},%{runas_group}) %spooldir

%clean
rm -rf $RPM_BUILD_ROOT

%changelog
* Tue Nov 22 2016 Matěj Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.14.vcs0433b24
- systemd unit files are not executable anymore
- rebase on the top of the upstream Gitlab checkout.

* Thu Jan 08 2015 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.13.vcs0433b24
- Don't install default filters and fix xinetd configuration.

* Thu Jan 08 2015 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.12.vcs0433b24
- Make cronjobs into proper scripts and add proper configuration file.

* Mon Dec 29 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.11.vcs0433b24
- Add patch converting fetchnews(8) to UTF-8.

* Sat Dec 27 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.10.vcs0433b24
- Fix all FSF addresses in all license attributions.

* Sat Dec 27 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.9.vcs0433b24
- Use the patch for systemd posted upstream.

* Sat Dec 27 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.7.vcs0433b24
- Make it buildable on RHEL-6 (apparently just decreasing required
  autoconf is enough).

* Fri Dec 26 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.6.vcs0433b24
- Add a crontab job fetching news.

* Fri Dec 26 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.5.vcs0433b24
- Set run_as_user parameter in /etc/leafnode/config explicitly.

* Mon Dec 15 2014 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20140727b-0.0.1
- Update to the latest upstream

* Thu Jul 24 2014 Matěj Cepl <mcepl@redhat.com> - 2.0.0.alpha-0.0.vcs20140724git3f38b2b
- Update to the latest upstream

* Wed May 23 2007 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20070108a-3
- Added support for croning of texpire daily

* Thu Apr 26 2007 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20070108a-2
- Add pcre-devel to Build-Requires; thanks build.opensuse.org for catching this.
- Add /etc/leafnode/local.groups

* Fri Mar 23 2007 Matej Cepl <mcepl@redhat.com> - 2.0.0.alpha20070108a-1
- new upstream release
- enabled pam

* Mon Jan 02 2006 Matěj Cepl <mcepl@redhat.com> 2.0.0.alpha20061010a-0
- experimental build