net-mail/automx2: amd64 stable wrt bug #721532
[gentoo.git] / net-mail / dovecot / dovecot-2.2.36.4.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 # do not add a ssl USE flag.  ssl is mandatory
7 SSL_DEPS_SKIP=1
8 inherit autotools eapi7-ver ssl-cert systemd toolchain-funcs user versionator
9
10 MY_P="${P/_/.}"
11 major_minor="$(ver_cut 1-2)"
12 sieve_version="0.4.24.2"
13 if [[ ${PV} == *_rc* ]] ; then
14         rc_dir="rc/"
15 else
16         rc_dir=""
17 fi
18 SRC_URI="https://dovecot.org/releases/${major_minor}/${rc_dir}${MY_P}.tar.gz
19         sieve? (
20         https://pigeonhole.dovecot.org/releases/${major_minor}/${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
21         )
22         managesieve? (
23         https://pigeonhole.dovecot.org/releases/${major_minor}/${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
24         ) "
25 DESCRIPTION="An IMAP and POP3 server written with security primarily in mind"
26 HOMEPAGE="https://www.dovecot.org/"
27
28 SLOT="0"
29 LICENSE="LGPL-2.1 MIT"
30 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sparc ~x86"
31
32 IUSE_DOVECOT_AUTH="kerberos ldap mysql pam postgres sqlite vpopmail"
33 IUSE_DOVECOT_COMPRESS="bzip2 lzma lz4 zlib"
34 IUSE_DOVECOT_OTHER="caps doc ipv6 libressl lucene managesieve selinux sieve solr static-libs suid tcpd textcat"
35
36 IUSE="${IUSE_DOVECOT_AUTH} ${IUSE_DOVECOT_STORAGE} ${IUSE_DOVECOT_COMPRESS} ${IUSE_DOVECOT_OTHER}"
37
38 DEPEND="bzip2? ( app-arch/bzip2 )
39         caps? ( sys-libs/libcap )
40         kerberos? ( virtual/krb5 )
41         ldap? ( net-nds/openldap )
42         lucene? ( >=dev-cpp/clucene-2.3 )
43         lzma? ( app-arch/xz-utils )
44         lz4? ( app-arch/lz4 )
45         mysql? ( dev-db/mysql-connector-c:0= )
46         pam? ( sys-libs/pam )
47         postgres? ( dev-db/postgresql:* !dev-db/postgresql[ldap,threads] )
48         selinux? ( sec-policy/selinux-dovecot )
49         solr? ( net-misc/curl dev-libs/expat )
50         sqlite? ( dev-db/sqlite:* )
51         !libressl? ( dev-libs/openssl:0= )
52         libressl? ( dev-libs/libressl:0= )
53         tcpd? ( sys-apps/tcp-wrappers )
54         textcat? ( app-text/libexttextcat )
55         vpopmail? ( net-mail/vpopmail )
56         zlib? ( sys-libs/zlib )
57         virtual/libiconv
58         dev-libs/icu:="
59
60 RDEPEND="${DEPEND}
61         net-mail/mailbase"
62
63 PATCHES=(
64         "${FILESDIR}/${PN}-userdb-passwd-fix.patch"
65 )
66
67 pkg_setup() {
68         if use managesieve && ! use sieve; then
69                 ewarn "managesieve USE flag selected but sieve USE flag unselected"
70                 ewarn "sieve USE flag will be turned on"
71         fi
72         # default internal user
73         enewgroup dovecot 97
74         enewuser dovecot 97 -1 /dev/null dovecot
75         # default login user
76         enewuser dovenull -1 -1 /dev/null
77         # add "mail" group for suid'ing. Better security isolation.
78         if use suid; then
79                 enewgroup mail
80         fi
81 }
82
83 src_prepare() {
84         default
85         # bug 657108
86         elibtoolize
87 }
88
89 src_configure() {
90         local conf=""
91
92         if use postgres || use mysql || use sqlite; then
93                 conf="${conf} --with-sql"
94         fi
95
96         # turn valgrind tests off. Bug #340791
97         VALGRIND=no econf \
98                 --with-statedir="${EPREFIX}/var/lib/dovecot" \
99                 --with-rundir="${EPREFIX}/run/dovecot" \
100                 --with-moduledir="${EPREFIX}/usr/$(get_libdir)/dovecot" \
101                 --without-stemmer \
102                 --disable-rpath \
103                 --with-icu \
104                 --with-ssl \
105                 --with-systemdsystemunitdir="$(systemd_get_systemunitdir)" \
106                 $( use_with bzip2 bzlib ) \
107                 $( use_with caps libcap ) \
108                 $( use_with kerberos gssapi ) \
109                 $( use_with ldap ) \
110                 $( use_with lucene ) \
111                 $( use_with lz4 ) \
112                 $( use_with lzma ) \
113                 $( use_with mysql ) \
114                 $( use_with pam ) \
115                 $( use_with postgres pgsql ) \
116                 $( use_with sqlite ) \
117                 $( use_with solr ) \
118                 $( use_with tcpd libwrap ) \
119                 $( use_with textcat ) \
120                 $( use_with vpopmail ) \
121                 $( use_with zlib ) \
122                 $( use_enable static-libs static ) \
123                 ${conf}
124
125         if use sieve || use managesieve ; then
126                 # The sieve plugin needs this file to be build to determine the plugin
127                 # directory and the list of libraries to link to.
128                 emake dovecot-config
129                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
130                 econf \
131                         $( use_enable static-libs static ) \
132                         --localstatedir="${EPREFIX}/var" \
133                         --enable-shared \
134                         --with-dovecot="${S}" \
135                         $( use_with managesieve )
136         fi
137 }
138
139 src_compile() {
140         default
141         if use sieve || use managesieve ; then
142                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
143                 emake CC="$(tc-getCC)" CFLAGS="${CFLAGS}"
144         fi
145 }
146
147 src_test() {
148         default
149         if use sieve || use managesieve ; then
150                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
151                 default
152         fi
153 }
154
155 src_install() {
156         default
157
158         # insecure:
159         # use suid && fperms u+s /usr/libexec/dovecot/deliver
160         # better:
161         if use suid;then
162                 einfo "Changing perms to allow deliver to be suided"
163                 fowners root:mail "/usr/libexec/dovecot/dovecot-lda"
164                 fperms 4750 "/usr/libexec/dovecot/dovecot-lda"
165         fi
166
167         newinitd "${FILESDIR}"/dovecot.init-r6 dovecot
168
169         rm -rf "${ED}"/usr/share/doc/dovecot
170
171         dodoc AUTHORS NEWS README TODO
172         dodoc doc/*.{txt,cnf,xml,sh}
173         docinto example-config
174         dodoc doc/example-config/*.{conf,ext}
175         docinto example-config/conf.d
176         dodoc doc/example-config/conf.d/*.{conf,ext}
177         docinto wiki
178         dodoc doc/wiki/*
179         doman doc/man/*.{1,7}
180
181         # Create the dovecot.conf file from the dovecot-example.conf file that
182         # the dovecot folks nicely left for us....
183         local conf="${ED}/etc/dovecot/dovecot.conf"
184         local confd="${ED}/etc/dovecot/conf.d"
185
186         insinto /etc/dovecot
187         doins doc/example-config/*.{conf,ext}
188         insinto /etc/dovecot/conf.d
189         doins doc/example-config/conf.d/*.{conf,ext}
190         fperms 0600 /etc/dovecot/dovecot-{ldap,sql}.conf.ext
191         rm -f "${confd}/../README"
192
193         # .maildir is the Gentoo default
194         local mail_location="maildir:~/.maildir"
195         sed -i -e \
196                 "s|#mail_location =|mail_location = ${mail_location}|" \
197                 "${confd}/10-mail.conf" \
198                 || die "failed to update mail location settings in 10-mail.conf"
199
200         # We're using pam files (imap and pop3) provided by mailbase
201         if use pam; then
202                 sed -i -e '/driver = pam/,/^[ \t]*}/ s|#args = dovecot|args = "\*"|' \
203                         "${confd}/auth-system.conf.ext" \
204                         || die "failed to update PAM settings in auth-system.conf.ext"
205                 # mailbase does not provide a sieve pam file
206                 use managesieve && dosym imap /etc/pam.d/sieve
207                 sed -i -e \
208                         's/#!include auth-system.conf.ext/!include auth-system.conf.ext/' \
209                         "${confd}/10-auth.conf" \
210                         || die "failed to update PAM settings in 10-auth.conf"
211         fi
212
213         # Disable ipv6 if necessary
214         if ! use ipv6; then
215                 sed -i -e 's/^#listen = \*, ::/listen = \*/g' "${conf}" \
216                         || die "failed to update listen settings in dovecot.conf"
217         fi
218
219         # Update ssl cert locations
220         sed -i -e 's:^#ssl = yes:ssl = yes:' "${confd}/10-ssl.conf" \
221                 || die "ssl conf failed"
222         sed -i -e 's:^ssl_cert =.*:ssl_cert = </etc/ssl/dovecot/server.pem:' \
223                 -e 's:^ssl_key =.*:ssl_key = </etc/ssl/dovecot/server.key:' \
224                 "${confd}/10-ssl.conf" || die "failed to update SSL settings in 10-ssl.conf"
225
226         # Install SQL configuration
227         if use mysql || use postgres; then
228                 sed -i -e \
229                         's/#!include auth-sql.conf.ext/!include auth-sql.conf.ext/' \
230                         "${confd}/10-auth.conf" || die "failed to update SQL settings in \
231                         10-auth.conf"
232         fi
233
234         # Install LDAP configuration
235         if use ldap; then
236                 sed -i -e \
237                         's/#!include auth-ldap.conf.ext/!include auth-ldap.conf.ext/' \
238                         "${confd}/10-auth.conf" \
239                         || die "failed to update ldap settings in 10-auth.conf"
240         fi
241
242         if use vpopmail; then
243                 sed -i -e \
244                         's/#!include auth-vpopmail.conf.ext/!include auth-vpopmail.conf.ext/' \
245                         "${confd}/10-auth.conf" \
246                         || die "failed to update vpopmail settings in 10-auth.conf"
247         fi
248
249         if use sieve || use managesieve ; then
250                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
251                 emake DESTDIR="${ED}" install
252                 sed -i -e \
253                         's/^[[:space:]]*#mail_plugins = $mail_plugins/mail_plugins = sieve/' "${confd}/15-lda.conf" \
254                         || die "failed to update sieve settings in 15-lda.conf"
255                 rm -rf "${ED}"/usr/share/doc/dovecot
256                 docinto example-config/conf.d
257                 dodoc doc/example-config/conf.d/*.conf
258                 insinto /etc/dovecot/conf.d
259                 doins doc/example-config/conf.d/90-sieve{,-extprograms}.conf
260                 use managesieve && doins doc/example-config/conf.d/20-managesieve.conf
261                 docinto sieve/rfc
262                 dodoc doc/rfc/*.txt
263                 docinto sieve/devel
264                 dodoc doc/devel/DESIGN
265                 docinto plugins
266                 dodoc doc/plugins/*.txt
267                 docinto extensions
268                 dodoc doc/extensions/*.txt
269                 docinto locations
270                 dodoc doc/locations/*.txt
271                 doman doc/man/*.{1,7}
272         fi
273
274         use static-libs || find "${ED}"/usr/lib* -name '*.la' -delete
275 }
276
277 pkg_postinst() {
278         # Let's not make a new certificate if we already have one
279         if ! [[ -e "${ROOT}"/etc/ssl/dovecot/server.pem && \
280         -e "${ROOT}"/etc/ssl/dovecot/server.key ]];     then
281                 einfo "Creating SSL     certificate"
282                 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Dovecot IMAP Server}"
283                 install_cert /etc/ssl/dovecot/server
284         fi
285
286         elog "Please read https://doc.dovecot.org/installation_guide/upgrading/ for upgrade notes."
287 }