%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

Summary:   SAGATOR - antivir/antispam gateway for smtp server
Name:      sagator
Version:   0.9.1
Release:   1%{?dist}
Source:    http://www.salstar.sk/pub/antivir/snapshots/sagator-%{version}.tar.bz2
URL:       http://www.salstar.sk/pub/antivir/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, sed, make, gettext
Requires:  python >= 2.2.2, sed
%if %_vendor == "suse"
Requires:  aaa_base, smtp_daemon
BuildRequires: aaa_base
%else
Requires:  initscripts, smtpdaemon
BuildRequires: initscripts
%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:
    * simple chroot support
    * 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 mailbox cleaning
    * nice statistics via WWW or MRTG
    * easy installation

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

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

# SElinux directory and policy package
%define sedir %{_libdir}/%{name}/selinux
%define sepolicy %{sedir}/%{name}.pp

%prep
%setup -q

%build
./configure --prefix %{_prefix} --libdir %{_libdir} --filelist
make %{?_smp_mflags}

%install
make DESTDIR=%{buildroot} PREFIX=%{_prefix} install
rm -f %{buildroot}%{_libdir}/sagator/etc/sgconf.py[co]
mkdir -p %{buildroot}/var/spool/vscan/tmp/quarantine
if [ -e %{buildroot}%{sepolicy} ]; then
  echo "%dir %{sedir}" >> filelist
  echo "%doc %{sepolicy}" >> filelist
fi


%pre
id vscan > /dev/null 2>&1 || adduser -r -M vscan

%post
#exec &>/dev/null
# Adding postfix config
if [ $1 = 2 ]; then # upgrade
  [ -f /etc/sysconfig/sagator ] && . /etc/sysconfig/sagator || true
  # update configuration
  %{_libdir}/sagator/updatecfg.py || true
  if [ "$RESTART" = "auto" ]; then
    # restart sagator
    /etc/init.d/sagator condrestart || true
  fi
else # install
  if [ -x /sbin/chkconfig ]; then
    chkconfig --add sagator
  elif [ -x /sbin/insserv ]; then
    insserv sagator
  fi
  mkdir -p %{CHROOTDIR}
  /usr/sbin/mkchroot.sagator --auto
  # selinux
  [ ! -x /usr/sbin/semodule ] || [ ! -x /usr/sbin/sestatus ] || 
    [ ! -x /usr/sbin/selinuxenabled ] || ! /usr/sbin/selinuxenabled || \
      [ ! -e %{sepolicy} ] || \
        /usr/sbin/semodule -i %{sepolicy} \
          >/dev/null 2>/dev/null
fi

%preun
if [ $1 = 0 ]; then # uninstall
  if [ "$1" = 0 ] ; then
    # delete chroot (including quarantine and some stats)
    #[ "%{CHROOTDIR}" != "/" ] && rm -rf %{CHROOTDIR}/*
    # remove init script symlinks
    if [ -x /sbin/chkconfig ]; then
      chkconfig --del sagator
    elif [ -x /sbin/insserv ]; then
      insserv -r sagator
    fi
  fi
fi

%triggerin -- %{BASE_LIBS},%{ARCHIVERS},%{ANTIVIRS},%{ANTISPAMS}
/usr/sbin/mkchroot.sagator --auto --quiet || true

#%triggerpostun -- %{BASE_LIBS},%{ARCHIVERS},%{ANTIVIRS},%{ANTISPAMS}
#/usr/sbin/mkchroot.sagator --auto --quiet || true

%clean
rm -rf %{buildroot}

%files -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
%{_sysconfdir}/init.d/%{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/log scripts/*.sh
%{_bindir}/*
%{_sbindir}/*
%dir %{_libdir}/%{name}
%{_libdir}/%{name}/*.py*
%dir %attr(750,root,vscan) %{_libdir}/%{name}/etc
%{_libdir}/%{name}/etc/*.py*
%dir %{_libdir}/%{name}/av
%{_libdir}/%{name}/av/*.py*
%dir %{_libdir}/%{name}/as
%{_libdir}/%{name}/as/*.py*
%dir %{_libdir}/%{name}/interscan
%{_libdir}/%{name}/interscan/*.py*
%dir %{_libdir}/%{name}/srv
%{_libdir}/%{name}/srv/*.py*
%{_mandir}/man*/*
%dir /var/spool/vscan
%attr(1777,vscan,vscan) %dir /var/spool/vscan/tmp
%attr(0770,vscan,vscan) %dir /var/spool/vscan/tmp/quarantine
%if %(test -d %{_sysconfdir}/yum.repos.d && echo 1 || echo 0)
%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/yum.repos.d/%{name}.repo
%{_sysconfdir}/pki/rpm-gpg/SAGATOR-GPG-KEY
%endif

%files webq
%dir %{_libdir}/%{name}/srv/web
%{_libdir}/%{name}/srv/web/*.py*
%{_libdir}/%{name}/srv/web/*.kid
%{_datadir}/locale/*/LC_MESSAGES/%{name}.mo

%changelog
* 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
