File rbldnsd.spec of Package rbldnsd

%define rbldnsd_version 0.998 
%define rbldnsd_release 1.0

Summary:         A small and fast DNS daemon to serve DNSBL zones
Name:            rbldnsd
Version:         %{rbldnsd_version}
Release:         %{rbldnsd_release}
License:         GPL-2.0+
URL:             http://www.corpit.ru/mjt/rbldnsd.html 

Source:          http://www.corpit.ru/mjt/rbldnsd/rbldnsd-%{rbldnsd_version}.tar.gz
BuildRoot:       %{_tmppath}/%{name}-%{version}-%{release}-build

%if 0%{?suse_version}
Group:           Productivity/Networking/DNS/Servers
Requires(pre):   pwdutils
Requires(pre):   %fillup_prereq %insserv_prereq
%else # fedora
Group:           System Environment/Daemons
Requires(pre):   shadow-utils
Requires(post):  chkconfig
Requires(preun): chkconfig initscripts
%endif

Source1:         %{name}.init
Source2:         sysconfig.%{name}
Source3:         %{name}.service

%if 0%{?suse_version} >= 1140
BuildRequires:   syslog, sysconfig
%endif
%if 0%{?suse_version} > 1140 || 0%{?fedora_version} > 15
BuildRequires:   systemd
%{?systemd_requires}
%if 0%{?fedora_version} > 15 
Requires(post):  systemd-sysv
Requires(post):  systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%endif
%endif

%description
rbldnsd is a small and fast DNS daemon which is especially made to serve DNSBL zones. This daemon was inspired by Dan J. Bernstein's rbldns program found in the djbdns package.
rbldnsd is extremely fast - it outperforms both bind and djbdns greatly. It has very small memory footprint. 

%prep
%setup -q 

%build
./configure
%{__make} %{?_smp_mflags} OPTIMIZE="%{optflags}"

%pre
getent group rbldns >/dev/null || /usr/sbin/groupadd -r rbldns
getent passwd rbldns >/dev/null || /usr/sbin/useradd -r -g rbldns -c "rbldns daemon" -d /var/lib/rbldnsd/ -s /bin/false rbldns
exit 0

%install
# install systemd service files
%if 0%{?suse_version} > 1140 || 0%{?fedora_version} > 15 
  mkdir -p %{buildroot}/%{_unitdir}
  install -m 0644 %{SOURCE3} %{buildroot}/%{_unitdir}/
%endif
%if 0%{?suse_version} 
  install -Dm0600 %{SOURCE2} %{buildroot}/var/adm/fillup-templates/sysconfig.%{name}
  %if 0%{?suse_version} <= 1140
    install -Dm0755 %{SOURCE1} %{buildroot}/%{_sysconfdir}/init.d/%{name}
    install -d %{buildroot}/%{_sbindir}
    ln -sf %{_sysconfdir}/init.d/rbldnsd %{buildroot}/%{_sbindir}/rcrbldnsd
  %endif
%else # fedora
  install -Dm0600 %{SOURCE2} %{buildroot}/%{_sysconfdir}/sysconfig/%{name}
  %if 0%{?fedora_version} > 15
    # do nothing
  %else
    install -Dm0755 %{SOURCE1} %{buildroot}/%{_sysconfdir}/rc.d/init.d/%{name}
  %endif
%endif
install -d -m 0755 %{buildroot}/%{_sbindir}
install -m 0755 rbldnsd %{buildroot}/%{_sbindir}/rbldnsd
install -d -m 0755 %{buildroot}/%{_mandir}/man8
install -m 0644 rbldnsd.8 %{buildroot}/%{_mandir}/man8/rbldnsd.8
install -d -m 0755 %{buildroot}/var/lib/rbldnsd

%post
%if 0%{?suse_version}
  %if %suse_version > 1140
    %service_add_post %{name}.service
    %{fillup_only %{name}}
  %else
    %{fillup_and_insserv -y %{name}}
  %endif
%else # fedora
  %if 0%{?fedora_version} > 15
    if [ $1 -eq 1 ] ; then # Initial installation 
      /bin/systemctl daemon-reload >/dev/null 2>&1 || :
    fi
  %else
    /sbin/chkconfig --add %{name}
  %endif
%endif

%clean
%{__rm} -rf %{buildroot}

%preun
%if 0%{?suse_version}
  %if %suse_version > 1140
    %service_del_preun %{name}.service
  %else
    %stop_on_removal %{name}
  %endif
%else # fedora
  if [ $1 -eq 0 ] ; then
    %if 0%{?fedora_version} > 15
      /bin/systemctl stop %{name}.service > /dev/null 2>&1 || :
      /bin/systemctl --no-reload disable %{name}.service > /dev/null 2>&1 || :
    %else
      /sbin/service %{name} stop >/dev/null 2>&1
      /sbin/chkconfig --del %{name}
    %endif
  fi
%endif

%postun
%if 0%{?suse_version}
  %if %suse_version > 1140
    %service_del_postun %{name}.service
  %else
    %restart_on_update %{name}
    %insserv_cleanup
  %endif
%else # fedora
  %if 0%{?fedora_version} > 15
    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
    if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall
      /bin/systemctl try-restart %{name}.service >/dev/null 2>&1 || :
    fi
  %else
    if [ $1 -ge 1 ] ; then
      /sbin/service %{name} condrestart >/dev/null 2>&1 || :
    fi
  %endif
%endif

%files
%defattr(-, root, root, -)
%if 0%{?suse_version} > 1140 || 0%{?fedora_version} > 15 
/%{_unitdir}/%{name}.service
%else
  %if 0%{?suse_version}
    %{_sbindir}/rcrbldnsd
    %config %{_sysconfdir}/init.d/%{name}
  %else # fedora
    %config %{_sysconfdir}/rc.d/init.d/%{name}
  %endif
%endif
%if 0%{?suse_version}
  /var/adm/fillup-templates/sysconfig.rbldnsd
%else # fedora
  /etc/sysconfig/rbldnsd
%endif
%dir /var/lib/rbldnsd
%{_sbindir}/rbldnsd
%doc %{_mandir}/man8/rbldnsd.8*

%changelog
* Wed Jan 09 2013 Stefan Jakobs <stefan.jakobs@rus.uni-stuttgart.de> - 0.996c
- add ipv6 support
* Tue Oct 09 2012 Stefan Jakobs <stefan.jakobs@rus.uni-stuttgart.de> - 0.996b
- add systemd support
* Fri Mar 11 2011 Stefan Jakobs <stefan.jakobs@rus.uni-stuttgart.de> - 0.996b
- openSUSE >= 11.4 requires syslog and sysconfig to build
* Thu May 21 2010 Stefan Jakobs <stefan.jakobs@rus.uni-stuttgart.de> - 0.996b
- Initial release 1.0