]> Pileus Git - ~andy/sunrise/blob - mail-filter/MailScanner/MailScanner-4.55.10.3.ebuild
669bf4f0a07847de59a005bd6695e75b5c90c6e7
[~andy/sunrise] / mail-filter / MailScanner / MailScanner-4.55.10.3.ebuild
1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4
5 inherit eutils versionator
6
7 MY_PV=$(get_version_component_range 1-3 )
8 MY_PVR=$(replace_version_separator 3 '-' )
9
10 DESCRIPTION="Free Anti-Virus and Anti-Spam Filter"
11 HOMEPAGE="http://www.mailscanner.info/"
12 SRC_URI="http://www.mailscanner.info/files/4/tar/${PN}-install-${MY_PVR}.tar.gz"
13
14 LICENSE="GPL-2"
15 SLOT="0"
16 KEYWORDS="~x86"
17 IUSE="bitdefender clamav doc exim f-prot postfix sendmail spamassassin vlnx"
18
19 DEPEND="dev-lang/perl"
20 RDEPEND="${DEPEND}
21         dev-perl/Archive-Zip
22         dev-perl/Compress-Zlib
23         dev-perl/Convert-BinHex
24         dev-perl/Convert-TNEF
25         dev-perl/DBD-SQLite
26         dev-perl/DBI
27         >=dev-perl/HTML-Parser-3.45
28         dev-perl/HTML-Tagset
29         dev-perl/IO-stringy
30         >=dev-perl/MIME-tools-5.417
31         dev-perl/MailTools
32         dev-perl/Net-CIDR
33         dev-perl/Net-DNS
34         dev-perl/TimeDate
35         dev-perl/Sys-Hostname-Long
36         >=net-mail/tnef-1.4.3
37         perl-core/File-Spec
38         perl-core/File-Temp
39         perl-core/Getopt-Long
40         >=perl-core/Sys-Syslog-0.18
41         >=perl-core/MIME-Base64-3.05
42         virtual/cron
43         || (
44                 sendmail? ( mail-mta/sendmail )
45                 postfix? ( mail-mta/postfix )
46                 exim? ( mail-mta/exim )
47                 mail-mta/sendmail
48         )
49         bitdefender? ( app-antivirus/bitdefender-console )
50         clamav? ( >=app-antivirus/clamav-0.88.4 )
51         f-prot? ( app-antivirus/f-prot )
52         spamassassin? ( >=mail-filter/spamassassin-3.1.5 )
53         vlnx? ( app-antivirus/vlnx )"
54
55 S="${WORKDIR}/${PN}-${MY_PV}"
56 BASE="/usr"
57
58 src_unpack() {
59         unpack ${A}
60         unpack ./${PN}-install-${MY_PV}/perl-tar/${PN}-${MY_PVR}.tar.gz
61 }
62
63 src_compile() {
64         cd "${S}"
65         # setup MTA
66         if use postfix ; then
67                 RUNASUSER='postfix'
68                 RUNASGROUP='postfix'
69                 INQUEUE='/var/spool/postfix.in/deferred'
70                 OUTQUEUE='/var/spool/postfix/incoming'
71                 MTA='postfix'
72                 SENDMAIL='/usr/lib/sendmail'
73                 SENDMAIL2='/usr/lib/sendmail'
74         elif use exim ; then
75                 RUNASUSER='mail'
76                 RUNASGROUP='mail'
77                 INQUEUE='/var/spool/exim.in/input'
78                 OUTQUEUE='/var/spool/exim/input'
79                 MTA='exim'
80                 SENDMAIL='/usr/sbin/exim -oMr MailScanner'
81                 SENDMAIL2='/usr/sbin/exim -C /etc/exim/exim_out.conf -oMr MailScanner'
82         else
83         #       use sendmail as default, but we should add more as needed
84         #       RUNASUSER='mail'
85         #       RUNASGROUP='mail'
86                 INQUEUE='/var/spool/mqueue.in'
87                 OUTQUEUE='/var/spool/mqueue'
88                 MTA='sendmail'
89                 SENDMAIL='/usr/lib/sendmail'
90                 SENDMAIL2='/usr/lib/sendmail'
91         fi
92
93         # update init script parameters for selected MTA
94         sed \
95                 -e "s|^\(MTA=\).*|\1${MTA}|g" \
96                 "${FILESDIR}/confd.mailscanner-mta" > "${S}/confd.mailscanner-mta"
97
98         # setup virus scanner(s)
99         VIRUS_SCANNERS=""
100         use bitdefender && VIRUS_SCANNERS="bitdefender ${VIRUS_SCANNERS}"
101         use clamav && VIRUS_SCANNERS="clamav ${VIRUS_SCANNERS}"
102         use f-prot && VIRUS_SCANNERS="f-prot ${VIRUS_SCANNERS}"
103         use vlnx && VIRUS_SCANNERS="mcafee ${VIRUS_SCANNERS}"
104
105         if [ "$VIRUS_SCANNERS" == "" ]; then
106                 VIRUS_SCANNERS="none"
107                 VIRUS_SCANNING="no"
108         else
109                 VIRUS_SCANNING="yes"
110         fi
111
112         sed -i \
113                 -e "s/^\(Virus Scanning[ \t]*=\).*/\1 ${VIRUS_SCANNING}/" \
114                 -e "s/^\(Virus Scanners[ \t]*=\).*/\1 ${VIRUS_SCANNERS}/" \
115                 "${S}/etc/MailScanner.conf"
116
117         # setup spamassassin
118         if use spamassassin ; then
119                 sed -i \
120                         -e "s/^\(Use SpamAssassin[ \t]*=\).*$/\1 yes/" \
121                         "${S}/etc/MailScanner.conf"
122         else
123                 sed -i \
124                         -e "s/^\(Use SpamAssassin[ \t]*=\).*$/\1 no/" \
125                         "${S}/etc/MailScanner.conf"
126         fi
127
128         # update bin files
129         sed -i \
130                 -e "s#msbindir=/opt/MailScanner/bin#msbindir=/usr/sbin#g" \
131                 -e "s#config=/opt/MailScanner/etc/MailScanner.conf#config=/etc/MailScanner/MailScanner.conf#g" \
132                 "${S}/bin/check_mailscanner"
133         sed -i \
134                 -e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
135                 "${S}/bin/update_virus_scanners"
136         sed -i \
137                 -e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
138                 -e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#g" \
139                 "${S}/bin/MailScanner"
140
141         # update cron files
142         sed -i \
143                 -e "s#/opt/MailScanner/bin/check_mailscanner#/usr/sbin/check_MailScanner#g" \
144                 "${S}/bin/cron/check_MailScanner.cron"
145         sed -i \
146                 -e "s#/etc/sysconfig/MailScanner#/etc/conf.d/mailscanner#g" \
147                 -e "s#/opt/MailScanner/bin/update_virus_scanners#/usr/sbin/update_virus_scanners#g" \
148                 "${S}/bin/cron/update_virus_scanners.cron"
149
150         # Determine some things that may need to be changed in conf file
151         # (need to arrive at sensible replacement for yoursite)
152         YOURSITE=`dnsdomainname | sed -e "s/\./-/g"`
153         BASEBIN="${BASE}/sbin"
154
155         # ClamAV requires some specific changes to MailScanner.conf
156         # when mailscanner is running as root (i.e. sendmail)
157         if use clamav ; then
158                 if [ "$MTA" == "sendmail" ] ; then
159                         WORKGRP="clamav"
160                         WORKPERM="0640"
161                 else
162                         WORKGRP=""
163                         WORKPERM="0600"
164                 fi
165         else
166                 WORKGRP=""
167                 WORKPERM="0600"
168         fi
169
170         # update conf files
171         sed -i \
172                 -e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
173                 -e "s#/opt/MailScanner/bin#$BASEBIN#g" \
174                 -e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#g" \
175                 -e "s#^\(Run As User[ \t]*=\).*#\1 $RUNASUSER#" \
176                 -e "s#^\(Run As Group[ \t]*=\).*#\1 $RUNASGROUP#" \
177                 -e "s#^\(Incoming Queue Dir[ \t]*=\).*#\1 $INQUEUE#" \
178                 -e "s#^\(Outgoing Queue Dir[ \t]*=\).*#\1 $OUTQUEUE#" \
179                 -e "s#^\(MTA[ \t]*=\).*#\1 $MTA#" \
180                 -e "s/^#\(TNEF.*internal\)$/\1/" \
181                 -e "s/^\(TNEF.*0000\)$/#\1/" \
182                 -e "s#^\(PID file[ \t]=\).*#\1 /var/run/mailscanner.pid#" \
183                 -e "s#^\(%org-name%\)[ \t]*=.*#\1 = ${YOURSITE}#" \
184                 -e "s#^\(Sendmail[ \t]*=\).*#\1 ${SENDMAIL}#" \
185                 -e "s#^\(Sendmail2[ \t]*=\).*#\1 ${SENDMAIL2}#" \
186                 -e "s#^\(Incoming Work Group[ \t]*=\).*#\1 ${WORKGRP}#" \
187                 -e "s#^\(Incoming Work Permissions[ \t]*=\).*#\1 ${WORKPERM}#" \
188                 "${S}/etc/MailScanner.conf"
189
190         # net-mail/vlnx net-mail/clamav net-mail/f-prot package compatibility
191         sed -i \
192                 -e "s#PREFIX=/usr/local/uvscan#PREFIX=/opt/vlnx#" \
193                 "${S}/lib/mcafee-autoupdate"
194         sed -i \
195                 -e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#" \
196                 -e 's#^\(mcafee.*\)/usr/local/uvscan$#\1/opt/vlnx#' \
197                 -e 's#^\(clamav\t.*/usr\)/local$#\1#' \
198                 -e 's#^\(f-prot.*\)/usr/local/f-prot$#\1/opt/f-prot#' \
199                 "${S}/etc/virus.scanners.conf"
200
201         # update lib files
202         sed -i \
203                 -e "s#/opt/MailScanner/bin#$BASEBIN#g" \
204                 -e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
205                 -e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#g" \
206                 "${S}/lib/MailScanner/ConfigDefs.pl"
207         sed -i \
208                 -e "s#/etc/MailScanner#/etc/MailScanner#g" \
209                 "${S}/lib/MailScanner/CustomConfig.pm"
210
211         # finally, change MailScanner.conf into MailScanner.conf.sample
212         cp "${S}/etc/MailScanner.conf" "${S}/etc/MailScanner.conf.${MY_PV}"
213         mv "${S}/etc/MailScanner.conf" "${S}/etc/MailScanner.conf.sample"
214
215 }
216
217 src_install() {
218         cd "${S}"
219         exeinto ${BASE}/sbin
220         #newexe bin/check_mailscanner.linux check_MailScanner
221         newexe  bin/check_mailscanner check_MailScanner
222         doexe   bin/df2mbox
223         doexe   bin/MailScanner
224         doexe   bin/update_virus_scanners
225         doexe   bin/upgrade_MailScanner_conf
226         newexe  bin/Sophos.install.linux Sophos.install
227
228         insinto /etc/MailScanner
229         doins   etc/*.conf
230         doins   etc/mailscanner.conf.with.mcp
231         doins   etc/MailScanner.conf.${MY_PV}
232         doins   etc/MailScanner.conf.sample
233
234         insinto /etc/MailScanner/rules
235         doins   etc/rules/*
236         insinto /etc/MailScanner/mcp
237         doins   etc/mcp/*
238
239         for i in $(ls etc/reports/)
240         do
241                 if [ $i != "cat" ]
242                 then
243                         insinto /etc/MailScanner/reports/$i
244                         doins etc/reports/$i/*
245                 fi
246         done
247
248         insinto ${BASE}/lib/MailScanner
249         doins   lib/*.prf
250
251         exeinto ${BASE}/lib/MailScanner
252         doexe   lib/*-wrapper
253         doexe   lib/*-autoupdate
254         doexe   lib/*-autoupdate.old
255         doexe   lib/*.pm
256
257         exeinto ${BASE}/lib/MailScanner/MailScanner
258         doexe   lib/MailScanner/*.pm
259         doexe   lib/MailScanner/*.pl
260
261         insinto ${BASE}/lib/MailScanner/MailScanner
262         doins   lib/MailScanner/*.txt
263
264         exeinto ${BASE}/lib/MailScanner/MailScanner/CustomFunctions
265         doexe   lib/MailScanner/CustomFunctions/MyExample.pm
266
267         newinitd "${FILESDIR}"/initd.mailscanner MailScanner
268         newinitd "${FILESDIR}"/initd.mailscanner-mta MailScanner-mta
269         newconfd "${FILESDIR}"/confd.mailscanner MailScanner
270         newconfd "${S}/confd.mailscanner-mta" MailScanner-mta
271
272         #Set up cron jobs
273         exeinto /etc/cron.hourly
274         newexe "${S}/bin/cron/check_MailScanner.cron" check_MailScanner
275         newexe "${S}/bin/cron/update_virus_scanners.cron" update_virus_scanners
276
277         exeinto /etc/cron.daily
278         newexe "${S}/bin/cron/clean.quarantine.cron" clean.quarantine
279
280         if use doc ; then
281                 dodir /usr/share/doc/${PF}/html
282                 cp -r docs/* "${D}usr/share/doc/${PF}/html"
283         fi
284
285         dodoc notes.txt docs/QuickInstall.txt docs/README.sql-logging
286
287         keepdir /var/spool/MailScanner/incoming
288         keepdir /var/spool/MailScanner/quarantine
289         keepdir /var/spool/MailScanner/spamassassin
290         keepdir /var/spool/MailScanner/archive
291         keepdir ${BASE}/var
292
293         if use postfix ; then
294                 chown -R postfix:postfix "${D}/var/spool/MailScanner/"
295         elif use exim ; then
296                 chown -R mail:mail "${D}/var/spool/MailScanner/"
297         else
298                 keepdir /var/spool/mqueue.in
299         fi
300 }
301
302 pkg_postinst() {
303         if [ -n "`grep -xE "[[:space:]]*provide[[:space:]]+(.*[[:space:]]+)*mta([[:space:]]+.*)*" /etc/init.d/${MTA}`" ]; then
304                 ewarn
305                 ewarn "Warning: your mta service startup script /etc/init.d/${MTA}"
306                 ewarn "seems to provide 'mta', this may give problems with /etc/init.d/MailScanner-mta."
307                 ewarn
308                 ewarn "The Installation is *NOT* Completed Yet, You still need Filesystem::Df"
309                 ewarn "Please use emerge g-cpan and run the following command"
310                 ewarn
311                 ewarn " # g-cpan -i Filesys::Df "
312                 ewarn
313
314                 echo
315         fi
316         elog "Remove the line containing 'provide mta' from your MTA's init script"
317         elog "and take care that using etc-update will not insert this line after"
318         elog "re-emerging / updating your mta!"
319         elog "The related bug in bugs.gentoo.org is #46897"
320         echo
321
322         if [ -f "/etc/MailScanner/MailScanner.conf" ]; then
323                 einfo "Upgrading the MailScanner.conf file"
324                 cp /etc/MailScanner/MailScanner.conf /etc/MailScanner/MailScanner.conf.pre_upgrade.${MY_PV}
325                 /usr/sbin/upgrade_MailScanner_conf \
326                 /etc/MailScanner/MailScanner.conf.pre_upgrade.${MY_PV} \
327                 /etc/MailScanner/MailScanner.conf.${MY_PV} \
328                 > /etc/MailScanner/MailScanner.conf 2> /dev/null
329         else
330                 cp /etc/MailScanner/MailScanner.conf.sample /etc/MailScanner/MailScanner.conf
331         fi
332 }