app-editors/kakoune: drop old 0_pre20160620
[gentoo.git] / net-mail / vpopmail / vpopmail-5.4.33-r1.ebuild
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5
6 inherit autotools eutils fixheadtails qmail user
7
8 HOMEPAGE="http://www.inter7.com/index.php?page=vpopmail"
9 DESCRIPTION="A collection of programs to manage virtual email domains and accounts on your Qmail mail servers"
10 SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"
11
12 LICENSE="GPL-2"
13 SLOT="0"
14 KEYWORDS="~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
15 IUSE="clearpasswd ipalias maildrop mysql postgres spamassassin"
16 REQUIRED_USE="mysql? ( !postgres )"
17
18 DEPEND="virtual/qmail
19         maildrop? ( mail-filter/maildrop )
20         mysql? ( virtual/mysql )
21         postgres? ( dev-db/postgresql[server] )
22         spamassassin? ( mail-filter/spamassassin )"
23 RDEPEND="${DEPEND}"
24
25 # This makes sure the variable is set, and that it isn't null.
26 VPOP_DEFAULT_HOME="/var/vpopmail"
27
28 vpopmail_set_homedir() {
29         VPOP_HOME=$(egethome vpopmail)
30         if [[ -z "${VPOP_HOME}" ]]; then
31                 ebeep
32                 eerror "vpopmail's home directory is null in passwd data!"
33                 eerror "You probably want to check that out."
34                 eerror "Continuing with default."
35                 VPOP_HOME="${VPOP_DEFAULT_HOME}"
36         else
37                 einfo "Setting VPOP_HOME to: $VPOP_HOME"
38         fi
39 }
40
41 pkg_setup() {
42         enewgroup vpopmail 89
43         enewuser vpopmail 89 -1 ${VPOP_DEFAULT_HOME} vpopmail
44         upgradewarning
45 }
46
47 src_prepare() {
48         epatch "${FILESDIR}"/${PN}-5.4.9-access.violation.patch
49         epatch "${FILESDIR}"/${PN}-lazy.patch
50         epatch "${FILESDIR}"/${PN}-double-free.patch
51         epatch "${FILESDIR}"/${PN}-vpgsql.patch
52
53         echo 'install-recursive: install-exec-am' \
54                 >>"${S}"/Makefile.am
55
56         # fix maildir paths
57         sed -i -e 's|Maildir|.maildir|g' \
58                 vchkpw.c vconvert.c vdelivermail.c \
59                 vpopbull.c vpopmail.c vqmaillocal.c \
60                 vuserinfo.c maildirquota.c || die
61
62         # remove vpopmail advertisement
63         sed -i -e '/printf.*vpopmail/s:vpopmail (:(:' \
64                 vdelivermail.c vpopbull.c vqmaillocal.c || die
65
66         # automake/autoconf
67         mv -f "${S}"/configure.{in,ac} || die
68         sed -i -e 's,AM_CONFIG_HEADER,AC_CONFIG_HEADERS,g' \
69                 configure.ac || die
70
71         # _FORTIFY_SOURCE
72         sed -i \
73                 -e 's/\(snprintf(\s*\(LI->[a-zA-Z_]\+\),\s*\)[a-zA-Z_]\+,/\1 sizeof(\2),/' \
74                 vlistlib.c || die
75
76         eautoreconf
77         ht_fix_file cdb/Makefile
78 }
79
80 src_configure() {
81         vpopmail_set_homedir
82
83         local authopts
84         if use mysql; then
85                 mysqlinc=$(mysql_config --include)
86                 authopts="--enable-incdir=${mysqlinc#-I}"
87                 authopts+=" --enable-auth-module=mysql"
88                 authopts+="     --enable-libdir=/usr/$(get_libdir)/mysql"
89                 authopts+="     --enable-sql-logging"
90                 authopts+=" --enable-valias"
91                 authopts+="     --disable-mysql-replication"
92                 authopts+="     --enable-mysql-limits"
93         elif use postgres; then
94                 pglibdir=$(pg_config --libdir)
95                 authopts+=" --enable-auth-module=pgsql"
96                 authopts+=" --enable-libdir=${pglibdir}"
97                 authopts+=" --enable-sql-logging"
98                 authopts+=" --enable-valias"
99         else
100                 authopts+=" --enable-auth-module=cdb"
101         fi
102
103         econf ${authopts} \
104                 --sysconfdir=${VPOP_HOME}/etc \
105                 --enable-non-root-build \
106                 --enable-qmaildir=${QMAIL_HOME} \
107                 --enable-qmail-newu=${QMAIL_HOME}/bin/qmail-newu \
108                 --enable-qmail-inject=${QMAIL_HOME}/bin/qmail-inject \
109                 --enable-qmail-newmrh=${QMAIL_HOME}/bin/qmail-newmrh \
110                 --enable-vpopuser=vpopmail \
111                 --enable-vpopgroup=vpopmail \
112                 --enable-many-domains \
113                 --enable-file-locking \
114                 --enable-file-sync \
115                 --enable-md5-passwords \
116                 --enable-logging \
117                 --enable-auth-logging \
118                 --enable-log-name=vpopmail \
119                 --enable-qmail-ext \
120                 --disable-tcpserver-file \
121                 --disable-roaming-users \
122                 $(use_enable ipalias ip-alias-domains) \
123                 $(use_enable clearpasswd clear-passwd) \
124                 $(use_enable maildrop) \
125                 $(use_enable maildrop maildrop-prog /usr/bin/maildrop) \
126                 $(use_enable spamassassin)
127 }
128
129 src_install() {
130         vpopmail_set_homedir
131
132         emake DESTDIR="${D}" install
133         keepdir "${VPOP_HOME}"/domains
134
135         # install helper script for maildir conversion
136         into "${VPOP_HOME}"
137         dobin "${FILESDIR}"/vpopmail-Maildir-dotmaildir-fix.sh
138         into /usr
139
140         dodoc doc/AUTHORS ChangeLog doc/FAQ doc/INSTALL doc/README*
141         dohtml doc/doc_html/* doc/man_html/*
142         rm -rf "${D}/${VPOP_HOME}"/doc
143         dosym /usr/share/doc/${PF}/ "${VPOP_HOME}"/doc
144
145         # create /etc/vpopmail.conf
146         if use mysql; then
147                 dodir /etc
148                 mv "${D}${VPOP_HOME}"/etc/vpopmail.mysql "${D}"/etc/vpopmail.conf
149                 dosym /etc/vpopmail.conf "${VPOP_HOME}"/etc/vpopmail.mysql
150
151                 sed -e '12d' -i "${D}"/etc/vpopmail.conf
152                 echo '# Read-only DB' >> "${D}"/etc/vpopmail.conf
153                 echo 'localhost|0|vpopmail|secret|vpopmail' >> "${D}"/etc/vpopmail.conf
154                 echo '# Write DB' >> "${D}"/etc/vpopmail.conf
155                 echo 'localhost|0|vpopmail|secret|vpopmail' >> "${D}"/etc/vpopmail.conf
156
157                 # lock down perms
158                 fperms 640 /etc/vpopmail.conf
159                 fowners root:vpopmail /etc/vpopmail.conf
160         fi
161
162         insinto "${VPOP_HOME}"/etc
163         doins vusagec.conf
164         dosym "${VPOP_HOME}"/etc/vusagec.conf /etc/vusagec.conf
165         sed -i 's/Disable = False;/Disable = True;/g' "${D}${VPOP_HOME}"/etc/vusagec.conf
166
167         einfo "Installing env.d entry"
168         dodir /etc/env.d
169         doenvd "${FILESDIR}"/99vpopmail
170
171         einfo "Locking down vpopmail permissions"
172         fowners -R root:0 "${VPOP_HOME}"/{bin,etc,include}
173         fowners root:vpopmail "${VPOP_HOME}"/bin/vchkpw
174         fperms 4711 "${VPOP_HOME}"/bin/vchkpw
175 }
176
177 pkg_postinst() {
178         if use mysql ; then
179                 elog
180                 elog "You have 'mysql' turned on in your USE"
181                 elog "Vpopmail needs a VALID MySQL USER. Let's call it 'vpopmail'"
182                 elog "You MUST add it and then specify its passwd in the /etc/vpopmail.conf file"
183                 elog
184                 elog "First log into mysql as your mysql root user and pass. Then:"
185                 elog "> create database vpopmail;"
186                 elog "> use mysql;"
187                 elog "> grant select, insert, update, delete, create, drop on vpopmail.* to"
188                 elog "  vpopmail@localhost identified by 'your password';"
189                 elog "> flush privileges;"
190                 elog
191                 elog "If you have problems with vpopmail not accepting mail properly,"
192                 elog "please ensure that /etc/vpopmail.conf is chmod 640 and"
193                 elog "owned by root:vpopmail"
194                 elog
195         fi
196
197         # do this for good measure
198         if [[ -e /etc/vpopmail.conf ]]; then
199                 chmod 640 /etc/vpopmail.conf
200                 chown root:vpopmail /etc/vpopmail.conf
201         fi
202
203         upgradewarning
204 }
205
206 pkg_postrm() {
207         vpopmail_set_homedir
208
209         elog "The vpopmail DATA will NOT be removed automatically."
210         elog "You can delete them manually by removing the ${VPOP_HOME} directory."
211 }
212
213 upgradewarning() {
214         ewarn
215         ewarn "Massive important warning if you are upgrading to 5.2.1-r8 or older"
216         ewarn "The internal structure of the mail storage has changed for"
217         ewarn "consistancy with the rest of Gentoo! Please review and utilize the "
218         ewarn "script at ${VPOP_HOME}/bin/vpopmail-Maildir-dotmaildir-fix.sh"
219         ewarn "to upgrade your system! (It can do conversions both ways)."
220         ewarn "You should be able to run it right away without any changes."
221         ewarn
222
223         elog
224         elog "Use of vpopmail's tcp.smtp[.cdb] is also deprecated now, consider"
225         elog "using net-mail/relay-ctrl instead."
226         elog
227
228         if use mysql; then
229                 elog
230                 elog "If you are upgrading from 5.4.17 or older, you have to fix your"
231                 elog "MySQL tables:"
232                 elog
233                 elog 'ALTER TABLE `dir_control` CHANGE `domain` `domain` CHAR(96) NOT NULL;'
234                 elog 'ALTER TABLE `ip_alias_map` CHANGE domain domain CHAR(96) NOT NULL;'
235                 elog 'ALTER TABLE `lastauth` CHANGE domain domain CHAR(96) NOT NULL;'
236                 elog 'ALTER TABLE `valias` CHANGE domain domain CHAR(96) NOT NULL;'
237                 elog 'ALTER TABLE `vlog` CHANGE domain domain CHAR(96) NOT NULL;'
238                 elog 'ALTER TABLE `vpopmail` CHANGE domain domain CHAR(96) NOT NULL;'
239                 elog 'ALTER TABLE `limits` CHANGE domain domain CHAR(96) NOT NULL,'
240                 elog '    ADD `disable_spamassassin` TINYINT(1) DEFAULT '0' NOT NULL AFTER `disable_smtp`,'
241                 elog '    ADD `delete_spam` TINYINT(1) DEFAULT '0' NOT NULL AFTER `disable_spamassassin`;'
242                 elog
243         fi
244
245         ewarn
246         ewarn "Newer versions of vpopmail contain a quota daemon called vusaged."
247         ewarn "This ebuild DOES NOT INSTALL vusaged and has therefore disabled"
248         ewarn "its usage in ${VPOP_HOME}/etc/vusagec.conf. DO NOT ENABLE!"
249         ewarn "Otherwise mail delivery WILL BREAK"
250         ewarn
251 }