File sympa.spec of Package sympa

%define archive_version 5.2.3
%define version %{archive_version}.0
%define lib_s	%{_libdir}/sympa
%define data_s	%{_datadir}/sympa
%define conf_s	%{_sysconfdir}/sympa
%define home_s	%{_localstatedir}/sympa
%define spool_s	/var/spool/sympa
%define log_s /var/log/sympa
# ugly...
%define exceptions perl(\\(Archive\\|Commands\\|Conf\\|Language\\|Ldap\\|List\\|Log\\|Marc.*\\|Message\\|SympaTransport\\|Version\\|X509\\|cookielib\\|mail\\|smtp\\|wwslib\\|.*\.pl\\))
%define _provides_exceptions %{exceptions}
%define _requires_exceptions %{exceptions}

Summary:	SYMPA is an electronic mailing list manager
Name:		sympa
Version:	%{version}
Release:	0
License:	GPL
Group:		Productivity/Networking/Email/Mailinglists
Source0:	%{name}-%{archive_version}.tar.bz2
#Patch0:	sympa-3.2.1-gprintify.patch.bz2
URL:		http://www.sympa.org/
Requires:	openssl >= 0.9.5a
Requires:	MHonArc >= 2.4.5
Requires:	perl-MailTools
Requires:	mail-server
Requires:	apache >= 2.0.54
Requires:	apache-mod_fastcgi
Requires:	perl-CGI-Fast
Requires:	perl-Crypt-CipherSaber
Requires:	perl-Template
Requires(pre,postun):	rpm-helper
Requires(pre):	mail-server
#BuildRequires:	apache-base >= 2.0.54-5mdk
BuildRequires:	apache2 >= 2.0.54
BuildRequires:	openssl-devel >= 0.9.5a
BuildRequires:	perl-MailTools, perl-libintl-perl
BuildRoot:	%{_tmppath}/%{name}-%{version}

%description
SYMPA is an electronic mailing list manager. It is used to automate list
management functions such as subscription, moderation and management of 
archives. SYMPA also manages sending of messages to the lists, and 
makes it possible to reduce the load on the system. Provided that you 
have enough memory on your system, Sympa is especially well adapted for big 
lists. For a list with 20 000 subscribers, it takes 5 minutes to send a
message to 90% of subscribers, of course considering that the network is 
available.

Documentation is available under HTML and SGML (source) formats. 

%prep

%setup -q -n %name-%{archive_version}
#%patch0 -p1 -b .gprintify
perl -pi -e 's/^\\r sympa//' src/etc/script/create_db.mysql

## strip away annoying ^M
#find . -type f|xargs file|grep 'CRLF'|cut -d: -f1|xargs perl -p -i -e 's/\r//'
#find . -type f|xargs file|grep 'text'|cut -d: -f1|xargs perl -p -i -e 's/\r//'

#%serverbuild
./configure \
	--prefix=%{_prefix} \
	--with-mandir=%{_mandir} \
	--with-confdir=%{_sysconfdir}/%name \
	--with-etcdir=%{_sysconfdir}/%name \
	--with-cgidir=%{_var}/www/fcgi-bin \
	--with-iconsdir=%{_var}/www/icons/%name \
	--with-bindir=%{lib_s}/bin \
	--with-sbindir=%{lib_s}/bin \
	--with-libexecdir=%{lib_s}/bin \
	--with-libdir=%{lib_s}/lib \
	--with-datadir=%{data_s} \
	--with-expldir=%{home_s}/expl \
	--with-piddir=/var/run/sympa \
	--with-nlsdir=%{lib_s}/nls \
	--with-scriptdir=%{data_s}/examples/script \
	--with-sampledir=%{data_s}/examples/sample \
	--with-spooldir=%{spool_s} \
	--with-sendmail_aliases=/etc/aliases \
	--with-initdir=%{_initrddir} \
	--with-docdir=%{_docdir}/%name

%build
make sources

%install
rm -rf %{buildroot}

# Fix owner/group in filelist
#for i in src/Makefile wwsympa/Makefile Makefile soap/Makefile src/etc/sample/Makefile; do
for i in `find . -name '*Makefile*' -type f`;do
    perl -pi -e "s|chown|/bin/true|" $i
    perl -pi -e "s|chgrp|/bin/true|" $i
done

# Actually chmod the files but not the directory!
perl -pi -e "s|chmod -R 644(.+wws_templates)|chmod 644 \1/*|" ./wwsympa/Makefile

%makeinstall

# Fix permissions
chmod 0644 %{buildroot}%{_mandir}/man8/*.8
chmod 0644 %{buildroot}%{data_s}/ca-bundle.crt
#chmod 0644 %{buildroot}%{data_s}/mhonarc-ressources

# Remove docs in bad directory
#rm -rf %{buildroot}%{lib_s}/doc
#cp -a doc/html doc/sympa

# Create bounce and archive incoming directories
for dir in bounce arc; do
  mkdir -p %{buildroot}%{spool_s}/$dir
done

# Create bounce and archive storage directories
for dir in bounce arc; do
  mkdir -p %{buildroot}%{home_s}/$dir
done

# Create PID directory
mkdir -p %{buildroot}/var/run/sympa

# Populate config directory
#for dir in create_list_templates scenari wws_templates templates; do
 # mkdir -p %{buildroot}%{conf_s}/$dir
#done

cat >> %{buildroot}/etc/sympa/sympa.conf <<EOF
## Temporary directory
tmpdir		%{spool_s}
EOF

# Dispatch config samples and fix permissions
mkdir -p %{buildroot}%{data_s}/examples/config
mv %{buildroot}%{data_s}/examples/sample/{,ww}sympa.conf \
   %{buildroot}%{data_s}/examples/config/
chmod 0644 %{buildroot}%{data_s}/examples/config/*.conf

# Move DB scripts to examples/db
mkdir -p %{buildroot}%{data_s}/examples/db
mv %{buildroot}%{data_s}/examples/script/create_db.* \
   %{buildroot}%{data_s}/examples/db/

# log directory
mkdir -p %{buildroot}/%{log_s}

# logrotate
install -d m 755 %{buildroot}%{_sysconfdir}/logrotate.d
cat > %{buildroot}%{_sysconfdir}/logrotate.d/%{name} <<EOF
/var/log/sympa {
	missingok
	notifempty
	copytruncate
}
EOF

# Apache configuration
install -d -m 755 %{buildroot}%{_sysconfdir}/httpd/conf/webapps.d
cat >%{buildroot}%{_sysconfdir}/httpd/conf/webapps.d/%{name}.conf <<EOF
AddHandler cgi-script .fcgi .cgi .pl .sh
Alias /wwsicons /var/www/icons/sympa
ScriptAlias /wws /var/www/fcgi-bin/wwsympa.fcgi
EOF

# sendmail  secure shell
#install -d -m 755 %{buildroot}%{_sysconfdir}/smrsh
install -d -m 755 $RPM_BUILD_ROOT/etc/smrsh
#ln -s %{home_s}/bin/queue %{buildroot}%{_sysconfdir}/smrsh/%{name}
#ln -s ../../bin/queue $RPM_BUILD_ROOT%{_sysconfdir}/smrsh/%{name}

%pre
%_pre_useradd %{name} %{home_s} /bin/false

# Add "apache" in group "sympa" so that it could access
# /etc/sympa/wwsympa.conf and therefore a working wwsympa ;-)
groups=`groups apache | cut -d " " -f 4- | tr ' ' ,`
if [ -n "$groups" ]; then
	groups="$groups,sympa"
else
	groups="sympa";
fi
usermod -G $groups apache

%post
%_post_service %{name}
%_post_webapp

if [ $1 = 1 ]; then
  # installation

  # Setup log facility for Sympa
  cntlog=0
  while [ `grep -c local${cntlog} /etc/syslog.conf` -gt 0 ];do cntlog=$((cntlog+1));done
  if [ ${cntlog} -le 9 ];then
    # syslog configuration
  cat >> %{_sysconfdir}/syslog.conf <<EOF
# added by %{name}-%{version} rpm $(date)
local${cntlog}.*	-%{log_s}/sympa.log
EOF
    /sbin/service syslog reload

    # sympa configuration
    perl -pi -e "s|syslog(\s+)LOCAL[0-9]+|syslog\1LOCAL${cntlog}.*|" /etc/sympa/sympa.conf
  fi    

  # create log file
  # %create_ghostfile /var/log/sympa sympa sympa 640
  # create directory and log file
  %create_ghostfile %{log_s}/sympa.log sympa sympa 640

  # Try to add some sample entries in /etc/aliases for sympa
  cat >> %{_sysconfdir}/aliases <<EOF
# added by %{name}-%{version} rpm $(date)
listmaster:	"|%{lib_s}/bin/queue listmaster"
sympa:		"|%{lib_s}/bin/queue sympa"
bounce+*:	"|%{lib_s}/bin/bouncequeue sympa"
sympa-request:	listmaster@${HOSTNAME}
sympa-owner:	listmaster@${HOSTNAME}
EOF
  /usr/bin/newaliases

  # hostname configuration
  perl -pi -e "s|MY_HOST|$ENV{HOSTNAME}|g" /etc/sympa/*.conf
fi

%preun
%_preun_service %{name}

if [ $1 = 0 ]; then
  # uninstallation

  # clean syslog
  sed -i \
    -e '/^# added by %{name}/d' \
    -e '/^local[0-9]	\/var\/log\/%{name}$/d' \
    %{_sysconfdir}/syslog.conf
  /sbin/service syslog reload

  # clean aliases
  sed -i \
    -e '/^# added by %{name}/d' \
    -e '/^listmaster:/d' \
    -e '/^sympa:/d' \
    -e '/^bounce+\*:/d' \
    -e '/^sympa-request:/d' \
    -e '/^sympa-owner:/d' \
    %{_sysconfdir}/aliases
  /usr/bin/newaliases
fi

%postun
%_postun_userdel %{name}
%_postun_webapp

%files
%defattr(-,sympa,sympa)

# Home directory
%{home_s}

# Spools
%{spool_s}

# PID directory
/var/run/sympa

# Config files
%dir /etc/sympa
%config(noreplace) /etc/sympa/sympa.conf
%config(noreplace) /etc/sympa/wwsympa.conf
%config(noreplace) %{_sysconfdir}/httpd/conf/webapps.d/%{name}.conf

# sendmail secure shell link
#%{_sysconfdir}/smrsh/%{name}

# Config directories populated by the user
%{conf_s}/create_list_templates
%{conf_s}/scenari
%{conf_s}/task_models
%{conf_s}/web_tt2
%{conf_s}/mail_tt2
%{conf_s}/general_task_models
#%{conf_s}/templates
#%{conf_s}/wws_templates

%defattr(-,root,root)
# Init scripts
%config(noreplace) %{_initrddir}/%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}

# Binaries
%dir %{lib_s}
%dir %{lib_s}/bin
%attr(-,sympa,sympa) %{lib_s}/bin/queue
%attr(-,sympa,sympa) %{lib_s}/bin/bouncequeue
%{lib_s}/bin/*.pl
%{lib_s}/bin/aliaswrapper
%{lib_s}/bin/virtualwrapper
%{lib_s}/lib

# Locales
#%{lib_s}/nls
/usr/locale/*/LC_MESSAGES/sympa.mo

# Data
%{data_s}

# Logs
%dir %{log_s}

# Icons and binaries for Apache
%{_var}/www/fcgi-bin/wwsympa.fcgi
%attr(-,sympa,sympa) %{_var}/www/fcgi-bin/sympa_soap_server.fcgi
%{_var}/www/icons/sympa

# Documentation
%doc COPYING README NEWS KNOWNBUGS
%{_mandir}/man8/*
%doc %{_docdir}/sympa/*

%clean
rm -rf %{buildroot}

%changelog
openSUSE Build Service is sponsored by