1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 inherit pam systemd toolchain-funcs
8 MY_SRC="${PN}-${MY_PV}"
9 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/experimental"
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"
16 LICENSE="|| ( IBM EPL-2.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"
21 DEPEND=">=dev-libs/libpcre-3.4
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 )
32 postgres? ( dev-db/postgresql:* )
33 sasl? ( >=dev-libs/cyrus-sasl-2 )
34 sqlite? ( dev-db/sqlite:3 )
36 !libressl? ( dev-libs/openssl:0= )
37 libressl? ( >=dev-libs/libressl-2.9.1:0= )
44 memcached? ( net-misc/memcached )
58 selinux? ( sec-policy/selinux-postfix )"
60 REQUIRED_USE="ldap-bind? ( ldap sasl )"
62 S="${WORKDIR}/${MY_SRC}"
65 "${FILESDIR}/${PN}-libressl-certkey.patch"
66 "${FILESDIR}/${PN}-libressl-server.patch"
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"
78 for name in CDB LDAP LMDB MYSQL PCRE PGSQL SDBM SQLITE
80 local AUXLIBS_${name}=""
83 # Make sure LDFLAGS get passed down to the executables.
84 local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -ldl"
85 AUXLIBS_PCRE="$(pcre-config --libs)"
87 use pam && mylibs="${mylibs} -lpam"
90 mycc="${mycc} -DHAS_LDAP"
91 AUXLIBS_LDAP="-lldap -llber"
95 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
96 AUXLIBS_MYSQL="$(mysql_config --libs)"
100 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
101 AUXLIBS_PGSQL="-L$(pg_config --libdir) -lpq"
105 mycc="${mycc} -DHAS_SQLITE"
106 AUXLIBS_SQLITE="-lsqlite3 -lpthread"
110 mycc="${mycc} -DUSE_TLS"
111 mylibs="${mylibs} -lssl -lcrypto"
115 mycc="${mycc} -DHAS_LMDB"
116 AUXLIBS_LMDB="-llmdb -lpthread"
120 mycc="${mycc} -DNO_EAI"
123 # broken. and "in other words, not supported" by upstream.
124 # Use inet_protocols setting in main.cf
126 # mycc="${mycc} -DNO_IPV6"
130 if use dovecot-sasl; then
131 # Set dovecot as default.
132 mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
134 if use ldap-bind; then
135 mycc="${mycc} -DUSE_LDAP_SASL"
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\\\""
144 mycc="${mycc} -DNO_NIS"
147 if ! use berkdb; then
148 mycc="${mycc} -DNO_DB"
150 # change default hash format from Berkeley DB to cdb
151 mycc="${mycc} -DDEF_DB_TYPE=\\\"cdb\\\""
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"
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}"
170 sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
171 sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
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}"
183 LD_LIBRARY_PATH="${S}/lib" \
184 /bin/sh postfix-install \
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"
195 # Fix spool removal on upgrade
197 keepdir /var/spool/postfix
199 # Install rmail for UUCP, closes bug #19127
200 dobin auxiliary/rmail/rmail
202 # Provide another link for legacy FSH
203 dosym ../sbin/sendmail /usr/$(get_libdir)/sendmail
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
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
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}
227 keepdir /etc/postfix/postfix-files.d
229 mypostconf="mail_spool_directory=/var/spool/mail"
231 mypostconf="home_mailbox=.maildir/"
233 LD_LIBRARY_PATH="${S}/lib" \
234 "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
235 -e ${mypostconf} || die "postconf failed"
238 newins "${FILESDIR}"/smtp.pass saslpass
239 fperms 600 /etc/postfix/saslpass
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"
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
251 pamd_mimic_system smtp auth account
255 newins "${FILESDIR}"/smtp.sasl smtpd.conf
259 insinto /usr/include/postfix
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
267 systemd_dounit "${FILESDIR}/${PN}.service"
271 if [[ ! -e /etc/mail/aliases.db ]] ; then
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."
279 # check and fix file permissions
280 "${EROOT}"/usr/sbin/postfix set-permissions
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
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