%define ver 		0.1
%define rel 		1.nvi
%define name 		sa-conf
%define sacf 		/etc/mail/spamassassin
%define sauser		nospam
%define distserver 	rsync://bsd.falbi.kiev.ua/spamassassin

Summary: 	A Corvax's way to fight the spam
Name: 		%{name}
Version: 	%{ver}
Release:	%{rel}
URL:		http://bsd.falbi.kiev.ua/spamassassin
Group: 		System Environment/Daemons
License: 	GPL
BuildRoot: 	%{_tmppath}/%{name}-root
Source:		rules_sync
BuildPrereq: 	rsync
Requires: 	spamassassin >= 3.0
Vendor:		Victor Ustugov <victor@corvax.kiev.ua>
Packager:	Nikolai V. Ivanyushin <nvi@itadvisor.ru>
BuildArch:	noarch
Epoch: 		99999

%description
Additional rules to spamassassin

%prep

%build

%install
[ "$RPM_BUILD_ROOT" != "/" ] && %__rm -rf $RPM_BUILD_ROOT
%__mkdir -p $RPM_BUILD_ROOT%{sacf}/rules.{corvax,local}
%__mkdir -p $RPM_BUILD_ROOT%{_bindir}
%__cp %{SOURCE0} $RPM_BUILD_ROOT%{_bindir}
rsync -avz --delete %{distserver}/rules.local/ $RPM_BUILD_ROOT%{sacf}/rules.corvax/
										
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && %__rm -rf $RPM_BUILD_ROOT
%__rm -rf $RPM_BUILD_DIR/%{name}

%pre
%{_sbindir}/useradd -r -d /home/%{sauser} -M -s /sbin/nologin \
    -c 'SpamAssassin Daemon' %{sauser} 2>/dev/null
exit 0

																    

%post
if grep '-d -x -u %{sauser} -H /home/%{sauser}' /etc/sysconfig/spamassassin; then
	exit 0
	perl -pi -e 's/^SPAMDOPTIONS=/#SPAMDOPTIONS=/' /etc/sysconfig/spamassassin
	echo "SPAMDOPTIONS=\"-d -x -u %{sauser} -H /home/%{sauser} \"" >> \
	/etc/sysconfig/spamassassin
	%{_sbindir}/service spamassassin restart
fi

dst_dir=%{sacf}
link() {
    rules_order=$1
    rules_dir=$2
    rules=`find ${rules_dir}/ -name "*.cf"`
    if [ ! -z "${rules}" ]; then
        for rule in ${rules}; do
            rule_dir=`dirname ${rule}`
            rule_file=`basename ${rule}`
            ln -s ${rule_dir}/${rule_file} \
            ${dst_dir}/${rules_order}_${rule_file}
        done
    fi
}
find ${dst_dir}/ -type l | xargs rm -f
link 93 %{sacf}/rules.corvax 2>/dev/null
rm -rf ${dst_dir}/93*{test,corvax,falbi}.cf
link 94 %{sacf}/rules.local 2>/dev/null

%files
%defattr(-,root,root)
%{sacf}/rules.corvax/*
%config(missingok,noreplace) %{sacf}/rules.local
%{_bindir}

%changelog
* Mon Mar 21 2005 Nikolai V. Ivanyushin <nvi@itadvisor.ru> nvi
- initial build
