###############################################################################
#
# General
#
###############################################################################

%define svnrevision	25734
%define php5_extdir	%php5_libdir/extensions
%define apachepath	%_sysconfdir/apache2/conf.d
%define webprefix	%_datadir/zarafa-webaccess
%define mobprefix	%_datadir/zarafa-webaccess-mobile
%define licensepath	%_docdir

Name: zarafa
Version: 7.0.0
Release: alt1
License: AGPLv3
Group: Networking/Mail
Summary: Server program for the Zarafa Collaboration Platform
Packager: Radik Usupov <radik@altlinux.org>
Url: http://www.zarafa.com/

Source: %name-%version.tar.gz
Patch: zarafa-7.0b3-alt-makefile.patch
Patch1: zarafa-7.0b3-alt-fix-build.patch
Patch2: zarafa-7.0b3-alt-use-init.alt.patch

BuildRequires(pre): rpm-build-php5
BuildRequires(pre): rpm-build-apache2
# Automatically added by buildreq on Fri Apr 15 2011
# optimized out: boost-devel boost-devel-headers libcom_err-devel libgpg-error libkrb5-devel libncurses-devel libstdc++-devel libtinfo-devel pkg-config python-base python-modules
BuildRequires: boost-filesystem-devel flex-old gcc-c++ libclucene-devel libical-devel libicu-devel libldap-devel libmysqlclient-devel
BuildRequires: libpam-devel libssl-devel libuuid-devel libvmime-devel libxml2-devel php5-devel rpm-build-python swig tzdata xmlto zlib-devel
BuildRequires: perl-CGI

Requires: zarafa-server = %version-%release
Requires: zarafa-client = %version-%release
Requires: zarafa-libs
Requires: zarafa-utils
Requires: zarafa-monitor
Requires: zarafa-spooler
Requires: zarafa-dagent
Requires: zarafa-ical
Requires: zarafa-gateway
Requires: zarafa-indexer

%description
The Zarafa Collaboration Platform (ZCP) combines the usability of
Outlook with the stability and flexibility of a Linux server. It
features a rich web-interface, the Zarafa WebAccess, and provides
brilliant integration options with all sorts of clients including
all most popular mobile platforms.

#'emacs colors

%package devel
Group: Development/C++
Summary: C++ development files for the Zarafa Collaboration Platform

%description devel
Development files to create MAPI aware programs under Linux.
Examples and documentation can be found on our website:
http://developer.zarafa.com/

%package devel-static
Group: Development/C++
Summary: C++ development files for the Zarafa Collaboration Platform

%description devel-static
Development files to create MAPI aware programs under Linux.
Examples and documentation can be found on our website:
http://developer.zarafa.com/

%package common
Group: Networking/Mail
Summary: Shared files between ZCP services

%description common
Common components for services of the Zarafa Collaboration Platform

%package server
Group: Networking/Mail
Summary: Server component for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release

%description server
The key component of the ZCP, providing the server to which ZCP
clients connect. The server requires a MySQL server to use for
storage.

%package client
Group: Networking/Mail
Summary: MAPI4Linux and the Zarafa MAPI provider libraries

%description client
The main libraries for any Zarafa client program. This package is
required by all Zarafa client programs.

%package libs
Group: Networking/Mail
Summary: Conversion libraries between Open Standards and MAPI
Requires: libvmime >= 0.9.2
Requires: libical >= 0.44

%description libs
Commonly used libraries by Zarafa Collaboration Platform client
programs.

%package libarchiver
Group: Networking/Mail
Summary: Library with shared ZCP archiver functionality
Requires: zarafa-client = %version-%release
Requires: zarafa-common = %version-%release

%description libarchiver
Library with shared archiver functionality for the Zarafa Collaboration Platform.

%package utils
Group: Networking/Mail
Summary: Admin command-line utils for the Zarafa Collaboration Platform
Requires: zarafa-client = %version-%release

%description utils
Commandline clients to control and check the ZCP server.

%package monitor
Group: Networking/Mail
Summary: Quota Monitor for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release
Requires: zarafa-client = %version-%release

%description monitor
Regularly checks stores for total usage. If a quota limit has been
exceeded, an e-mail will be internally sent to this account.

%package spooler
Group: Networking/Mail
Summary: E-mail Spooler for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release
Requires: zarafa-client = %version-%release
Requires: zarafa-libs = %version-%release

%description spooler
Sends all outgoing e-mail requests from Zarafa to an SMTP server.

%package dagent
Group: Networking/Mail
Summary: E-Mail Delivery Agent for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release
Requires: zarafa-client = %version-%release
Requires: zarafa-libs = %version-%release

%description dagent
Delivers incoming e-mail from your SMTP server to stores in the
Zarafa server.

%package gateway
Group: Networking/Mail
Summary: POP3 and IMAP Gateway for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release
Requires: zarafa-client = %version-%release
Requires: zarafa-libs = %version-%release

%description gateway
Provides access to the Zarafa server through the POP3 and IMAP
protocols.

%package ical
Group: Networking/Mail
Summary: ICal and CalDAV Gateway for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release
Requires: zarafa-client = %version-%release
Requires: zarafa-libs = %version-%release

%description ical
Provides access to the Zarafa server through the ICal and CalDAV
protocols.

%package -n python-module-mapi
Group: Networking/Mail
Summary: Python MAPI bindings
#By http://www.altlinux.org/Python_Policy
Requires: python = %_python_version
Requires: zarafa-client = %version-%release
Requires: zarafa-libs = %version-%release

%description -n python-module-mapi
Using this module, you can create python programs which use MAPI
calls to interact with Zarafa.

%package -n php5-mapi
Group: Networking/Mail
Summary: PHP MAPI bindings
Requires: zarafa-client = %version-%release
Requires: zarafa-libs = %version-%release
# add provide package name:
Provides: php(mapi) = %version-%release
Provides: php-mapi = %version-%release

%description -n php5-mapi
Using this module, you can create PHP programs which use MAPI
calls to interact with Zarafa.

%package indexer
Group: Networking/Mail
Summary: Indexer search engine for the Zarafa Collaboration Platform
Requires: zarafa-common = %version-%release
Requires: zarafa-client = %version-%release
Requires: zarafa-libarchiver = %version-%release
Requires: coreutils mktemp bash gawk lynx libxslt poppler unzip file catdoc

%description indexer
Based on the CLucene search engine, the zarafa-indexer makes an index
per user of messages and attachments. When this service is enabled,
search queries on the server will use this index to quickly find
messages and even in contents of attached documents.

# noarch packages
%package webaccess
Group: Networking/Mail
Summary: A web interface for the Zarafa Collaboration Platform
License: AGPLv3
Requires: php-mapi >= %version-%release apache2
Conflicts: zarafa-webaccess-ajax
Obsoletes: zarafa-webaccess-ajax

%description webaccess
Provides a web-client written in PHP that makes use of AJAX to allow
users to make full use of the Zarafa Collaboration Platform through a
modern web browser.

%package webaccess-mobile
Group: Networking/Mail
Summary: A mobile device optimized web interface to the Zarafa Collaboration Platform
License: AGPLv3
Requires: php5-mapi >= %version-%release apache2

%description webaccess-mobile
Allows user to manage their e-mail, calendar and contacts by simple
web browsers as found on older mobile devices.

#end noarch packages

###############################################################################
#
# Build
#
###############################################################################

%prep
%setup
%patch0 -p2
%patch1 -p2
%patch2 -p2

%build
%add_optflags -DBOOST_FILESYSTEM_VERSION=2
%configure --with-distro=alt \
	--prefix=%prefix \
	--sysconfdir=%_sysconfdir \
	--localstatedir=%_localstatedir \
	--libdir=%_libdir \
	--mandir=%_mandir \
	--with-userscript-prefix=%_sysconfdir/zarafa/userscripts \
	--with-quotatemplate-prefix=%_sysconfdir/zarafa/quotamail \
	--with-indexerscripts-prefix=%_datadir/zarafa/indexerscripts \
	--disable-static \
	--with-clucene-lib-prefix=%_libdir \
	--enable-unicode \
	--enable-tcmalloc \
	--with-tcmalloc-prefix=%_libdir \
	--enable-python \
	--disable-perl \
	--disable-swig \
	--enable-oss
%make_build

###############################################################################
#
# Install
#
###############################################################################

%install
%makeinstall_std

# move license files to doc dirs
	mkdir -p %buildroot%licensepath/%name
	cp %buildroot%_docdir/%name/AGPL-3 %buildroot%licensepath/%name/LICENSE
	for package in spooler gateway monitor dagent ical indexer devel client libs utils; do
		mkdir -p %buildroot%licensepath/%name-$package
		cp %buildroot%_docdir/%name/AGPL-3 %buildroot%licensepath/%name-$package/LICENSE
	done
	for package in php python; do
		mkdir -p %buildroot%licensepath/$package-mapi
		cp %buildroot%_docdir/%name/AGPL-3 %buildroot%licensepath/$package-mapi/LICENSE
	done

# move example-config files
	for package in spooler gateway monitor dagent ical indexer; do
		mkdir -p %buildroot%_docdir/%name-$package/example-config
		mv %buildroot%_docdir/%name/example-config/$package.cfg %buildroot%_docdir/%name-$package/example-config
	done
	mv %buildroot%_docdir/%name/example-config/autorespond %buildroot%_docdir/%name-dagent/example-config

# link userscripts in %_datadir/zarafa/userscripts
	mkdir -p %buildroot%_datadir/%name/userscripts
	for file in $(find %buildroot%_sysconfdir/%name/userscripts -maxdepth 1 -type f); do
		mv $file %buildroot%_datadir/%name/userscripts
		ln -sf %_datadir/%name/userscripts/$(basename $file) $file
	done
# link indexerscripts
	ln -sf %_datadir/%name/indexerscripts %buildroot%_sysconfdir/%name/indexerscripts

# add default empty directories
	mkdir -p %buildroot%_sysconfdir/%name/license
	mkdir -p %buildroot/var/log/%name

# fix libdir in server config for user plugins
	sed -e "s@%_libdir/zarafa@%_libdir/zarafa@" -i %buildroot%_sysconfdir/%name/server.cfg

#NOARCH
# install webaccess
%makeinstall_std install-ajax-webaccess
%makeinstall_std install-mobile-webaccess

# install ajax apache config
	mkdir -p %buildroot%apachepath
	mv %buildroot%webprefix/%name-webaccess.conf %buildroot%apachepath

# install mobile apache config
	mkdir -p %buildroot%apachepath
	mv %buildroot%mobprefix/%name-webaccess-mobile.conf %buildroot%apachepath

# remove debug files
rm %buildroot%_libdir/libzarafaclient.la %buildroot%_libdir/%name/*.la
rm %buildroot%_libdir/python2.6/site-packages/*.la
rm %buildroot/etc/rc.d/%name-*

###############################################################################
#
# Scripts
#
###############################################################################

%post server
%preun server
%postun server
%post spooler
%preun spooler
%postun spooler
%post dagent
%preun dagent
%postun dagent
%post gateway
%preun gateway
%postun gateway
%post monitor
%preun monitor
%postun monitor
%post ical
%preun ical
%postun ical
%post indexer
%preun indexer
%postun indexer
###############################################################################
#
# File list
#
###############################################################################

%files
%files common
%dir %_datadir/%name/
%dir %_sysconfdir/%name
%dir %_logdir/%name
%config %attr(0644,root,root) %_sysconfdir/logrotate.d/%name

%files server
%_bindir/%name-server
%_bindir/%name-msr
%_libdir/%name/dbplugin.so
%_libdir/%name/unixplugin.so
%_libdir/%name/ldapplugin.so
%_sysconfdir/sysconfig/%name
%dir %_docdir/%name/
%_docdir/%name/*
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/ldap.active-directory.cfg
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/ldap.openldap.cfg
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/ldap.propmap.cfg
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/unix.cfg
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/server.cfg
%dir %_sysconfdir/%name/userscripts
%attr(0755,root,root) %_sysconfdir/%name/userscripts/createcompany
%attr(0755,root,root) %_sysconfdir/%name/userscripts/creategroup
%attr(0755,root,root) %_sysconfdir/%name/userscripts/createuser
%attr(0755,root,root) %_sysconfdir/%name/userscripts/deletecompany
%attr(0755,root,root) %_sysconfdir/%name/userscripts/deletegroup
%attr(0755,root,root) %_sysconfdir/%name/userscripts/deleteuser
%attr(0644,root,root) %_sysconfdir/%name/userscripts/*common.sh
%dir %_sysconfdir/%name/userscripts/createuser.d
%dir %_sysconfdir/%name/userscripts/creategroup.d
%dir %_sysconfdir/%name/userscripts/createcompany.d
%dir %_sysconfdir/%name/userscripts/deleteuser.d
%dir %_sysconfdir/%name/userscripts/deletegroup.d
%dir %_sysconfdir/%name/userscripts/deletecompany.d
%config(noreplace) %attr(0755,root,root) %_sysconfdir/%name/userscripts/createuser.d/*
%config(noreplace) %attr(0755,root,root) %_sysconfdir/%name/userscripts/createcompany.d/*
%dir %_datadir/%name/userscripts
%attr(0755,root,root) %_datadir/%name/userscripts/createcompany
%attr(0755,root,root) %_datadir/%name/userscripts/creategroup
%attr(0755,root,root) %_datadir/%name/userscripts/createuser
%attr(0755,root,root) %_datadir/%name/userscripts/deletecompany
%attr(0755,root,root) %_datadir/%name/userscripts/deletegroup
%attr(0755,root,root) %_datadir/%name/userscripts/deleteuser
%attr(0644,root,root) %_datadir/%name/userscripts/*common.sh
%config %attr(0755,root,root)  %_initdir/%name-server
%_man1dir/%name-server.1*
%_man1dir/%name-msr.1*
%_man1dir/%name-archiver.1*
%_man1dir/%name-backup.1*
%_man1dir/%name-licensed.1*
%_man1dir/%name-report.1*
%_man1dir/%name-restore.1*
%_man1dir/%name.1*
%_man5dir/%name-ldap.cfg.5*
%_man5dir/%name-server.cfg.5*
%_man5dir/%name-msr.cfg.5*
%_man5dir/%name-unix.cfg.5*
%_man5dir/%name-archiver.cfg.5*
%_man5dir/%name-ldapms.cfg.5*
%_man5dir/%name-licensed.cfg.5*
%dir %licensepath/%name
%licensepath/%name/LICENSE

%files devel
%_libdir/libarchiver.so
%_libdir/libmapi.so
%_libdir/libicalmapi.so
%_libdir/libinetmapi.so
%dir %_includedir/mapi4linux
%_includedir/mapi4linux/*
%dir %_includedir/zarafa
%_includedir/zarafa/*
%dir %_includedir/inetmapi
%_includedir/inetmapi/*
%dir %_includedir/icalmapi
%_includedir/icalmapi/*
%dir %_includedir/libfreebusy
%_includedir/libfreebusy/*
%dir %_includedir/libzarafasync
%_includedir/libzarafasync/*
%_pkgconfigdir/zarafa.pc
%dir %licensepath/%name-devel
%licensepath/%name-devel/LICENSE

%files devel-static
%_libdir/libcommon_mapi.a
%_libdir/libcommon_util.a
%_libdir/libcommon_ssl.a
%_libdir/libfreebusy.a
%_libdir/libzarafasync.a

%files client
%_libdir/libmapi*.so.*
%_libdir/libzarafaclient*.so*
%_datadir/locale/*/LC_MESSAGES/*mo
%dir %licensepath/%name-client
%licensepath/%name-client/LICENSE

%files libs
%_libdir/libicalmapi*.so.*
%_libdir/libinetmapi*.so.*
%_libdir/python2.6/site-packages/*.egg-info
%_libdir/python2.6/site-packages/zarafalib/*.py*
%dir %licensepath/%name-libs
%licensepath/%name-libs/LICENSE

%files libarchiver
%_libdir/libarchiver*.so.*

%files utils
%_bindir/%name-admin
%_bindir/%name-cfgchecker
%_bindir/%name-fsck
%_bindir/%name-passwd
%_bindir/%name-stats
%_man1dir/%name-admin.1*
%_man1dir/%name-cfgchecker.1*
%_man1dir/%name-fsck.1*
%_man1dir/%name-passwd.1*
%_man1dir/%name-stats.1*
%dir %licensepath/%name-utils
%licensepath/%name-utils/LICENSE

%files monitor
%_bindir/%name-monitor
%dir %_sysconfdir/%name/quotamail
%config(noreplace) %attr(0644,root,root) %_sysconfdir/%name/quotamail/*
%config %attr(0755,root,root) %_initdir/%name-monitor
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/monitor.cfg
%_man1dir/%name-monitor.1*
%_man5dir/%name-monitor.cfg.5*
%dir %_docdir/%name-monitor/
%_docdir/%name-monitor/*
%dir %licensepath/%name-monitor
%licensepath/%name-monitor/LICENSE

%files spooler
%_bindir/%name-spooler
%config %attr(0755,root,root) %_initdir/%name-spooler
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/spooler.cfg
%_man1dir/%name-spooler.1*
%_man5dir/%name-spooler.cfg.5*
%dir %_docdir/%name-spooler/
%_docdir/%name-spooler/*
%dir %licensepath/%name-spooler
%licensepath/%name-spooler/LICENSE

%files dagent
%_bindir/%name-autorespond
%_bindir/%name-dagent
%config %attr(0755,root,root) %_initdir/%name-dagent
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/dagent.cfg
%verify(not mode) %config(noreplace) %attr(0644,root,root) %_sysconfdir/%name/autorespond
%_man1dir/%name-dagent.1*
%_man5dir/%name-dagent.cfg.5*
%dir %_docdir/%name-dagent/
%_docdir/%name-dagent/*
%dir %licensepath/%name-dagent
%licensepath/%name-dagent/LICENSE

%files gateway
%_bindir/%name-gateway
%config %attr(0755,root,root) %_initdir/%name-gateway
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/gateway.cfg
%_man1dir/%name-gateway.1*
%_man5dir/%name-gateway.cfg.5*
%dir %_docdir/%name-gateway/
%_docdir/%name-gateway/*
%dir %licensepath/%name-gateway
%licensepath/%name-gateway/LICENSE

%files ical
%_bindir/%name-ical
%config %attr(0755,root,root) %_initdir/%name-ical
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/ical.cfg
%_man1dir/%name-ical.1*
%_man5dir/%name-ical.cfg.5*
%dir %_docdir/%name-ical/
%_docdir/%name-ical/*
%dir %licensepath/%name-ical
%licensepath/%name-ical/LICENSE

%files -n php5-mapi
%dir %php5_sysconfdir/cli/php.d
%config(noreplace) %php5_sysconfdir/cli/php.d/%name.ini
%php5_extdir/mapi*
%php5_datadir/mapi/*
%dir %licensepath/php-mapi
%licensepath/php-mapi/LICENSE

%files indexer
%_bindir/%name-indexer
%config %attr(0755,root,root) %_initdir/%name-indexer
%verify(not mode) %config(noreplace) %attr(0640,root,root) %_sysconfdir/%name/indexer.cfg
%_sysconfdir/%name/indexerscripts
%dir %_datadir/%name/indexerscripts
%_datadir/%name/indexerscripts/attachments_parser
%_datadir/%name/indexerscripts/attachments_parser.db
%_datadir/%name/indexerscripts/xmltotext.xslt
%_datadir/%name/indexerscripts/zmktemp
%_man1dir/%name-indexer.1*
%_man5dir/%name-indexer.cfg.5*
%dir %licensepath/%name-indexer
%licensepath/%name-indexer/LICENSE
%dir %_docdir/%name-indexer/
%_docdir/%name-indexer/*

%files -n python-module-mapi
%_libdir/python*/*/*.py*
%_libdir/python*/*/*.so
%_libdir/python*/*/MAPI/
%dir %licensepath/python-mapi
%licensepath/python-mapi/LICENSE

# noarch package files

%files webaccess
#is this the correct prefix now?
%dir %webprefix/
# add writeable temp dir
%dir %_localstatedir/%name-webaccess
%dir %_localstatedir/%name-webaccess/plugins
%attr(-,www-data,www-data) %dir %_localstatedir/%name-webaccess/tmp
%webprefix/.htaccess
%webprefix/*
%config %dir %_sysconfdir/%name/webaccess-ajax
%config(noreplace) %_sysconfdir/%name/webaccess-ajax/config.php
%config(noreplace) %apachepath/%name-webaccess.conf

%files webaccess-mobile
%dir %mobprefix/
# add writeable temp dir
%dir %_localstatedir/%name-webaccess-mobile
%attr(-,www-data,www-data) %dir %_localstatedir/%name-webaccess-mobile/config
%attr(-,www-data,www-data) %dir %_localstatedir/%name-webaccess-mobile/cache
%attr(-,www-data,www-data) %dir %_localstatedir/%name-webaccess-mobile/templates_c
%mobprefix/.htaccess
%mobprefix/*
%config %dir %_sysconfdir/%name/webaccess-mobile
%config(noreplace) %_sysconfdir/%name/webaccess-mobile/config.php
%config(noreplace) %apachepath/%name-webaccess-mobile.conf

# end noarch files

%changelog
* Mon Apr 11 2011 Radik Usupov <radik@altlinux.org> 7.0.0-alt1
- initial build for ALT Linux Sisyphus
