%define CHROOTDIR %{_var}/spool/vscan
%define BASE_LIBS glibc,libgcc,expat,libstdc++,zlib,bzip2-libs,cracklib,cracklib-dicts
%define ARCHIVERS tar,arc,unace,unrar,rar,zoo,unarj,arj,unzip,zip,gzip,bzip2
%define ANTIVIRS clamav,clamav-libs,avglinux,nod32ls,nod32lfs,kav4mailservers-linux
%define ANTISPAMS bogofilter,qsf
%define CLAMAV_VERSION 0.92

Summary:   Antivir/antispam gateway for smtp server
Name:      sagator
Version:   %SAGATOR_VERSION%
Release:   %SAGATOR_RELEASE%%{?dist}
Source:    http://www.salstar.sk/pub/antivir/snapshots/sagator-%{version}%UNSTABLE_RELEASE%.tar.bz2
URL:       http://www.salstar.sk/sagator/
License:   GPLv2+
Group:     System Environment/Daemons
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: python-devel >= 2.2.2, ed, gettext
Requires:  %{name}-core = %{version}-%{release}
Requires:  python >= 2.2.2, sed
Requires:  spamassassin
%if %_vendor == "suse"
Requires:  clamav >= %{CLAMAV_VERSION}
%else
Requires:  clamav-lib >= %{CLAMAV_VERSION}
%endif

%description
This program is an email antivirus/antispam gateway. It is an interface to
the postfix, sendmail, or any other smtpd, which runs antivirus and/or
spamchecker. Its modular architecture can use any combination of
antivirus/spamchecker according to configuration.

It has some internal checkers (string_scanner and regexp_scanner). Sagator
can parse MIME mails and decompress archives, if it is configured so.

Features:
    * modular antivirus/spamchecker support
    * you don't need any perl modules or any other modules, only python
    * you can return any quarantined mail to mailq/user mailbox
    * mailbox/maildir scanning and cleaning
    * smtp policy service (greylist)
    * nice statistics via RRDTOOL or MRTG
    * web-quarantine access for users
    * daily reports for users
    * SQL database logging and configuration
    * simple chroot support

%package core
Summary:        Antivir/antispam gateway for smtp server, core files
Group:          System Environment/Daemons
Requires:       python >= 2.2.2, sed
%if %_vendor == "suse"
BuildRequires: aaa_base, python-xml, clamav >= %{CLAMAV_VERSION}
Requires:  aaa_base, smtp_daemon
%if 0%suse_version < 01030
Requires:  python-ctypes
%endif
%else
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires:       initscripts, smtpdaemon, shadow-utils
BuildRequires:  initscripts, logwatch, clamav-devel >= %{CLAMAV_VERSION}
Requires: clamav-lib >= %{CLAMAV_VERSION}
Requires: spamassassin
%endif
Obsoletes: sagator-libclamav <= 1.2.3
Obsoletes: sagator-pydspam <= 0.9.1

%description core
SAGATOR's core files. You can use this package separatelly, if you do
not to depend on other software, required by sagator.

%package webq
Summary:        SAGATOR's web quarantine access
Group:          System Environment/Daemons
Requires:       sagator-core = %{version}-%{release}, python-kid >= 0.9.5
BuildRequires:  python-kid

%description webq
SAGATOR's web quarantine access can be used to allow users (or admin)
to access their emails in sagator's quarantine.

# SElinux policy for Fedoras and RHEL>=5
%if 0%{?fedora} || 0%{?rhel} >= 5
%package        selinux
Summary:        SELinux support for SAGATOR
Group:          System Environment/Daemons
Requires:       %{name}-core = %{version}-%{release}
Requires(postun): policycoreutils, selinux-policy
BuildRequires: selinux-policy-devel
# SElinux directory and policy package
%define install_sepolicy 1
%define sepolicy %{_datadir}/%{name}/selinux/%{name}.pp

%description selinux
This package helps moving to the upstream SELinux module.

%else
%define install_sepolicy 0
%endif

%prep
%setup -q

%build
sh configure --prefix=%{_prefix} --filelist
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make DESTDIR=%{buildroot} PREFIX=%{_prefix} install
rm -f %{buildroot}%{_datadir}/sagator/etc/sgconf.py* \
  scripts/mkchroot.sh scripts/graphs/*.in
touch %{buildroot}%{_datadir}/%{name}/etc/sgconf.py_
ln -s ../../../..%{_sysconfdir}/sagator.conf \
  %{buildroot}%{_datadir}/%{name}/etc/sgconf.py
mkdir -p %{buildroot}%{CHROOTDIR}/tmp/quarantine
%find_lang %{name}

%pre core
getent group vscan >/dev/null || groupadd -r vscan
getent passwd vscan >/dev/null || \
useradd -r -g vscan -d %{CHROOTDIR} -s /sbin/nologin -c "SAGATOR" vscan
exit 0

%post core
touch %{_var}/lib/sagator-mkchroot
if [ $1 = 2 ]; then # upgrade
  [ -f %{_sysconfdir}/sysconfig/sagator ] && . %{_sysconfdir}/sysconfig/sagator || true
  # update configuration
  %{_datadir}/sagator/updatecfg.py || true
  if [ "$RESTART" = "auto" ]; then
    # restart sagator
    %{_initrddir}/sagator try-restart >/dev/null 2>&1 || true
  fi
else # install
  if [ -x /sbin/chkconfig ]; then
    chkconfig --add sagator
  elif [ -x /sbin/insserv ]; then
    insserv sagator
  fi
fi

%preun core
if [ $1 = 0 ]; then # uninstall
  # stop service
  %{_initrddir}/sagator stop >/dev/null 2>&1
  # remove init script symlinks
  if [ -x /sbin/chkconfig ]; then
    chkconfig --del sagator
  elif [ -x /sbin/insserv ]; then
    insserv -r sagator
  fi
fi

%if %{install_sepolicy}
%post selinux
if selinuxenabled; then
    # Replace the module by the upstream one
    #. /etc/selinux/config 2>/dev/null || :
    semodule -i %{sepolicy} 2>/dev/null || :
    # relabel files
    fixfiles -R %{name} restore || :
    # relabel chroot
    restorecon -R %{CHROOTDIR} || :
fi
%endif

%triggerin core -- sagator-webq,%{BASE_LIBS},%{ARCHIVERS},%{ANTIVIRS},%{ANTISPAMS}
touch %{_var}/lib/sagator-mkchroot

%triggerpostun core -- sagator-webq,%{BASE_LIBS},%{ARCHIVERS},%{ANTIVIRS},%{ANTISPAMS}
touch %{_var}/lib/sagator-mkchroot

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
# no files, this package just requires others

%files core -f filelist
%defattr(-,root,root)
%config(noreplace) %verify(not md5 size mtime) %attr(640,root,vscan) %{_sysconfdir}/%{name}.conf
%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/sysconfig/%{name}
%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/*/conf.d/%{name}.conf
%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/mrtg/%{name}.cfg
%{_initrddir}/%{name}
%config(noreplace) %verify(not md5 size mtime) %attr(644,root,root) %{_sysconfdir}/cron.d/%{name}
%doc doc/README doc/FAQ doc/*.txt doc/*.html TODO COPYING ChangeLog test
%doc scripts/db scripts/graphs scripts/*.sh
%{_bindir}/*
%{_sbindir}/*
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*.py*
%dir %attr(750,root,vscan) %{_datadir}/%{name}/etc
%{_datadir}/%{name}/etc/*.py*
%exclude %{_datadir}/%{name}/etc/sgconf.py?
%dir %{_datadir}/%{name}/av
%{_datadir}/%{name}/av/*.py*
%dir %{_datadir}/%{name}/av/libclamav
%{_datadir}/%{name}/av//libclamav/*.py*
%dir %{_datadir}/%{name}/as/pydspam
%{_datadir}/%{name}/as//pydspam/*.py*
%dir %{_datadir}/%{name}/as
%{_datadir}/%{name}/as/*.py*
%dir %{_datadir}/%{name}/interscan
%{_datadir}/%{name}/interscan/*.py*
%dir %{_datadir}/%{name}/srv
%{_datadir}/%{name}/srv/*.py*
%{_mandir}/man*/*
%dir %{CHROOTDIR}
%attr(1777,vscan,vscan) %dir %{CHROOTDIR}/tmp
%attr(0770,vscan,vscan) %dir %{CHROOTDIR}/tmp/quarantine

%files webq -f sagator.lang
%defattr(-,root,root)   
%dir %{_datadir}/%{name}/srv/web
%{_datadir}/%{name}/srv/web/*.py*
%{_datadir}/%{name}/srv/web/*.kid

%if %{install_sepolicy}
%files selinux
%defattr(-,root,root)   
%dir %{_datadir}/%{name}/selinux
%{sepolicy}
%endif

%changelog
* Wed Sep 17 2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk> - %SAGATOR_VERSION%-%SAGATOR_RELEASE%
- core files moved to core packages, sagator package now requires clamav
  and spamassassin
- added selinux policy dir

* Sun Feb 17 2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk> - 1.1.0-2
- changed dependency from smtpdaemon to server(smtp)
- reverted back previous change

* Sun Feb 17 2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk> - 1.1.0-1
- added libclamav module
- added pydspam module
- selinux module moved to separate subpackage

* Fri Jan 3 2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk> - 1.0.0-1
- /var/spool/vscan replaced by CHROOTDIR macro
- posttrans section moved to init script (start section)
- more macros used

* Thu Jan 3 2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk> - 1.0.0-2
- clean buildroot before install
- sagator.conf symlink is now relative

* Fri Sep 7 2007 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk> - 1.0.0-1
- sagator moved from /usr/lib to /usr/share

* Fri Apr 13 2007 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- added sagator.pp selinux policy file and post-install script

* Wed Dec 27 2006 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- added GPG public key

* Tue Sep 05 2006 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- added gcc build-require for suse package
- better build for unstable releases
- postfix autoconfigure messages
- crontab modification moved to /etc/cron.d/ directory
- mrtg triggers removed
- removed clamav a dspam stuff
- fixed permissions for sagator.conf
- postfix autoconfiguration moved into documentation

* Sun Nov 20 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- suse support
- proper pathes for logwatch 0.7 scripts

* Sun Aug 28 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- configuration moved into config directory

* Fri Aug 05 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- script documentation added

* Mon Jul 18 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- new description
- changed dependecy from postfix to smtpdaemon

* Sun Jun 26 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- changes recommended by Fedora Extras Packaging Guidelines

* Mon May 30 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- web directory added

* Mon Apr 11 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- postinstall script fix to update master.cf properly

* Mon Dec 20 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- Documentation moved into doc directory.
- man pages added
- dspam module

* Sun Nov  7 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- chkconfig is started only on install (not upgrade)
- sagator is restarted only when RESTART=auto is configured in sysconfig
- You will be able ... message will show only on install
- Fedora Core 3 yum.repos.d autodetect

* Thu Aug 26 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- logrotate script added

* Thu Aug  6 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- srv/* added
- updatecfg.py in postinstall script

* Tue Jul  6 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- mrtg script added

* Mon May 31 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- cron script is now as configuration script (not replaced)

* Thu Apr 29 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- added triggers

* Tue Apr 13 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- /var/spool/vscam/tmp permission fix

* Wed Feb  4 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- postfix requirement added
- fixed scriptlet fail when postfix is not started
- testing programs added to documentation

* Wed Jan 28 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- configs are not replaced

* Mon Jan 19 2004 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- added sysconfig file
- added logrotate files
- config moved into /etc and symlink into /usr/lib/sagator

* Fri Oct 31 2003 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- added mrtg.cfg and index.html
- making of chroot removed on upgrading

* Thu Sep 18 2003 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- postfix is not reloaded, when sagator is upgrading

* Tue Jun 10 2003 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
- first release
