File postfixadmin.spec of Package postfixadmin23

# spec file for package postfixadmin
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

Name:           postfixadmin
Version:        2.3.8
Release:        0
Source0:        %{name}-%{version}.tar.gz

# changes from SVN 2.3 branch since the release
Patch:          postfixadmin-changes-since-2.3.8.diff

BuildArch:      noarch

# Web interface
%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_ver}
  # Requires:   mod_php_any # no idea in which fedora package mod_php5 is...
Requires:       php_database
Requires:       mod_php_any
Requires:       php_any_db
Recommends:     php-mysql

Requires:       /usr/sbin/sendmail
Requires:       php-mbstring
Requires:       php-spl

# test/*, xmlrpc.php, squirrelmail plugin
# big dependency, not needed by all users - therefore no hard Requirement
%if 0%{?suse_version}
Recommends:     php5-ZendFramework

Requires:       perl(DBI)
Requires:       perl(Email::Valid)
Requires:       perl(Getopt::Std)
Requires:       perl(Log::Log4perl)
Requires:       perl(MIME::Base64)
Requires:       perl(MIME::EncWords)
Requires:       perl(Mail::Sender)
Requires:       perl(strict)

Requires:       perl(File::Path)
Requires:       perl(Getopt::Long)
Requires:       perl(Fcntl)
Requires:       perl(IO)
Requires:       perl(IO::File)
Requires:       perl(POSIX)
Requires:       perl(Time::Local)
Requires:       perl(File::Temp)
Requires:       perl(LockFile::Simple)
Requires:       perl(Sys::Syslog)

%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_ver}
# create vacation user/group
PreReq:         shadow-utils
BuildRequires:  httpd-devel
#define serverroot %(/usr/sbin/apxs -q datadir 2>/dev/null || /usr/sbin/apxs -q PREFIX)/htdocs/
%define serverroot /var/www/html/
# create vacation user/group
PreReq:         pwdutils
BuildRequires:  apache2-devel
%define serverroot %(/usr/sbin/apxs2 -q datadir 2>/dev/null || /usr/sbin/apxs2 -q PREFIX)/htdocs/
Recommends:     postfix
Suggests:       php-pgsql

%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_ver}
# Do not check any files in ADDITIONS for Requires, see
%global __requires_exclude_from ^%{_prefix}/lib/%{name}/ADDITIONS/.*$
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

Summary:        Web-based management tool for Postfix virtual domains, mailboxes and aliases
License:        GPL-2.0+
Group:          Productivity/Networking/Web/Frontends

PostfixAdmin is a PHP based application that handles Postfix Style Virtual Domains and
Users that are stored in MySQL or PostgreSQL.

Postfix Admin supports:
- Virtual Mailboxes / Virtual Aliases / Forwarders
- Alias domains (Domain to Domain forwarding with recipient validation)
- Vacation (auto-response) for Virtual Mailboxes.
- Quota / Alias & Mailbox limits per domain.
- Fetchmail integration
- Packaged with over 25 languages.

%setup -q

echo "*** serverroot: %{serverroot} ***"

mkdir -p -m0755 %{buildroot}%{_sysconfdir}/%{name}
#mkdir -p -m0755 %{buildroot}%{_datadir}/%{name}
mkdir -p -m0755 %{buildroot}%{serverroot}/%{name}
mkdir -p -m0755 %{buildroot}%{_localstatedir}/spool/vacation
mkdir -p -m0755 %{buildroot}/%{_prefix}/lib/%{name}

# install the config files
#install -m 0640 %{buildroot}%{_sysconfdir}/%{name}/
#ln -s ../../../..%{_sysconfdir}/%{name}/ \
#    %{buildroot}%{_datadir}/%{name}/

install -m 0644 *.php motd*.txt %{buildroot}%{serverroot}/%{name}/

mv VIRTUAL_VACATION/ %{buildroot}%{_prefix}/lib/%{name}/
# compatibility symlink to match documentation
( cd %{buildroot}%{_localstatedir}/spool/vacation/ && ln -s ../../../usr/lib/%{name}/ )

# copy over the rest
for d in admin images languages model templates users css; do
    cp -rp $d %{buildroot}%{serverroot}/%{name}/

# remove files related to debian packaging (to avoid it's copied as %doc)
rm -r ADDITIONS/squirrelmail-plugin/debian/
cp -rp ADDITIONS %{buildroot}%{_prefix}/lib//%{name}/
chmod 755 %{buildroot}%{_prefix}/lib/%{name}/ADDITIONS/*.{pl,sh,py}

# install the config file
#mkdir -p %{buildroot}%{_sysconfdir}/apache2/conf.d
#install -m 644 $RPM_SOURCE_DIR/%{name}.conf \
#   %{buildroot}%{_sysconfdir}/apache2/conf.d/

%{_sbindir}/groupadd -r vacation 2> /dev/null || :
%{_sbindir}/useradd -c "Virtual Vacation" -d %{_localstatedir}/spool/vacation -s /sbin/nologin -M -r -g vacation vacation 2> /dev/null || :
# fix group for vacation user (if created by older versions (< 2012-02-13) of this package, it was created with group users)
%{_sbindir}/usermod -g vacation vacation 2> /dev/null || :

#if [ -z "`grep vacation /etc/postfix/ 2>/dev/null`" ]; then
#cat <<'EOF' >>/etc/postfix/
## Postfix Admin Vacation
#vacation	unix	-	n	n	-	-	pipe
#	flags=Rq user=vacation argv=/usr/lib/postfixadmin/ -f ${sender} -- ${recipient}

#if [ $1 = 0 ]; then
#    /usr/sbin/userdel vacation 2>/dev/null || :

#%config %dir %{_sysconfdir}/%{name}
#%attr(640,root,www) %config(noreplace) %{_sysconfdir}/%{name}/*.php
#%config(noreplace) %{_sysconfdir}/apache2/conf.d/*.conf
%dir %{_prefix}/lib/%{name}/
%attr( 750,root,vacation)       %{_prefix}/lib/%{name}/
%attr(1770,root,vacation) %dir %{_localstatedir}/spool/vacation