mail-mta/postfix: bump to 3.5.2
[gentoo.git] / mail-mta / postfix / postfix-3.6_pre20200511.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5 inherit pam systemd toolchain-funcs
6
7 MY_PV="${PV/_pre/-}"
8 MY_SRC="${PN}-${MY_PV}"
9 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/experimental"
10 RC_VER="2.7"
11
12 DESCRIPTION="A fast and secure drop-in replacement for sendmail"
13 HOMEPAGE="http://www.postfix.org/"
14 SRC_URI="${MY_URI}/${MY_SRC}.tar.gz"
15
16 LICENSE="|| ( IBM EPL-2.0 )"
17 SLOT="0"
18 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86"
19 IUSE="+berkdb cdb dovecot-sasl +eai ldap ldap-bind libressl lmdb memcached mbox mysql nis pam postgres sasl selinux sqlite ssl"
20
21 DEPEND=">=dev-libs/libpcre-3.4
22         dev-lang/perl
23         berkdb? ( >=sys-libs/db-3.2:* )
24         cdb? ( || ( >=dev-db/tinycdb-0.76 >=dev-db/cdb-0.75-r4 ) )
25         eai? ( dev-libs/icu:= )
26         ldap? ( net-nds/openldap )
27         ldap-bind? ( net-nds/openldap[sasl] )
28         lmdb? ( >=dev-db/lmdb-0.9.11 )
29         mysql? ( dev-db/mysql-connector-c:0= )
30         nis? ( net-libs/libnsl )
31         pam? ( sys-libs/pam )
32         postgres? ( dev-db/postgresql:* )
33         sasl? (  >=dev-libs/cyrus-sasl-2 )
34         sqlite? ( dev-db/sqlite:3 )
35         ssl? (
36                 !libressl? ( dev-libs/openssl:0= )
37                 libressl? ( >=dev-libs/libressl-2.9.1:0= )
38         )"
39
40 RDEPEND="${DEPEND}
41         acct-group/postfix
42         acct-group/postdrop
43         acct-user/postfix
44         memcached? ( net-misc/memcached )
45         net-mail/mailbase
46         !mail-mta/courier
47         !mail-mta/esmtp
48         !mail-mta/exim
49         !mail-mta/mini-qmail
50         !mail-mta/msmtp[mta]
51         !mail-mta/netqmail
52         !mail-mta/nullmailer
53         !mail-mta/qmail-ldap
54         !mail-mta/sendmail
55         !mail-mta/opensmtpd
56         !mail-mta/ssmtp[mta]
57         !net-mail/fastforward
58         selinux? ( sec-policy/selinux-postfix )"
59
60 REQUIRED_USE="ldap-bind? ( ldap sasl )"
61
62 S="${WORKDIR}/${MY_SRC}"
63
64 PATCHES=(
65         "${FILESDIR}/${PN}-libressl-certkey.patch"
66         "${FILESDIR}/${PN}-libressl-server.patch"
67 )
68
69 src_prepare() {
70         default
71         sed -i -e "/^#define ALIAS_DB_MAP/s|:/etc/aliases|:/etc/mail/aliases|" \
72                 src/util/sys_defs.h || die "sed failed"
73         # change default paths to better comply with portage standard paths
74         sed -i -e "s:/usr/local/:/usr/:g" conf/master.cf || die "sed failed"
75 }
76
77 src_configure() {
78         for name in CDB LDAP LMDB MYSQL PCRE PGSQL SDBM SQLITE
79         do
80                 local AUXLIBS_${name}=""
81         done
82
83         # Make sure LDFLAGS get passed down to the executables.
84         local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -ldl"
85         AUXLIBS_PCRE="$(pcre-config --libs)"
86
87         use pam && mylibs="${mylibs} -lpam"
88
89         if use ldap; then
90                 mycc="${mycc} -DHAS_LDAP"
91                 AUXLIBS_LDAP="-lldap -llber"
92         fi
93
94         if use mysql; then
95                 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
96                 AUXLIBS_MYSQL="$(mysql_config --libs)"
97         fi
98
99         if use postgres; then
100                 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
101                 AUXLIBS_PGSQL="-L$(pg_config --libdir) -lpq"
102         fi
103
104         if use sqlite; then
105                 mycc="${mycc} -DHAS_SQLITE"
106                 AUXLIBS_SQLITE="-lsqlite3 -lpthread"
107         fi
108
109         if use ssl; then
110                 mycc="${mycc} -DUSE_TLS"
111                 mylibs="${mylibs} -lssl -lcrypto"
112         fi
113
114         if use lmdb; then
115                 mycc="${mycc} -DHAS_LMDB"
116                 AUXLIBS_LMDB="-llmdb -lpthread"
117         fi
118
119         if ! use eai; then
120                 mycc="${mycc} -DNO_EAI"
121         fi
122
123         # broken. and "in other words, not supported" by upstream.
124         # Use inet_protocols setting in main.cf
125         #if ! use ipv6; then
126         #       mycc="${mycc} -DNO_IPV6"
127         #fi
128
129         if use sasl; then
130                 if use dovecot-sasl; then
131                         # Set dovecot as default.
132                         mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
133                 fi
134                 if use ldap-bind; then
135                         mycc="${mycc} -DUSE_LDAP_SASL"
136                 fi
137                 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
138                 mylibs="${mylibs} -lsasl2"
139         elif use dovecot-sasl; then
140                 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
141         fi
142
143         if ! use nis; then
144                 mycc="${mycc} -DNO_NIS"
145         fi
146
147         if ! use berkdb; then
148                 mycc="${mycc} -DNO_DB"
149                 if use cdb; then
150                         # change default hash format from Berkeley DB to cdb
151                         mycc="${mycc} -DDEF_DB_TYPE=\\\"cdb\\\""
152                 fi
153         fi
154
155         if use cdb; then
156                 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
157                 # Tinycdb is preferred.
158                 if has_version dev-db/tinycdb ; then
159                         einfo "Building with dev-db/tinycdb"
160                         AUXLIBS_CDB="-lcdb"
161                 else
162                         einfo "Building with dev-db/cdb"
163                         CDB_PATH="/usr/$(get_libdir)"
164                         for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
165                                 AUXLIBS_CDB="${AUXLIBS_CDB} ${CDB_PATH}/${i}"
166                         done
167                 fi
168         fi
169
170         sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
171         sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
172
173         emake makefiles shared=yes dynamicmaps=no pie=yes \
174                 shlib_directory="/usr/$(get_libdir)/postfix/MAIL_VERSION" \
175                 DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" \
176                 AUXLIBS_CDB="${AUXLIBS_CDB}" AUXLIBS_LDAP="${AUXLIBS_LDAP}" \
177                 AUXLIBS_LMDB="${AUXLIBS_LMDB}" AUXLIBS_MYSQL="${AUXLIBS_MYSQL}" \
178                 AUXLIBS_PCRE="${AUXLIBS_PCRE}" AUXLIBS_PGSQL="${AUXLIBS_PGSQL}" \
179                 AUXLIBS_SQLITE="${AUXLIBS_SQLITE}"
180 }
181
182 src_install() {
183         LD_LIBRARY_PATH="${S}/lib" \
184         /bin/sh postfix-install \
185                 -non-interactive \
186                 install_root="${D}" \
187                 config_directory="/etc/postfix" \
188                 manpage_directory="/usr/share/man" \
189                 command_directory="/usr/sbin" \
190                 mailq_path="/usr/bin/mailq" \
191                 newaliases_path="/usr/bin/newaliases" \
192                 sendmail_path="/usr/sbin/sendmail" \
193                 || die "postfix-install failed"
194
195         # Fix spool removal on upgrade
196         rm -Rf "${D}"/var
197         keepdir /var/spool/postfix
198
199         # Install rmail for UUCP, closes bug #19127
200         dobin auxiliary/rmail/rmail
201
202         # Provide another link for legacy FSH
203         dosym ../sbin/sendmail /usr/$(get_libdir)/sendmail
204
205         # Install qshape, posttls-finger and collate and tlstype
206         dobin auxiliary/qshape/qshape.pl
207         doman man/man1/qshape.1
208         dobin bin/posttls-finger
209         doman man/man1/posttls-finger.1
210         dobin auxiliary/collate/collate.pl
211         newdoc auxiliary/collate/README README.collate
212         dobin auxiliary/collate/tlstype.pl
213         dodoc auxiliary/collate/README.tlstype
214
215         # Performance tuning tools and their manuals
216         dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
217         doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
218
219         # Set proper permissions on required files/directories
220         keepdir /var/lib/postfix
221         fowners -R postfix:postfix /var/lib/postfix
222         fperms 0750 /var/lib/postfix
223         fowners root:postdrop /usr/sbin/post{drop,queue}
224         fperms 02755 /usr/sbin/post{drop,queue}
225
226         keepdir /etc/postfix
227         keepdir /etc/postfix/postfix-files.d
228         if use mbox; then
229                 mypostconf="mail_spool_directory=/var/spool/mail"
230         else
231                 mypostconf="home_mailbox=.maildir/"
232         fi
233         LD_LIBRARY_PATH="${S}/lib" \
234         "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
235                 -e ${mypostconf} || die "postconf failed"
236
237         insinto /etc/postfix
238         newins "${FILESDIR}"/smtp.pass saslpass
239         fperms 600 /etc/postfix/saslpass
240
241         newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
242         # do not start mysql/postgres unnecessarily - bug #359913
243         use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
244         use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
245
246         dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
247         mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
248         # postfix set-permissions expects uncompressed man files
249         docompress -x /usr/share/man
250
251         pamd_mimic_system smtp auth account
252
253         if use sasl; then
254                 insinto /etc/sasl2
255                 newins "${FILESDIR}"/smtp.sasl smtpd.conf
256         fi
257
258         # header files
259         insinto /usr/include/postfix
260         doins include/*.h
261
262         if has_version mail-mta/postfix; then
263                 # let the sysadmin decide when to change the compatibility_level
264                 sed -i -e /^compatibility_level/"s/^/#/" "${D}"/etc/postfix/main.cf || die
265         fi
266
267         systemd_dounit "${FILESDIR}/${PN}.service"
268 }
269
270 pkg_postinst() {
271         if [[ ! -e /etc/mail/aliases.db ]] ; then
272                 ewarn
273                 ewarn "You must edit /etc/mail/aliases to suit your needs"
274                 ewarn "and then run /usr/bin/newaliases. Postfix will not"
275                 ewarn "work correctly without it."
276                 ewarn
277         fi
278
279         # check and fix file permissions
280         "${EROOT}"/usr/sbin/postfix set-permissions
281
282         # configure tls
283         if use ssl ; then
284                 if "${EROOT}"/usr/sbin/postfix tls all-default-client; then
285                         elog "To configure client side TLS settings:"
286                         elog "${EROOT}"/usr/sbin/postfix tls enable-client
287                 fi
288                 if "${EROOT}"/usr/sbin/postfix tls all-default-server; then
289                         elog "To configure server side TLS settings:"
290                         elog "${EROOT}"/usr/sbin/postfix tls enable-server
291                 fi
292         fi
293 }