9bfc6c31191736a5f2840550ef73bfd3be7084dd
[gentoo.git] / mail-mta / postfix / postfix-2.10.9.ebuild
1 # Copyright 1999-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5 inherit eutils multilib ssl-cert toolchain-funcs flag-o-matic pam user versionator systemd
6
7 MY_PV="${PV/_pre/-}"
8 MY_SRC="${PN}-${MY_PV}"
9 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/official"
10 VDA_PV="2.10.0"
11 VDA_P="${PN}-vda-v13-${VDA_PV}"
12 RC_VER="2.7"
13
14 DESCRIPTION="A fast and secure drop-in replacement for sendmail"
15 HOMEPAGE="http://www.postfix.org/"
16 SRC_URI="${MY_URI}/${MY_SRC}.tar.gz
17         vda? ( http://vda.sourceforge.net/VDA/${VDA_P}.patch ) "
18
19 LICENSE="IBM"
20 SLOT="0"
21 KEYWORDS="~s390"
22 IUSE="+berkdb cdb doc dovecot-sasl hardened ldap ldap-bind memcached mbox mysql nis pam postgres sasl selinux sqlite ssl vda"
23
24 DEPEND=">=dev-libs/libpcre-3.4
25         dev-lang/perl
26         berkdb? ( >=sys-libs/db-3.2:* )
27         cdb? ( || ( >=dev-db/tinycdb-0.76 >=dev-db/cdb-0.75-r1 ) )
28         ldap? ( net-nds/openldap )
29         ldap-bind? ( net-nds/openldap[sasl] )
30         mysql? ( virtual/mysql )
31         pam? ( virtual/pam )
32         postgres? ( dev-db/postgresql:* )
33         sasl? (  >=dev-libs/cyrus-sasl-2 )
34         sqlite? ( dev-db/sqlite:3 )
35         ssl? ( dev-libs/openssl:0= )"
36
37 RDEPEND="${DEPEND}
38         dovecot-sasl? ( net-mail/dovecot )
39         memcached? ( net-misc/memcached )
40         net-mail/mailbase
41         selinux? ( sec-policy/selinux-postfix )
42         !mail-mta/courier
43         !mail-mta/esmtp
44         !mail-mta/exim
45         !mail-mta/mini-qmail
46         !mail-mta/msmtp[mta]
47         !mail-mta/netqmail
48         !mail-mta/nullmailer
49         !mail-mta/qmail-ldap
50         !mail-mta/sendmail
51         !mail-mta/opensmtpd
52         !<mail-mta/ssmtp-2.64-r2
53         !>=mail-mta/ssmtp-2.64-r2[mta]
54         !net-mail/fastforward"
55
56 REQUIRED_USE="ldap-bind? ( ldap sasl )"
57
58 S="${WORKDIR}/${MY_SRC}"
59
60 pkg_setup() {
61         # Add postfix, postdrop user/group (bug #77565)
62         enewgroup postfix 207
63         enewgroup postdrop 208
64         enewuser postfix 207 -1 /var/spool/postfix postfix,mail
65 }
66
67 src_prepare() {
68         epatch "${FILESDIR}/${PN}-2.11.1-db6.patch"
69         if use vda; then
70                 epatch "${DISTDIR}"/${VDA_P}.patch
71         fi
72
73         sed -i -e "/^#define ALIAS_DB_MAP/s|:/etc/aliases|:/etc/mail/aliases|" \
74                 src/util/sys_defs.h || die "sed failed"
75
76         # change default paths to better comply with portage standard paths
77         sed -i -e "s:/usr/local/:/usr/:g" conf/master.cf || die "sed failed"
78 }
79
80 src_configure() {
81         # Make sure LDFLAGS get passed down to the executables.
82         local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -lpcre -lcrypt -lpthread"
83
84         use pam && mylibs="${mylibs} -lpam"
85
86         if use ldap; then
87                 mycc="${mycc} -DHAS_LDAP"
88                 mylibs="${mylibs} -lldap -llber"
89         fi
90
91         if use mysql; then
92                 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
93                 mylibs="${mylibs} $(mysql_config --libs)"
94         fi
95
96         if use postgres; then
97                 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
98                 mylibs="${mylibs} -lpq -L$(pg_config --libdir)"
99         fi
100
101         if use sqlite; then
102                 mycc="${mycc} -DHAS_SQLITE"
103                 mylibs="${mylibs} -lsqlite3"
104         fi
105
106         if use ssl; then
107                 mycc="${mycc} -DUSE_TLS"
108                 mylibs="${mylibs} -lssl -lcrypto"
109         fi
110
111         # broken. and "in other words, not supported" by upstream.
112         # Use inet_protocols setting in main.cf
113         #if ! use ipv6; then
114         #       mycc="${mycc} -DNO_IPV6"
115         #fi
116
117         if use sasl; then
118                 if use dovecot-sasl; then
119                         # Set dovecot as default.
120                         mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
121                 fi
122                 if use ldap-bind; then
123                         mycc="${mycc} -DUSE_LDAP_SASL"
124                 fi
125                 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
126                 mylibs="${mylibs} -lsasl2"
127         elif use dovecot-sasl; then
128                 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
129         fi
130
131         if ! use nis; then
132                 sed -i -e "s|#define HAS_NIS|//#define HAS_NIS|g" \
133                         src/util/sys_defs.h || die "sed failed"
134         fi
135
136         if ! use berkdb; then
137                 mycc="${mycc} -DNO_DB"
138                 if use cdb; then
139                         # change default hash format from Berkeley DB to cdb
140                         sed -i -e "s/hash/cdb/" src/util/sys_defs.h || die
141                 fi
142         fi
143
144         if use cdb; then
145                 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
146                 CDB_LIBS=""
147                 # Tinycdb is preferred.
148                 if has_version dev-db/tinycdb ; then
149                         einfo "Building with dev-db/tinycdb"
150                         CDB_LIBS="-lcdb"
151                 else
152                         einfo "Building with dev-db/cdb"
153                         CDB_PATH="/usr/$(get_libdir)"
154                         for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
155                                 CDB_LIBS="${CDB_LIBS} ${CDB_PATH}/${i}"
156                         done
157                 fi
158                 mylibs="${mylibs} ${CDB_LIBS}"
159         fi
160
161         # Robin H. Johnson <robbat2@gentoo.org> 17/Nov/2006
162         # Fix because infra boxes hit 2Gb .db files that fail a 32-bit fstat signed check.
163         mycc="${mycc} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
164         filter-lfs-flags
165
166         # Workaround for bug #76512
167         if use hardened; then
168                 [[ "$(gcc-version)" == "3.4" ]] && replace-flags -O? -Os
169         fi
170
171         # Remove annoying C++ comment style warnings - bug #378099
172         append-flags -Wno-comment
173
174         sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
175         sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
176         emake DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" makefiles
177 }
178
179 src_install () {
180         local myconf
181         use doc && myconf="readme_directory=\"/usr/share/doc/${PF}/readme\" \
182                 html_directory=\"/usr/share/doc/${PF}/html\""
183
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                 ${myconf} \
194                 || die "postfix-install failed"
195
196         # Fix spool removal on upgrade
197         rm -Rf "${D}"/var
198         keepdir /var/spool/postfix
199
200         # Install rmail for UUCP, closes bug #19127
201         dobin auxiliary/rmail/rmail
202
203         # Provide another link for legacy FSH
204         dosym /usr/sbin/sendmail /usr/$(get_libdir)/sendmail
205
206         # Install qshape tool
207         dobin auxiliary/qshape/qshape.pl
208         doman man/man1/qshape.1
209
210         # Performance tuning tools and their manuals
211         dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
212         doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
213
214         # Set proper permissions on required files/directories
215         dodir /var/lib/postfix
216         keepdir /var/lib/postfix
217         fowners -R postfix:postfix /var/lib/postfix
218         fperms 0750 /var/lib/postfix
219         fowners root:postdrop /usr/sbin/post{drop,queue}
220         fperms 02711 /usr/sbin/post{drop,queue}
221
222         keepdir /etc/postfix
223         if use mbox; then
224                 mypostconf="mail_spool_directory=/var/spool/mail"
225         else
226                 mypostconf="home_mailbox=.maildir/"
227         fi
228         "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
229                 -e ${mypostconf} || die "postconf failed"
230
231         insinto /etc/postfix
232         newins "${FILESDIR}"/smtp.pass saslpass
233         fperms 600 /etc/postfix/saslpass
234
235         newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
236         # do not start mysql/postgres unnecessarily - bug #359913
237         use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
238         use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
239
240         dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
241         mv "${D}"/etc/postfix/{*.default,makedefs.out} "${D}"/usr/share/doc/${PF}/
242         use doc && mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
243
244         pamd_mimic_system smtp auth account
245
246         if use sasl; then
247                 insinto /etc/sasl2
248                 newins "${FILESDIR}"/smtp.sasl smtpd.conf
249         fi
250
251         # header files
252         insinto /usr/include/postfix
253         doins include/*.h
254
255         # Remove unnecessary files
256         rm -f "${D}"/etc/postfix/{*LICENSE,access,aliases,canonical,generic}
257         rm -f "${D}"/etc/postfix/{header_checks,relocated,transport,virtual}
258
259         systemd_dounit "${FILESDIR}/${PN}.service"
260 }
261
262 pkg_preinst() {
263         # Postfix 2.9.
264         # default for inet_protocols changed from ipv4 to all in postfix-2.9.
265         # check inet_protocols setting in main.cf and modify if necessary to prevent
266         # performance loss with useless DNS lookups and useless connection attempts.
267         [[ -d ${ROOT}/etc/postfix ]] && {
268         if [[ "$(${D}/usr/sbin/postconf -dh inet_protocols)" != "ipv4" ]]; then
269                 if [[ ! -n "$(${D}/usr/sbin/postconf -c ${ROOT}/etc/postfix -n inet_protocols)" ]];
270                 then
271                         ewarn "\nCOMPATIBILITY: adding inet_protocols=ipv4 to main.cf."
272                         ewarn "That will keep the same behaviour as previous postfix versions."
273                         ewarn "Specify inet_protocols explicitly if you want to enable IPv6.\n"
274                 else
275                         # delete inet_protocols setting. there is already one in /etc/postfix
276                         sed -i -e /inet_protocols/d "${D}"/etc/postfix/main.cf || die
277                 fi
278         fi
279         }
280 }
281
282 pkg_postinst() {
283         # Do not install server.{key,pem) SSL certificates if they already exist
284         if use ssl && [[ ! -f "${ROOT}"/etc/ssl/postfix/server.key \
285                 && ! -f "${ROOT}"/etc/ssl/postfix/server.pem ]] ; then
286                 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Postfix SMTP Server}"
287                 install_cert /etc/ssl/postfix/server
288                 chown postfix:mail "${ROOT}"/etc/ssl/postfix/server.{key,pem}
289         fi
290
291         if [[ ! -e /etc/mail/aliases.db ]] ; then
292                 ewarn
293                 ewarn "You must edit /etc/mail/aliases to suit your needs"
294                 ewarn "and then run /usr/bin/newaliases. Postfix will not"
295                 ewarn "work correctly without it."
296                 ewarn
297         fi
298 }