File opensmtpd.spec of Package opensmtpd

%define realname   opensmtpd
%define realver    6.4.2
%define patchlevel p1
%define srcext     tar.gz

%define extras     6.4.0

Name:          %{realname}
Version:       %{realver}%{?patchlevel}
Release:       wiz%{?extraver:0.}1%{?dist}
Group:         Productivity/Networking/Email/Servers
License:       ISC and BSD-4-Clause and BSD-3-Clause and BSD-2-Clause
URL:           http://www.opensmtpd.org/portable.html
Summary:       FREE implementation of the server-side SMTP protocol

# Install-time parameters
Provides:      smtp_daemon smtpdaemon
Conflicts:     sendmail sendmail-tls postfix exim
Requires:      logrotate
%if 0%{?suse_version}
PreReq: permissions
%endif

BuildRequires: autoconf automake libtool
BuildRequires: groff bison
BuildRequires: libasr-devel
BuildRequires: zlib-devel
BuildRequires: libressl-devel
BuildRequires: pam-devel
BuildRequires: mysql-devel postgresql-devel hiredis-devel
BuildRequires: sqlite-devel >= 3 libevent-devel
BuildRequires: openldap%{?suse_version:2}-devel
BuildRequires: python-devel
%if 0%{?suse_version}
BuildRequires: db-devel
%else
%if 0%{?rhel} >= 7
BuildRequires: libdb-devel
%else
BuildRequires: db4-devel
%endif
%endif
%if 0%{?suse_version} && 0%{?opensuse_bs}
BuildRequires: -post-build-checks
%endif
BuildRoot:     %{_tmppath}/%{name}-%{version}-build
Source0:       http://www.opensmtpd.org/archives/%{realname}-%{realver}%{?patchlevel}.%{srcext}
Source1:       http://www.opensmtpd.org/archives/opensmtpd-extras-%{extras}.%{srcext}
Source11:      opensmtpd.init
Source12:      opensmtpd.service

%description
OpenSMTPD is a FREE implementation of the server-side SMTP protocol as defined
by RFC 5321, with some additional standard extensions. It allows ordinary
machines to exchange e-mails with other systems speaking the SMTP protocol.

Started out of dissatisfaction with other implementations, OpenSMTPD nowadays
is a fairly complete SMTP implementation.

%package ldap
Group:         Productivity/Networking/Email/Servers
Summary:       LDAP support for %{name}
Requires:      %{name} = %{version}

%description ldap
LDAP table backend for %{name}

%package mysql
Group:         Productivity/Networking/Email/Servers
Summary:       MySQL support for %{name}
Requires:      %{name} = %{version}

%description mysql
MySQL table backend for %{name}

%package postgres
Group:         Productivity/Networking/Email/Servers
Summary:       PostgreSQL support for %{name}
Requires:      %{name} = %{version}

%description postgres
PostgreSQL table backend for %{name}

%package python
Group:         Productivity/Networking/Email/Servers
Summary:       Python support for %{name}
Requires:      %{name} = %{version}

%description python
OpenSMTPd extensions using python: filter, queue, scheduler and table

%package redis
Group:         Productivity/Networking/Email/Servers
Summary:       Redis support for %{name}
Requires:      %{name} = %{version}

%description redis
Redis table backend for %{name}

%package sqlite
Group:         Productivity/Networking/Email/Servers
Summary:       SQLite support for %{name}
Requires:      %{name} = %{version}

%description sqlite
SQLite table backend for %{name}

%prep
%setup -q -n %{realname}-%{realver}%{?patchlevel} -a1
if [ ! -x configure ]; then
  ./bootstrap || autoreconf --force --install
fi
cd opensmtpd-extras-%{extras}
if [ ! -x configure ]; then
  ./bootstrap || autoreconf --force --install
fi
cd -
# Usually Linux uses /etc/aliases
%if %{_target_os} == "linux"
%{__sed} -ri 's|/etc/mail/aliases|/etc/aliases|' smtpd/smtpd.conf
%endif

%build
%configure \
 --sysconfdir=%{_sysconfdir}/%{name} \
 --libexecdir=%{_libdir} \
 \
 --disable-static \
 \
 --with-mantype=man \
 --with-user-smtpd=mail \
 --with-user-queue=mail \
 --with-group-queue=mail \
 --with-table-db \
 --with-spooldir=%{_localstatedir}/spool/mail \
 --with-cflags="%{optflags} %{?gcc_lto} -fPIE" \
 --with-ldflags="-Wl,--as-needed -Wl,--strip-all %{?gcc_lto} -pie"
%{__make} %{?_smp_mflags}
cd opensmtpd-extras-%{extras}
%configure \
 --sysconfdir=%{_sysconfdir}/%{name} \
 --libexecdir=%{_libdir} \
 \
 --disable-static \
 \
 --with-user-smtpd=mail \
 --with-filter-monkey \
 --with-filter-stub \
 --with-filter-trace \
 --with-filter-void \
 --with-queue-null \
 --with-queue-python \
 --with-queue-ram \
 --with-queue-stub \
 --with-table-ldap \
 --with-table-mysql \
 --with-table-postgres \
 --with-table-redis \
 --with-table-socketmap \
 --with-table-passwd \
 --with-table-python \
 --with-table-sqlite \
 --with-table-stub \
 --with-tool-stats \
 --with-scheduler-ram \
 --with-scheduler-stub \
 --with-scheduler-python \
 --with-cflags="%{optflags} %{?gcc_lto} -I`pg_config --includedir` -I%{_includedir}/hiredis" \
 --with-ldflags="-Wl,--as-needed -Wl,--strip-all %{?gcc_lto} -L%{_libdir}/mysql"
%{__make} %{?_smp_mflags}
cd -

%install
%{__make} install DESTDIR=%{buildroot}
cd opensmtpd-extras-%{extras}
%{__make} install DESTDIR=%{buildroot}
cd -
test -d %{buildroot}/usr/lib || %{__install} -d -m755 %{buildroot}/usr/lib
%{__ln_s} ../sbin/smtpctl %{buildroot}/usr/lib/sendmail
%if 0%{?_unitdir:1}
%{__install} -D -m644 %{S:12} %{buildroot}%{_unitdir}/opensmtpd.service
%else
%{__install} -D -m755 %{S:11} %{buildroot}%{_initrddir}/opensmtpd
%if 0%{?suse_version}
test -f %{buildroot}%{_initrddir}/opensmtpd && %{__ln_s} %{_initrddir}/opensmtpd %{buildroot}%{_sbindir}/rcopensmtpd
%endif
%endif
%if 0%{?suse_version}
%{__install} -d -m0755 %{buildroot}/etc/permissions.d/
cat > %{buildroot}/etc/permissions.d/%{name} <<EOF
%{sbindir}/smtpctl root:root 2555
EOF
%endif

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

%files
%defattr(-,root,root)
%doc LICENSE README.md THANKS
%config(noreplace) %{_sysconfdir}/%{name}/smtpd.conf
%if 0%{?_unitdir:1}
%{_unitdir}/opensmtpd.service
%else
%{_initrddir}/opensmtpd
%if 0%{?suse_version}
%{_sbindir}/rcopensmtpd
%endif
%endif
%if 0%{?suse_version}
%config /etc/permissions.d/%{name}
%verify(not mode) %attr(0555,root,root) %{_sbindir}/smtpctl
%else
%{_sbindir}/smtpctl
%endif
%{_sbindir}/smtpd
/usr/lib/sendmail
%dir %{_libdir}/opensmtpd
%{_libdir}/opensmtpd/*
%doc %{_mandir}/man5/*
%doc %{_mandir}/man8/*
%exclude %{_libdir}/opensmtpd/queue-python
%exclude %{_libdir}/opensmtpd/scheduler-python
%exclude %{_libdir}/opensmtpd/table-ldap
%exclude %{_libdir}/opensmtpd/table-mysql
%exclude %{_libdir}/opensmtpd/table-postgres
%exclude %{_libdir}/opensmtpd/table-python
%exclude %{_libdir}/opensmtpd/table-redis
%exclude %{_libdir}/opensmtpd/table-sqlite

%files ldap
%defattr(-,root,root)
%{_libdir}/opensmtpd/table-ldap

%files mysql
%defattr(-,root,root)
%{_libdir}/opensmtpd/table-mysql

%files postgres
%defattr(-,root,root)
%{_libdir}/opensmtpd/table-postgres

%files python
%defattr(-,root,root)
%{_libdir}/opensmtpd/*-python

%files redis
%defattr(-,root,root)
%{_libdir}/opensmtpd/table-redis

%files sqlite
%defattr(-,root,root)
%{_libdir}/opensmtpd/table-sqlite

%if %{expand:%_vendor == "suse"}

%verifyscript
%verify_permissions -e /usr/sbin/smtpctl

%if 0%{?_unitdir:1}
%pre
test -d /var/empty || mkdir /var/empty
%{service_add_pre %{name}.service}
%endif

%post
%set_permissions /usr/sbin/smtpctl
%if 0%{?_unitdir:1}
%{fillup_only %{name}}
%{service_add_post %{name}.service}
%else
%{fillup_and_insserv %{name}}
%endif

%preun
%if 0%{?_unitdir:1}
%{service_del_preun %{name}.service}
%else
%{stop_on_removal %{name}}
%endif

%postun
%if 0%{?_unitdir:1}
%{service_del_postun %{name}.service}
%else
%{restart_on_update %{name}}
%endif
%{insserv_cleanup}

%else

%pre
test -d /var/empty || mkdir /var/empty

%endif

%changelog
openSUSE Build Service is sponsored by