app-crypt/yubikey-manager: bump to 2.1.1
[gentoo.git] / mail-mta / postfix / postfix-3.2.4.ebuild
1 # Copyright 1999-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 inherit flag-o-matic pam systemd toolchain-funcs user
6
7 MY_PV="${PV/_pre/-}"
8 MY_SRC="${PN}-${MY_PV}"
9 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/official"
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"
17 SLOT="0"
18 KEYWORDS="alpha amd64 arm hppa ia64 ppc ppc64 ~sh sparc x86 ~x86-fbsd"
19 IUSE="+berkdb cdb doc dovecot-sasl +eai hardened 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? ( virtual/mysql )
30         pam? ( virtual/pam )
31         postgres? ( dev-db/postgresql:* )
32         sasl? (  >=dev-libs/cyrus-sasl-2 )
33         sqlite? ( dev-db/sqlite:3 )
34         ssl? (
35                 !libressl? ( dev-libs/openssl:0= )
36                 libressl? ( dev-libs/libressl )
37         )"
38
39 RDEPEND="${DEPEND}
40         dovecot-sasl? ( net-mail/dovecot )
41         memcached? ( net-misc/memcached )
42         net-mail/mailbase
43         !mail-mta/courier
44         !mail-mta/esmtp
45         !mail-mta/exim
46         !mail-mta/mini-qmail
47         !mail-mta/msmtp[mta]
48         !mail-mta/netqmail
49         !mail-mta/nullmailer
50         !mail-mta/qmail-ldap
51         !mail-mta/sendmail
52         !mail-mta/opensmtpd
53         !<mail-mta/ssmtp-2.64-r2
54         !>=mail-mta/ssmtp-2.64-r2[mta]
55         !net-mail/fastforward
56         selinux? ( sec-policy/selinux-postfix )"
57
58 REQUIRED_USE="ldap-bind? ( ldap sasl )"
59
60 S="${WORKDIR}/${MY_SRC}"
61
62 pkg_setup() {
63         # Add postfix, postdrop user/group (bug #77565)
64         enewgroup postfix 207
65         enewgroup postdrop 208
66         enewuser postfix 207 -1 /var/spool/postfix postfix,mail
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         eapply -p0 "${FILESDIR}/${PN}-libressl.patch"
76         eapply -p0 "${FILESDIR}/${PN}-libressl-runtime.patch"
77 }
78
79 src_configure() {
80         for name in CDB LDAP LMDB MYSQL PCRE PGSQL SDBM SQLITE
81         do
82                 local AUXLIBS_${name}=""
83         done
84
85         # Make sure LDFLAGS get passed down to the executables.
86         local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -ldl"
87         AUXLIBS_PCRE="$(pcre-config --libs)"
88
89         use pam && mylibs="${mylibs} -lpam"
90
91         if use ldap; then
92                 mycc="${mycc} -DHAS_LDAP"
93                 AUXLIBS_LDAP="-lldap -llber"
94         fi
95
96         if use mysql; then
97                 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
98                 AUXLIBS_MYSQL="$(mysql_config --libs)"
99         fi
100
101         if use postgres; then
102                 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
103                 AUXLIBS_PGSQL="-L$(pg_config --libdir) -lpq"
104         fi
105
106         if use sqlite; then
107                 mycc="${mycc} -DHAS_SQLITE"
108                 AUXLIBS_SQLITE="-lsqlite3 -lpthread"
109         fi
110
111         if use ssl; then
112                 mycc="${mycc} -DUSE_TLS"
113                 mylibs="${mylibs} -lssl -lcrypto"
114         fi
115
116         if use lmdb; then
117                 mycc="${mycc} -DHAS_LMDB"
118                 AUXLIBS_LMDB="-llmdb -lpthread"
119         fi
120
121         if ! use eai; then
122                 mycc="${mycc} -DNO_EAI"
123         fi
124
125         # broken. and "in other words, not supported" by upstream.
126         # Use inet_protocols setting in main.cf
127         #if ! use ipv6; then
128         #       mycc="${mycc} -DNO_IPV6"
129         #fi
130
131         if use sasl; then
132                 if use dovecot-sasl; then
133                         # Set dovecot as default.
134                         mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
135                 fi
136                 if use ldap-bind; then
137                         mycc="${mycc} -DUSE_LDAP_SASL"
138                 fi
139                 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
140                 mylibs="${mylibs} -lsasl2"
141         elif use dovecot-sasl; then
142                 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
143         fi
144
145         if ! use nis; then
146                 mycc="${mycc} -DNO_NIS"
147         fi
148
149         if ! use berkdb; then
150                 mycc="${mycc} -DNO_DB"
151                 if use cdb; then
152                         # change default hash format from Berkeley DB to cdb
153                         mycc="${mycc} -DDEF_DB_TYPE=\\\"cdb\\\""
154                 fi
155         fi
156
157         if use cdb; then
158                 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
159                 # Tinycdb is preferred.
160                 if has_version dev-db/tinycdb ; then
161                         einfo "Building with dev-db/tinycdb"
162                         AUXLIBS_CDB="-lcdb"
163                 else
164                         einfo "Building with dev-db/cdb"
165                         CDB_PATH="/usr/$(get_libdir)"
166                         for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
167                                 AUXLIBS_CDB="${AUXLIBS_CDB} ${CDB_PATH}/${i}"
168                         done
169                 fi
170         fi
171
172         # Robin H. Johnson <robbat2@gentoo.org> 17/Nov/2006
173         # Fix because infra boxes hit 2Gb .db files that fail a 32-bit fstat signed check.
174         mycc="${mycc} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
175         filter-lfs-flags
176
177         # Workaround for bug #76512
178         if use hardened; then
179                 [[ "$(gcc-version)" == "3.4" ]] && replace-flags -O? -Os
180         fi
181
182         # Remove annoying C++ comment style warnings - bug #378099
183         append-flags -Wno-comment
184
185         sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
186         sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
187
188         emake makefiles shared=yes dynamicmaps=no pie=yes \
189                 shlib_directory="/usr/$(get_libdir)/postfix/MAIL_VERSION" \
190                 DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" \
191                 AUXLIBS_CDB="${AUXLIBS_CDB}" AUXLIBS_LDAP="${AUXLIBS_LDAP}" \
192                 AUXLIBS_LMDB="${AUXLIBS_LMDB}" AUXLIBS_MYSQL="${AUXLIBS_MYSQL}" \
193                 AUXLIBS_PCRE="${AUXLIBS_PCRE}" AUXLIBS_PGSQL="${AUXLIBS_PGSQL}" \
194                 AUXLIBS_SQLITE="${AUXLIBS_SQLITE}"
195 }
196
197 src_install () {
198         local myconf
199         use doc && myconf="readme_directory=\"/usr/share/doc/${PF}/readme\" \
200                 html_directory=\"/usr/share/doc/${PF}/html\""
201
202         LD_LIBRARY_PATH="${S}/lib" \
203         /bin/sh postfix-install \
204                 -non-interactive \
205                 install_root="${D}" \
206                 config_directory="/etc/postfix" \
207                 manpage_directory="/usr/share/man" \
208                 command_directory="/usr/sbin" \
209                 mailq_path="/usr/bin/mailq" \
210                 newaliases_path="/usr/bin/newaliases" \
211                 sendmail_path="/usr/sbin/sendmail" \
212                 ${myconf} \
213                 || die "postfix-install failed"
214
215         # Fix spool removal on upgrade
216         rm -Rf "${D}"/var
217         keepdir /var/spool/postfix
218
219         # Install rmail for UUCP, closes bug #19127
220         dobin auxiliary/rmail/rmail
221
222         # Provide another link for legacy FSH
223         dosym ../sbin/sendmail /usr/$(get_libdir)/sendmail
224
225         # Install qshape and posttls-finger
226         dobin auxiliary/qshape/qshape.pl
227         doman man/man1/qshape.1
228         dobin bin/posttls-finger
229         doman man/man1/posttls-finger.1
230
231         # Performance tuning tools and their manuals
232         dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
233         doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
234
235         # Set proper permissions on required files/directories
236         dodir /var/lib/postfix
237         keepdir /var/lib/postfix
238         fowners -R postfix:postfix /var/lib/postfix
239         fperms 0750 /var/lib/postfix
240         fowners root:postdrop /usr/sbin/post{drop,queue}
241         fperms 02711 /usr/sbin/post{drop,queue}
242
243         keepdir /etc/postfix
244         if use mbox; then
245                 mypostconf="mail_spool_directory=/var/spool/mail"
246         else
247                 mypostconf="home_mailbox=.maildir/"
248         fi
249         LD_LIBRARY_PATH="${S}/lib" \
250         "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
251                 -e ${mypostconf} || die "postconf failed"
252
253         insinto /etc/postfix
254         newins "${FILESDIR}"/smtp.pass saslpass
255         fperms 600 /etc/postfix/saslpass
256
257         newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
258         # do not start mysql/postgres unnecessarily - bug #359913
259         use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
260         use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
261
262         dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
263         use doc && mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
264
265         pamd_mimic_system smtp auth account
266
267         if use sasl; then
268                 insinto /etc/sasl2
269                 newins "${FILESDIR}"/smtp.sasl smtpd.conf
270         fi
271
272         # header files
273         insinto /usr/include/postfix
274         doins include/*.h
275
276         # Keep config_dir clean
277         rm -f "${D}"/etc/postfix/{*LICENSE,access,aliases,canonical,generic}
278         rm -f "${D}"/etc/postfix/{header_checks,relocated,transport,virtual}
279
280         if has_version mail-mta/postfix; then
281                 # let the sysadmin decide when to change the compatibility_level
282                 sed -i -e /^compatibility_level/"s/^/#/" "${D}"/etc/postfix/main.cf || die
283         fi
284
285         systemd_dounit "${FILESDIR}/${PN}.service"
286 }
287
288 pkg_postinst() {
289         if [[ ! -e /etc/mail/aliases.db ]] ; then
290                 ewarn
291                 ewarn "You must edit /etc/mail/aliases to suit your needs"
292                 ewarn "and then run /usr/bin/newaliases. Postfix will not"
293                 ewarn "work correctly without it."
294                 ewarn
295         fi
296
297         # configure tls
298         if use ssl ; then
299                 if "${EROOT}"/usr/sbin/postfix tls all-default-client; then
300                         elog "To configure client side TLS settings:"
301                         elog "${EROOT}"usr/sbin/postfix tls enable-client
302                 fi
303                 if "${EROOT}"/usr/sbin/postfix tls all-default-server; then
304                         elog "To configure server side TLS settings:"
305                         elog "${EROOT}"usr/sbin/postfix tls enable-server
306                 fi
307         fi
308 }