aed561d90cedc032cd1c1062a14b82ab8c768ac8
[gentoo.git] / mail-filter / amavisd-new / amavisd-new-2.11.1-r3.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 inherit systemd user
6
7 DESCRIPTION="High-performance interface between the MTA and content checkers"
8 HOMEPAGE="https://gitlab.com/amavis/amavis"
9 SRC_URI="https://gitlab.com/amavis/amavis/-/archive/${P}/amavis-${P}.tar.gz"
10
11 LICENSE="GPL-2 BSD-2"
12 SLOT="0"
13 KEYWORDS="amd64 hppa ~ppc ppc64 sparc x86"
14 IUSE="clamav courier dkim ldap mysql postgres qmail razor snmp spamassassin zmq"
15
16 DEPEND=">=sys-apps/sed-4
17         >=dev-lang/perl-5.10.0"
18
19 RDEPEND="${DEPEND}
20         >=sys-apps/coreutils-5.0-r3
21         app-arch/cpio
22         app-arch/gzip
23         app-arch/bzip2
24         app-arch/arc
25         app-arch/cabextract
26         app-arch/lha
27         app-arch/lrzip
28         app-arch/lzop
29         app-arch/ncompress
30         app-arch/p7zip
31         app-arch/pax
32         app-arch/unarj
33         app-arch/unrar
34         app-arch/xz-utils
35         app-arch/zoo
36         net-mail/ripole
37         >=dev-perl/Archive-Zip-1.14
38         >=virtual/perl-IO-Compress-1.35
39         >=virtual/perl-Compress-Raw-Zlib-2.017
40         net-mail/tnef
41         virtual/perl-MIME-Base64
42         >=dev-perl/MIME-tools-5.415
43         >=dev-perl/MailTools-1.58
44         >=dev-perl/Net-Server-0.91
45         virtual/perl-Digest-MD5
46         dev-perl/IO-stringy
47         virtual/perl-IO-Socket-IP
48         >=virtual/perl-Time-HiRes-1.49
49         dev-perl/Unix-Syslog
50         dev-perl/Net-LibIDN
51         dev-perl/File-LibMagic
52         >=sys-libs/db-4.4.20
53         dev-perl/BerkeleyDB
54         dev-perl/Convert-BinHex
55         >=dev-perl/Mail-DKIM-0.31
56         virtual/perl-File-Temp
57         dev-perl/Net-SSLeay
58         dev-perl/IO-Socket-SSL
59         virtual/mta
60         clamav? ( app-antivirus/clamav )
61         ldap? ( >=dev-perl/perl-ldap-0.33 )
62         mysql? ( dev-perl/DBD-mysql )
63         postgres? ( dev-perl/DBD-Pg )
64         razor? ( mail-filter/razor )
65         snmp? ( net-analyzer/net-snmp[perl] )
66         spamassassin? ( mail-filter/spamassassin dev-perl/Image-Info )
67         zmq? ( dev-perl/ZMQ-LibZMQ3 )"
68
69 AMAVIS_ROOT="/var/amavis"
70 S="${WORKDIR}/amavis-${P}"
71
72 pkg_setup() {
73         # Create the user beforehand so that we can install the config file
74         # (and some directories) with group "amavis" in src_install().
75         enewgroup amavis
76         enewuser amavis -1 -1 "${AMAVIS_ROOT}" amavis
77 }
78
79 src_prepare() {
80         # amavisd-new version 2.11.0 breaks DKIM signing of outbound mail,
81         # see https://bugs.gentoo.org/603582
82         eapply "${FILESDIR}/amavisd-2.11.0-dkim.patch"
83
84         if use courier ; then
85                 eapply -p0 amavisd-new-courier.patch
86         fi
87
88         if use qmail ; then
89                 eapply -p0 amavisd-new-qmqpqq.patch
90         fi
91
92         # We need to fix the daemon_user and daemon_group in amavis-mc even
93         # though we're going to run it in the foreground, because it calls
94         # "drop_priv" unconditionally and will crash if its user/group
95         # doesn't exist.
96         sed -i  \
97                 -e '/daemon/s/vscan/amavis/' \
98                 -e "s:'/var/virusmails':\"\$MYHOME/quarantine\":" \
99                 "${S}/amavisd.conf" "${S}/amavis-mc" || die "missing conf file"
100
101         if ! use dkim ; then
102                 sed -i -e '/enable_dkim/s/1/0/' "${S}/amavisd.conf" \
103                         || die "missing conf file - dkim"
104         fi
105
106         if use zmq ; then
107                 sed -i -e '/enable_zmq/s/# //' "${S}/amavisd.conf" \
108                         || die "missing conf file - zmq"
109         fi
110
111         if ! use spamassassin ; then
112                 sed -i -e \
113                         "/^#[[:space:]]*@bypass_spam_checks_maps[[:space:]]*=[[:space:]]*(1)/s/^#//" \
114                         "${S}/amavisd.conf" || die "missing conf file - sa"
115         fi
116
117         eapply_user
118 }
119
120 src_install() {
121         dosbin amavisd{,-agent,-nanny,-release,-signer,-status}
122         dobin p0f-analyzer.pl amavisd-submit
123
124         if use snmp ; then
125                 dosbin amavisd-snmp-subagent
126                 newinitd "${FILESDIR}/amavisd-snmp-subagent.initd" \
127                                  amavisd-snmp-subagent
128                 dodoc AMAVIS-MIB.txt
129
130                 if use zmq ; then
131                         dosbin amavisd-snmp-subagent-zmq
132                         newinitd "${FILESDIR}/amavisd-snmp-subagent-zmq.initd" \
133                                          amavisd-snmp-subagent-zmq
134                 fi
135         fi
136
137         if use zmq ; then
138                 dosbin amavis-services amavis-mc
139                 newinitd "${FILESDIR}/amavis-mc.initd-r1" amavis-mc
140         fi
141
142         if use ldap ; then
143                 dodir /etc/openldap/schema
144                 insinto /etc/openldap/schema
145                 newins LDAP.schema "${PN}.schema"
146         fi
147
148         # The config file should be root:amavis so that the amavis user can
149         # read (only) it after dropping privileges. And of course he should
150         # own everything in his home directory.
151         insinto /etc
152         insopts -m0640 -g amavis
153         doins amavisd.conf
154
155         # Implementation detail? Keepdir calls dodir under the hood.
156         diropts -o amavis -g amavis
157         keepdir "${AMAVIS_ROOT}"/{,db,quarantine,tmp,var}
158
159         # BEWARE:
160         #
161         # Anything below this line is using the mangled insopts/diropts from
162         # above!
163         #
164
165         newinitd "${FILESDIR}/amavisd.initd-r2" amavisd
166
167         systemd_newunit "${FILESDIR}/amavisd.service-r1" amavisd.service
168
169         dodoc AAAREADME.first INSTALL MANIFEST RELEASE_NOTES TODO \
170                 amavisd.conf-default amavisd-custom.conf
171
172         docinto README_FILES
173         dodoc README_FILES/README*
174         dodoc -r README_FILES/*.{html,css}
175         docinto README_FILES/images
176         dodoc README_FILES/images/*.png
177         docinto README_FILES/images/callouts
178         dodoc README_FILES/images/callouts/*.png
179
180         docinto test-messages
181         dodoc test-messages/README
182         dodoc test-messages/sample.tar.gz.compl
183 }
184
185 pkg_preinst() {
186         # TODO: the following is done as root, but should probably be done
187         # as the amavis user.
188         if use razor ; then
189                 if [ ! -d "${ROOT}${AMAVIS_ROOT}/.razor" ] ; then
190                         elog "Setting up initial razor config files..."
191
192                         razor-admin -create -home="${D}/${AMAVIS_ROOT}/.razor"
193                         sed -i -e "s:debuglevel\([ ]*\)= .:debuglevel\1= 0:g" \
194                                 "${D}/${AMAVIS_ROOT}/.razor/razor-agent.conf" || die
195                 fi
196         fi
197 }