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