File netqmail.spec of Package netqmail

#
# spec file for package netqmail
#
# Copyright (c) 2012-2015,2017 Peter Conrad <obs@quisquis.de>
#
# 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 http://bugs.opensuse.org/

%define	qmail_home	%{_localstatedir}/lib/qmail

%if 0%{?suse_version} < 1000
%define defined()       %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%define undefined()     %{expand:%%{?%{1}:0}%%{!?%{1}:1}}
%endif
%if 0%{?suse_version} >= 1200 || 0%{?fedora} >= 16
%if %{undefined _unitdir}
%define	_unitdir	%(pkg-config --variable=systemdsystemunitdir systemd)
%endif
%endif
%if 0%{?fedora}
%define ext_man .gz
%endif

Summary: QMail mail transport and delivery system
Name: netqmail
Version: 1.06
Release: 9
URL: http://qmail.org/
License: MIT and GPL-2.0
Group: Productivity/Networking/Email/Servers
# netqmail is PD + MIT
#Source: http://qmail.speedbone.de/netqmail-%%{version}.tar.gz
Source: netqmail-%{version}.tar.bz2
# This patch is GPL + PD
Source1: http://www.ezmlm.org/archive/patches/qmail-verh-0.07.tar.gz
# GPL
Source2: http://www.ezmlm.org/pub/patches/qmail-mime.tgz
# Own creation
Source3: qmail-send-initscript
# Own creation
Source4: tcprules.smtpd
# GPL
Source5: http://download.sourceforge.net/qmail-spp/qmail-spp-0.42.tar.gz
# Own creation
Source6: smtpplugins
# Own creation
Source7: %{name}-rpmlintrc
# Own creation
Source8: genkey.sh
# GPL
Source9: https://manuel.mausz.at/coding/qmail-dkim/qmail-dkim-0.3.pl
# Own creation
Source10: qmail-mtp-initscript
# Own creation
Source11: auto_uids.c
# Own creation
Source12: auto_uids.h
# Own creation
Source13: qmail-tls.cron
# Own creation
Source14: qmail-permissions
# Own creation
Source15: qmail-permissions.paranoid
# GPL(?)
Source16: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# Own creation
Source17: qmail-qmtp-initscript
# Own creation
Source18: README.SUSE
# Own creation
Source19: signconf.xml
# Own creation
Source20: qmail-pop3-initscript
# Own creation
Source21: dkim-genkey.sh
# Own creation, GPL
Source22: apparmor.qmail-clean
# Own creation, GPL
Source23: apparmor.qmail-remote
# Own creation, GPL
Source24: apparmor.qmail-rspawn
# Own creation, GPL
Source25: apparmor.qmail-lspawn
# Own creation, GPL
Source26: apparmor.qmail-remote.real
# Own creation, GPL
Source27: apparmor.splogger
# Own creation, GPL
Source28: apparmor.start-pop3-tcpserver
# Own creation, GPL
Source29: start-pop3-tcpserver
# Own creation, GPL
Source30: dkim-genkey.8
# Own creation, GPL
Source31: netqmail-pop3d.service
# Own creation, GPL
Source32: netqmail-pop3d.socket
# Own creation, GPL
Source33: netqmail-qmtpd.service
# Own creation, GPL
Source34: netqmail-qmtpd.socket
# Own creation, GPL
Source35: netqmail.service
# Own creation, GPL
Source36: netqmail-smtpd.service
# Own creation, GPL
Source37: netqmail-smtpd.socket
# Own creation, GPL
Source38: apparmor.qmail-popup
# Own creation, GPL
Source39: pop3.pam
# Own creation, GPL
Source40: qmail-smtpd.suse-fw
# Own creation, GPL
Source41: qmail-qmtpd.suse-fw
# Own creation, GPL
Source42: qmail-pop3d.suse-fw
# Own creation, GPL
Source43: sysconfig.netqmail
# Own creation, GPL
Source44: netqmail-users.conf
# unknown copyright status
#Patch1: http://qmail.lightwerk.com/qmail-1.03-qmtpc.patch
# PD
Patch2: http://thedjbway.b0llix.net/qmail/patches/qmail-1.03.qmtpd-netstring.patch
# MIT
# http://www.memoryhole.net/qmail/patch-qmail-1.03-rfc2821.diff
Patch5: qmail-1.03-rfc2821-tls.patch
# unknown copyright status
#Patch10: http://homepages.tesco.net./~J.deBoynePollard/Softwares/qmail/smtpd-no-http.patch
# GPL
#Patch12: http://inoa.net/qmail-tls/netqmail-1.06-tls-20200107.patch
Patch12: netqmail-1.06-tls-20200107-local.patch
# Own creation
Patch13: qmail-1.05-tls-openssl098l.patch
# Own creation
Patch14: netqmail-1.06-types.patch
# Own creation, inspired by http://homepages.tesco.net./~J.deBoynePollard/Softwares/qmail/#smtpd-502-to-500
Patch15: qmail-smtpd-502.patch
# Own creation
Patch16: qmail-dkim.patch
# Own creation
Patch17: netqmail-1.06-ipv6.patch
# Own creation, GPL
Patch18: netqmail-1.06-tls-fixes.patch
# Kinda public domain, with local modifications
Patch19: netqmail-1.06-authentication075-pc.patch
# Own creation, GPL
Patch20: netqmail-cname.patch
Requires(pre): group(mail)
Requires: openssl perl-Mail-DKIM
Requires(pre): hostname
Requires(pre): systemd
%if 0%{?fedora} == 0
Requires(pre): pwdutils
Requires(post): permissions
Requires: cron
%else
Requires(pre): shadow-utils
%if 0%{?fedora} < 20
Requires: vixie-cron
%endif
%endif
%if %{defined insserv_prereq} && %{undefined _unitdir}
Requires(pre): %insserv_prereq
%endif
%if %{defined fillup_prereq}
Requires(pre): %fillup_prereq
%endif
%sysusers_requires
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: libopenssl-devel libsyncdir daemontools ucspi-tcp
%if 0%{?suse_version} >= 1140 || 0%{?sles_version} >= 11
BuildRequires: apparmor-profiles
%endif
%if %{undefined _unitdir}
Requires: daemontools
%endif
%if %{defined _unitdir}
Requires: systemd
BuildRequires: systemd-devel, pkg-config
%if 0%{?suse_version} >= 1210
BuildRequires:	systemd-rpm-macros
%endif
%{?systemd_requires}
%endif
%if 0%{?suse_version} > 0 && 0%{?suse_version} <= 1500
BuildRequires:	SuSEfirewall2
%endif
BuildRequires:	cron
BuildRequires:  sysuser-tools

%description
qmail is a modern SMTP server which makes sendmail obsolete, written by Dan
Bernstein, who also has a web page for qmail. qmail is a secure package. There
was a $1,000.00 prize for anyone who can show otherwise, which went unclaimed. 

netqmail is derived from Daniel Bernstein's qmail-1.03 plus bug fixes, a few
feature enhancements, and some documentation.

This package adds even more features and enhancements:

- support for STARTTLS
- FHS + LSB compliance
- qmail-spp SMTP plugin support
- DKIM signatures of outgoing mails (requires libdkim)
- support for sending mail via IPv6
- support for SMTP-AUTH (RFC-3848 & RFC-4945) using a modified version of
  Erwin Hoffmann's qmail-authentication patch

%package smtpd
Summary: Simple Mail Transfer Protocol Daemon for QMail
Group: Productivity/Networking/Email/Servers
Requires: netqmail daemontools
Provides: smtp_daemon
%if %{undefined _unitdir}
Requires: ucspi-tcp
%endif
%if %{defined _unitdir}
Requires: ucspi-tcp >= 1.88
Requires: systemd
%endif

%description smtpd
qmail is a modern SMTP server which makes sendmail obsolete, written by Dan
Bernstein, who also has a web page for qmail.

This subpackage contains the smtp daemon + support files.

%package qmtpd
Summary: Quick Mail Transfer Protocol Daemon for QMail
Group: Productivity/Networking/Email/Servers
Requires: netqmail
%if %{undefined _unitdir}
Requires: ucspi-tcp daemontools
%endif
%if %{defined _unitdir}
Requires: ucspi-tcp >= 1.88
Requires: systemd
%endif

%description qmtpd
qmail is a modern SMTP server which makes sendmail obsolete, written by Dan
Bernstein, who also has a web page for qmail.

This subpackage contains the qmtp daemon + support files.
(qmtp is the "quick mail transfer protocol", see http://cr.yp.to/proto/qmtp.txt ).

%package pop3d
Summary: Post Office Protocol (v3) Daemon for QMail
Group: Productivity/Networking/Email/Servers
Requires: checkpassword-pam
Requires(pre): hostname
%if %{undefined _unitdir}
Requires: ucspi-tcp daemontools
%endif
%if %{defined _unitdir}
Requires: ucspi-tcp >= 1.88
Requires: systemd netqmail
%endif

%description pop3d
qmail is a modern SMTP server which makes sendmail obsolete, written by Dan
Bernstein, who also has a web page for qmail.

This subpackage contains a pop3 daemon for accessing users' Maildirs.

%prep
%setup -q -a 1 -a 2 -a 5
cp "%{S:9}" qmail-dkim.pl
#%%patch -P 1 -p1
%patch -P 2 -p1
#patch <qmail-verh-0.07/qmail-remote.diff
%__patch -s --fuzz=0 <qmail-verh-0.07/qmail-local.diff
%__patch -s --fuzz=0 <qmail-send.mime.diff
%__patch -s --fuzz=0 -p0 <qmail-spp-0.42/netqmail-spp.diff
#%%patch -P 10 -p1
%patch -P 12 -p1
%patch -P 5 -p0
%patch -P 13 -p1
%patch -P 14 -p1
%patch -P 15 -p1
cp "%{S:11}" "%{S:12}" "%{S:8}" "%{S:16}" "%{S:18}" .
%patch -P 16 -p0
grep -v "^extern" alloc.c >tmp && mv tmp alloc.c
for i in auto-str.c auto-int8.c auto-int.c qmail-inject.c qmail-pop3d.c qmail-popup.c; do
    sed 's= puts= my_puts=g' <"$i" >tmp && mv tmp "$i"
done
%patch -P 17 -p1
%patch -P 18 -p1
%patch -P 19 -p1
%patch -P 20 -p1

chmod 644 genkey.sh
head -100 "%{P:12}" >README.tls
echo "Adapted to work with other patches by Peter Conrad <conrad@quisquis.de>" >>README.tls

%build
echo "systemd-sysusers - <<_EOU_" >netqmail.pre
%__sed 's=QMAIL_HOME=%{qmail_home}=g' <"%{SOURCE44}" >>netqmail.pre
echo "_EOU_" >>netqmail.pre
#%%sysusers_generate_pre netqmail-users.conf netqmail netqmail-users.conf
echo "%{qmail_home}" >conf-qmail
(echo mail; echo qmaild) >conf-groups
echo gcc %{optflags} -fpie -include errno.h -include string.h -include stdio.h -include unistd.h -include sys/socket.h -include stdlib.h -include sys/stat.h -include sys/types.h -include utime.h -include grp.h -DTLS >conf-cc
echo gcc %{optflags} -pie >conf-ld
echo >readwrite.h
make %{?_smp_mflags} load
cp load load.tmp && sed 's=}$=} -lsyncdir=' <load.tmp >load
make %{?_smp_mflags} auto-uid auto-gid
touch auto_uids.c
make %{?_smp_mflags} it `grep '^ *c.*man' hier.c | grep -v cat | cut -d, -f 3 | sed 's="==g'`
lic="`md5sum gpl-2.0.txt | cut -d' ' -f 1`"
if [ -r "/usr/share/doc/licenses/md5/$lic" ]; then
    ln -sf /usr/share/doc/licenses/md5/"$lic" gpl-2.0.txt
fi

%install
mkdir -p "%{buildroot}%{_libexecdir}/qmail"
grep ' d(.*[0-9]);' hier.c | grep -v '"man' \
 | sed 's=^[^"]*"==;s="[^0]*= =;s=[^0-9]*$==' \
 | while read name mode; do
    mkdir -p -m 0755 "%{buildroot}%{qmail_home}/$name"
    chmod "$mode" "%{buildroot}%{qmail_home}/$name"
   done
grep ' dsplit(.*[0-9]);' hier.c \
 | sed 's=^[^"]*"==;s="[^0]*= =;s=[^0-9]*$==' \
 | while read name mode; do
    for i in $(seq 0 $(($(head -1 conf-split) - 1))); do
	mkdir -p -m 0755 "%{buildroot}%{qmail_home}/$name/$i"
	chmod "$mode" "%{buildroot}%{qmail_home}/$name/$i"
    done
   done
grep ' z(.*[0-9]);' hier.c | grep -v tcpto \
 | sed 's=^[^"]*"==;s=",= =;s=,[^0]*,= =;s=[^0-9]*$==' \
 | while read name len mode; do
    head -c $len </dev/zero >"%{buildroot}%{qmail_home}/$name"
    chmod "$mode" "%{buildroot}%{qmail_home}/$name"
   done
grep ' c(.*[0-9]);' hier.c | grep -v 'man/cat' \
 | sed 's=^[^"]*"==;s=","= =;s="[^0]*= =;s=[^0-9]*$==' \
 | while read dest file mode; do
    case "$dest" in
	man*)	mkdir -p "%{buildroot}%{_mandir}${dest#man}"
		suff=
		if [ "$file" = "maildirmake.1" -o "$file" = "maildir.5" -o "$file" = "tcp-environ.5" ]; then
		    suff=q
		fi
		install -m "$mode" "$file" "%{buildroot}%{_mandir}${dest#man}/$file$suff"
		if [ "$file" != "qmail-qmtpd.8" -a "$file" != "qmail-smtpd.8" -a "$file" != "qmail-popup.8" -a "$file" != "qmail-pop3d.8" ]; then
		    echo "%{_mandir}${dest#man}/$file$suff%%{ext_man}"
		fi
		;;
	doc)	echo "%%doc $file"
		;;
	bin)	install -m "$mode" "$file" "%{buildroot}%{_libexecdir}/qmail/"
		if [ "$file" = "qmail-queue" ]; then
		    echo "%%attr(-,qmailq,mail) %{_libexecdir}/qmail/$file"
		elif [ "$file" != "qmail-qmtpd" -a "$file" != "qmail-smtpd" -a "$file" != "qmail-popup" -a "$file" != "qmail-pop3d" ]; then
		    echo "%{_libexecdir}/qmail/$file"
		fi
		;;
	*)	install -m "$mode" "$file" "%{buildroot}%{qmail_home}/$dest/"
    esac
   done >files.list

# install_replace src dest mode
function install_replace () {
    mkdir -p "%{buildroot}${2%/*}"
    sed 's=@QMAIL_HOME@=%{qmail_home}=g;s=@QMAIL_CONFDIR@=%{_sysconfdir}/qmail=g;s=@QMAIL_EXECDIR@=%{_libexecdir}/qmail=g' <"$1" >"%{buildroot}$2"
    chmod "$3" "%{buildroot}$2"
}

mkdir -p "%{buildroot}%{_localstatedir}/spool"
rmdir "%{buildroot}%{qmail_home}/bin"
ln -s "%{_libexecdir}/qmail" "%{buildroot}%{qmail_home}/bin"
mv "%{buildroot}%{qmail_home}/boot" "%{buildroot}%{_libexecdir}/qmail"
mv "%{buildroot}%{qmail_home}/queue" "%{buildroot}%{_localstatedir}/spool/qmail-queue"
ln -s "%{_localstatedir}/spool/qmail-queue" "%{buildroot}%{qmail_home}/queue"

mkdir -p "%{buildroot}%{_sysconfdir}/qmail/control/tlshosts"
mkdir -p "%{buildroot}%{_sysconfdir}/qmail/control/notlshosts"
mkdir -p "%{buildroot}%{_initrddir}"
mkdir -p "%{buildroot}/usr/lib"
mkdir -p "%{buildroot}/%{_bindir}"
for i in bouncesaying condredirect except forward maildir2mbox maildirmake \
	 maildirwatch mailsubj preline qbiff qmail-inject qmail-qmqpc \
	 qreceipt ; do
    ln -s "%{_libexecdir}/qmail/$i" "%{buildroot}/%{_bindir}/"
    echo "%{_bindir}/$i"
done >>files.list
mkdir -p "%{buildroot}/%{_sbindir}"
for i in dkim-genkey qmail-newmrh qmail-newu qmail-pw2u qmail-qread \
	 qmail-qstat qmail-showctl qmail-tcpok qmail-tcpto ; do
    ln -s "%{_libexecdir}/qmail/$i" "%{buildroot}/%{_sbindir}/"
    echo "%{_sbindir}/$i"
done >>files.list

%if 0%{?fedora} == 0
mkdir -p "%{buildroot}%{_sysconfdir}/apparmor.d"
%endif

%if %{undefined _unitdir}

# SYSV-Init

install_replace "%{S:3}" "%{_initrddir}/netqmail" 0755
ln -s "%{_initrddir}/netqmail" "%{buildroot}/%{_sbindir}/rcnetqmail"
install_replace "%{S:10}" "%{_initrddir}/netqmail-smtpd" 0755
ln -s "%{_initrddir}/netqmail-smtpd" "%{buildroot}/%{_sbindir}/rcnetqmail-smtpd"
install_replace "%{S:17}" "%{_initrddir}/netqmail-qmtpd" 0755
ln -s "%{_initrddir}/netqmail-qmtpd" "%{buildroot}/%{_sbindir}/rcnetqmail-qmtpd"
install_replace "%{S:20}" "%{_initrddir}/netqmail-pop3d" 0755
ln -s "%{_initrddir}/netqmail-pop3d" "%{buildroot}/%{_sbindir}/rcnetqmail-pop3d"
install -m 0755 "%{S:29}" "%{buildroot}%{_libexecdir}/qmail/"
install -m 0644 "%{S:28}" "%{buildroot}%{_sysconfdir}/apparmor.d/usr.lib.qmail.start-pop3-tcpserver"
%__install -D -m 0644 %{S:43} "%{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}"

# /SYSV-Init

%endif

install -m 0644 "%{S:4}" "%{buildroot}%{_sysconfdir}/tcprules.smtpd"
tcprules <"%{buildroot}%{_sysconfdir}/tcprules.smtpd" "%{buildroot}%{_sysconfdir}/tcprules.smtpd.cdb" "%{buildroot}%{_sysconfdir}/tcprules.smtpd.tmp"
cp "%{buildroot}%{_sysconfdir}"/tcprules.{s,q}mtpd
cp "%{buildroot}%{_sysconfdir}"/tcprules.{s,q}mtpd.cdb
cp "%{buildroot}%{_sysconfdir}"/tcprules.{smtp,pop3}d
cp "%{buildroot}%{_sysconfdir}"/tcprules.{smtp,pop3}d.cdb
rmdir "%{buildroot}%{qmail_home}/control"
ln -s "%{_sysconfdir}/qmail/control" "%{buildroot}%{qmail_home}/control"
install_replace %{S:6} "%{_sysconfdir}/qmail/control/smtpplugins" 0644
cp "%{buildroot}%{_libexecdir}/qmail/sendmail" "%{buildroot}%{_sbindir}"
ln -s "%{_sbindir}/sendmail" "%{buildroot}%{_prefix}/lib"
ln -sf "%{_sbindir}/sendmail" "%{buildroot}%{_libexecdir}/qmail/sendmail"
mkdir -p -m 0750 "%{buildroot}%{_sysconfdir}/qmail/env"
mkdir -p -m 0755 "%{buildroot}%{_libexecdir}/qmail/plugins"
ln -s "%{_libexecdir}/qmail/plugins" "%{buildroot}%{qmail_home}"
mkdir -p -m 0755 "%{buildroot}%{_sysconfdir}/skel"
"%{buildroot}%{_libexecdir}/qmail/maildirmake" "%{buildroot}%{_sysconfdir}/skel/Maildir"
mv "%{buildroot}%{_libexecdir}/qmail/qmail-remote"{,.real}
mkdir -p -m 0750 "%{buildroot}%{_sysconfdir}/qmail/dkim"
install_replace qmail-dkim.pl "%{_libexecdir}/qmail/qmail-remote" 751
install_replace "%{S:21}" "%{_libexecdir}/qmail/dkim-genkey" 755
install_replace "%{S:19}" "%{_sysconfdir}/qmail/dkim/signconf.xml" 644
mkdir -p "%{buildroot}%{_sysconfdir}/cron.daily"
install_replace "%{S:13}" "%{_sysconfdir}/cron.daily/quisquis.de-qmail-tls" 755
%if 0%{?fedora} == 0
mkdir -p "%{buildroot}%{_sysconfdir}/permissions.d"
install_replace "%{S:14}" "%{_sysconfdir}/permissions.d/%{name}" 644
install_replace "%{S:15}" "%{_sysconfdir}/permissions.d/%{name}.paranoid" 644
%endif
mkdir -p "%{buildroot}%{_sysconfdir}/pam.d"
%__install -m 0644 "%{S:39}" "%{buildroot}%{_sysconfdir}/pam.d/pop3"
%if 0%{?fedora} == 0
for i in "%{S:22}" "%{S:23}" "%{S:24}" "%{S:25}" "%{S:26}" "%{S:27}"; do
    target="%{_sysconfdir}/apparmor.d/usr.lib.qmail.${i#*apparmor.}"
    install -m 0644 "$i" "%{buildroot}$target"
    echo "%config $target" >>files.list
done
%endif
install_replace "%{S:30}" "%{_mandir}/man8/dkim-genkey.8" 644

%if %{defined _unitdir}

# systemd-init

mkdir -p "%{buildroot}%{_unitdir}"
for i in "%{S:31}" "%{S:32}" "%{S:33}" "%{S:34}" "%{S:35}" "%{S:36}" "%{S:37}"; do
    install_replace "$i" "%{_unitdir}/${i##*/}" 644
    case "$i" in
	*.service)
	    i="${i%.service}"
	    ln -s service "%{buildroot}%{_sbindir}/rc${i##*/}"
	    ;;
    esac
done
%if 0%{?fedora} == 0
install -m 0644 "%{S:38}" "%{buildroot}%{_sysconfdir}/apparmor.d/usr.lib.qmail.qmail-popup"
%endif
%__ln_s /usr/bin/envdir "%{buildroot}%{_libexecdir}/qmail/smtpd"

# /systemd-init

%endif

%if 0%{?suse_version} > 0 && 0%{?suse_version} <= 1500
%__mkdir_p -m 0700 "%{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/"
%__install -m 0644 "%{S:40}" "%{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/qmail-smtpd"
%__install -m 0644 "%{S:41}" "%{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/qmail-qmtpd"
%__install -m 0644 "%{S:42}" "%{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/qmail-pop3d"
%endif

%__debug_install_post

%pre -f netqmail.pre
%if %{defined service_add_pre}
%service_add_pre netqmail.service
%endif

%post
%if 0%{?set_permissions:1} > 0
    %set_permissions "%{_libexecdir}/qmail/qmail-queue"
%else
    %run_permissions
%endif
cd "%{qmail_home}/control"
if [ ! -f me ]; then
    hostname --fqdn >me
fi
if [ ! -f rcpthosts ]; then
    hostname --fqdn >rcpthosts
fi
if [ ! -r servercert.pem ]; then
    oldumask="`umask`"
    umask 0027
    openssl req -new -x509 -nodes -days 366 -out servercert.pem -keyout servercert.pem -batch -subj "/CN=`hostname --fqdn`"
    umask "$oldumask"
    chgrp mail servercert.pem
fi
if [ ! -r clientcert.pem ]; then
    ln -s servercert.pem clientcert.pem
fi
if [ ! -f "%{_sysconfdir}/qmail/control/dh1024.pem" \
     -o ! -f "%{_sysconfdir}/qmail/control/dh512.pem" \
     -o ! -f "%{_sysconfdir}/qmail/control/rsa512.pem" ]; then
    "%{_libexecdir}/qmail/update_tmprsadh"
fi
if [ ! -f "%{_sysconfdir}/qmail/dkim/default.key" \
     -a ! -f "%{_sysconfdir}/qmail/dkim/default.pub" ]; then
    "%{_libexecdir}/qmail/dkim-genkey" "%{_sysconfdir}/qmail/dkim/default"
    chgrp mail "%{_sysconfdir}/qmail/dkim/default".{key,pub}
fi
if [ ! -r "%{_localstatedir}/spool/qmail-queue/lock/tcpto" ]; then
    dd if=/dev/zero of="%{_localstatedir}/spool/qmail-queue/lock/tcpto" bs=2k count=1
    chmod 644 "%{_localstatedir}/spool/qmail-queue/lock/tcpto"
    chown qmailr:mail "%{_localstatedir}/spool/qmail-queue/lock/tcpto"
fi
if [ ! -r "%{_localstatedir}/spool/qmail-queue/lock/trigger" ]; then
    mknod -m 0666 "%{_localstatedir}/spool/qmail-queue/lock/trigger" p
    chown qmails:mail "%{_localstatedir}/spool/qmail-queue/lock/trigger"
fi
%if %{undefined _unitdir}
chkconfig netqmail on
%else
%if %{defined service_add_post}
%service_add_post netqmail.service
%else
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl enable netqmail.service >/dev/null 2>&1 || :
fi
%endif
%endif

%preun
%if %{undefined _unitdir}
%stop_on_removal netqmail
%else
%if %{defined service_del_preun}
%service_del_preun netqmail.service
%else
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -lt 1 ; then
    /bin/systemctl --no-reload disable netqmail.service >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail.service >/dev/null 2>&1 || :
fi
%endif
%endif

%postun
%if %{undefined _unitdir}
%restart_on_update netqmail
%insserv_cleanup
%endif
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -lt 1 ; then 
    rm -f "%{_localstatedir}/spool/qmail-queue/lock/tcpto"
    rm -f "%{_localstatedir}/spool/qmail-queue/lock/trigger"
fi
%if %{defined _unitdir}
%if %{defined service_del_postun_without_restart}
%service_del_postun_without_restart netqmail.service
%else
%if %{defined service_del_postun}
%service_del_postun netqmail.service
%else
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl try-restart netqmail.service >/dev/null 2>&1 || :
fi
%endif
%endif
%endif

%if %{defined _unitdir}
%if %{defined service_add_pre} && %{defined service_add_post} && %{defined service_del_preun} && %{defined service_del_postun_without_restart}
%pre smtpd
%service_add_pre netqmail-smtpd.socket netqmail-smtpd.service
%post smtpd
%service_add_post netqmail-smtpd.socket netqmail-smtpd.service
%preun smtpd
%service_del_preun netqmail-smtpd.socket netqmail-smtpd.service
%postun smtpd
%service_del_postun_without_restart netqmail-smtpd.socket netqmail-smtpd.service

%pre qmtpd
%service_add_pre netqmail-qmtpd.socket netqmail-qmtpd.service
%post qmtpd
%service_add_post netqmail-qmtpd.socket netqmail-qmtpd.service
%preun qmtpd
%service_del_preun netqmail-qmtpd.socket netqmail-qmtpd.service
%postun qmtpd
%service_del_postun_without_restart netqmail-qmtpd.socket netqmail-qmtpd.service

%pre pop3d
%service_add_pre netqmail-pop3d.socket netqmail-pop3d.service
%post pop3d
%service_add_post netqmail-pop3d.socket netqmail-pop3d.service
%preun pop3d
%service_del_preun netqmail-pop3d.socket netqmail-pop3d.service
%postun pop3d
%service_del_postun_without_restart netqmail-pop3d.socket netqmail-pop3d.service

%else
%post smtpd
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl enable netqmail-smtpd.socket >/dev/null 2>&1 || :
fi

%post qmtpd
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl enable netqmail-qmtpd.socket >/dev/null 2>&1 || :
fi

%post pop3d
systemdconfdir=%(pkg-config --variable=systemdsystemconfdir systemd)
if [ ! -r "$systemdconfdir/netqmail-pop3d.service" ]; then
    sed "s=@HOSTNAME@=$(hostname --fqdn)=g" <"%{_unitdir}/netqmail-pop3d.service" >"$systemdconfdir/netqmail-pop3d.service"
fi
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl enable netqmail-pop3d.socket >/dev/null 2>&1 || :
fi

%preun pop3d
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -lt 1 ; then
    /bin/systemctl --no-reload disable netqmail-pop3d.socket >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail-pop3d.socket >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail-pop3d.service >/dev/null 2>&1 || :
fi

%preun smtpd
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -lt 1 ; then
    /bin/systemctl --no-reload disable netqmail-smtpd.socket >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail-smtpd.socket >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail-smtpd.service >/dev/null 2>&1 || :
fi

%preun qmtpd
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -lt 1 ; then
    /bin/systemctl --no-reload disable netqmail-qmtpd.socket >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail-qmtpd.socket >/dev/null 2>&1 || :
    /bin/systemctl stop netqmail-qmtpd.service >/dev/null 2>&1 || :
fi

%postun pop3d
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl stop netqmail-pop3d.service >/dev/null 2>&1 || :
    /bin/systemctl try-restart netqmail-pop3d.socket >/dev/null 2>&1 || :
fi

%postun smtpd
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl stop netqmail-smtpd.service >/dev/null 2>&1 || :
    /bin/systemctl try-restart netqmail-smtpd.socket >/dev/null 2>&1 || :
fi

%postun qmtpd
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
test -n "$FIRST_ARG" || FIRST_ARG=$1
if test "$FIRST_ARG" -ge 1 ; then
    /bin/systemctl stop netqmail-qmtpd.service >/dev/null 2>&1 || :
    /bin/systemctl try-restart netqmail-qmtpd.socket >/dev/null 2>&1 || :
fi
%endif

%else
# !defined _unitdir
%post smtpd
%fillup_only netqmail

%preun smtpd
%stop_on_removal netqmail-smtpd

%preun qmtpd
%stop_on_removal netqmail-qmtpd

%preun pop3d
%stop_on_removal netqmail-pop3d

%postun smtpd
%insserv_cleanup

%postun qmtpd
%insserv_cleanup

%postun pop3d
%insserv_cleanup
%endif

%if 0%{?suse_version} >= 1120
%verifyscript
%verify_permissions -e "%{_libexecdir}/qmail/qmail-queue"
%endif

%clean
[ "%{buildroot}" = "/" ] || rm -rf "%{buildroot}"

%files -f files.list
%defattr(-,root,mail,-)
%doc genkey.sh README.tls README.SUSE gpl-2.0.txt README.auth LICENSE.authentication
%dir %{qmail_home}
%dir %{_sysconfdir}/qmail
%dir %{_sysconfdir}/qmail/control
%config(noreplace) %{_sysconfdir}/qmail/control/tlshosts/
%config(noreplace) %{_sysconfdir}/qmail/control/notlshosts/
%config(noreplace) %{_sysconfdir}/qmail/dkim/
%{qmail_home}/control
%{qmail_home}/queue
%attr(-,qmailq,mail) %dir %{_localstatedir}/spool/qmail-queue
%attr(-,qmailq,mail) %{_localstatedir}/spool/qmail-queue/pid
%attr(-,qmailq,mail) %{_localstatedir}/spool/qmail-queue/intd
%attr(-,qmailq,mail) %{_localstatedir}/spool/qmail-queue/todo
%attr(-,qmails,mail) %{_localstatedir}/spool/qmail-queue/bounce
%attr(-,qmailq,mail) %{_localstatedir}/spool/qmail-queue/mess
%attr(-,qmails,mail) %{_localstatedir}/spool/qmail-queue/info
%attr(-,qmails,mail) %{_localstatedir}/spool/qmail-queue/local
%attr(-,qmails,mail) %{_localstatedir}/spool/qmail-queue/remote
%attr(-,qmailq,mail) %dir %{_localstatedir}/spool/qmail-queue/lock
%attr(-,qmails,mail) %{_localstatedir}/spool/qmail-queue/lock/sendmutex
%{qmail_home}/bin
%{qmail_home}/users
%dir %{_libexecdir}/qmail
%{_libexecdir}/qmail/boot/
%{_libexecdir}/qmail/dkim-genkey
%{_libexecdir}/qmail/qmail-remote.real
%{_sysconfdir}/skel/Maildir/
%config(noreplace) %{_sysconfdir}/cron.daily/quisquis.de-qmail-tls
%if 0%{?fedora} == 0
%config(noreplace) %{_sysconfdir}/permissions.d/%{name}
%config(noreplace) %{_sysconfdir}/permissions.d/%{name}.paranoid
%endif
/usr/lib/sendmail
%{_sbindir}/sendmail
%{_mandir}/man8/dkim-genkey.8%{ext_man}
%if %{undefined _unitdir}
%{_initrddir}/netqmail
%else
%{_unitdir}/netqmail.service
%endif
%{_sbindir}/rcnetqmail

%files smtpd
%defattr(-,root,root,-)
%config(noreplace) %attr(-,root,mail) %{_sysconfdir}/qmail/env/
%config(noreplace) %{_sysconfdir}/qmail/control/smtpplugins
%config(noreplace) %{_sysconfdir}/tcprules.smtpd
%config(noreplace) %{_sysconfdir}/tcprules.smtpd.cdb
%{_libexecdir}/qmail/qmail-smtpd
%{_mandir}/man8/qmail-smtpd.8%{ext_man}
%dir %{_libexecdir}/qmail/plugins
%{qmail_home}/plugins
%if %{undefined _unitdir}
%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}
%{_initrddir}/netqmail-smtpd
%else
%{_libexecdir}/qmail/smtpd
%{_unitdir}/netqmail-smtpd.service
%{_unitdir}/netqmail-smtpd.socket
%endif
%{_sbindir}/rcnetqmail-smtpd
%if 0%{?suse_version} > 0 && 0%{?suse_version} <= 1500
%config(noreplace) %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/qmail-smtpd
%endif

%files qmtpd
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/tcprules.qmtpd
%config(noreplace) %{_sysconfdir}/tcprules.qmtpd.cdb
%{_libexecdir}/qmail/qmail-qmtpd
%{_mandir}/man8/qmail-qmtpd.8%{ext_man}
%if %{undefined _unitdir}
%{_initrddir}/netqmail-qmtpd
%else
%{_unitdir}/netqmail-qmtpd.service
%{_unitdir}/netqmail-qmtpd.socket
%endif
%{_sbindir}/rcnetqmail-qmtpd
%if 0%{?suse_version} > 0 && 0%{?suse_version} <= 1500
%config(noreplace) %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/qmail-qmtpd
%endif

%files pop3d
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/pam.d/pop3
%config(noreplace) %{_sysconfdir}/tcprules.pop3d
%config(noreplace) %{_sysconfdir}/tcprules.pop3d.cdb
%{_libexecdir}/qmail/qmail-pop3d
%{_libexecdir}/qmail/qmail-popup
%{_mandir}/man8/qmail-pop3d.8%{ext_man}
%{_mandir}/man8/qmail-popup.8%{ext_man}
%if %{undefined _unitdir}
%config %{_sysconfdir}/apparmor.d/usr.lib.qmail.start-pop3-tcpserver
%{_libexecdir}/qmail/start-pop3-tcpserver
%{_initrddir}/netqmail-pop3d
%else
%if 0%{?fedora} == 0
%config %{_sysconfdir}/apparmor.d/usr.lib.qmail.qmail-popup
%endif
%{_unitdir}/netqmail-pop3d.service
%{_unitdir}/netqmail-pop3d.socket
%endif
%{_sbindir}/rcnetqmail-pop3d
%if 0%{?suse_version} > 0 && 0%{?suse_version} <= 1500
%config(noreplace) %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/qmail-pop3d
%endif

%changelog
openSUSE Build Service is sponsored by