summaryrefslogtreecommitdiff
blob: d48b7347087e01b27666db87e37e22a67bbbabcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils versionator

MY_PV=$(get_version_component_range 1-3 )
MY_PVR=$(replace_version_separator 3 '-' )

DESCRIPTION="Free Anti-Virus and Anti-Spam Filter"
HOMEPAGE="http://www.mailscanner.info/"
SRC_URI="http://www.mailscanner.info/files/4/tar/${PN}-install-${MY_PVR}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~x86"
IUSE="bitdefender clamav doc exim f-prot postfix spamassassin"

DEPEND="dev-lang/perl"
RDEPEND="${DEPEND}
	dev-perl/Archive-Zip
	dev-perl/Compress-Zlib
	dev-perl/Convert-BinHex
	dev-perl/Convert-TNEF
	dev-perl/DBD-SQLite
	dev-perl/DBI
	>=dev-perl/HTML-Parser-3.45
	dev-perl/HTML-Tagset
	dev-perl/IO-stringy
	>=dev-perl/MIME-tools-5.417
	dev-perl/MailTools
	dev-perl/Net-CIDR
	dev-perl/Net-DNS
	dev-perl/TimeDate
	dev-perl/Sys-Hostname-Long
	>=net-mail/tnef-1.4.3
	virtual/perl-File-Spec
	virtual/perl-File-Temp
	virtual/perl-Getopt-Long
	>=virtual/perl-Sys-Syslog-0.18
	>=virtual/perl-MIME-Base64-3.05
	virtual/cron
	!postfix? ( !exim? ( mail-mta/sendmail ) )
	postfix? ( mail-mta/postfix )
	exim? ( mail-mta/exim )
	bitdefender? ( app-antivirus/bitdefender-console )
	clamav? ( >=app-antivirus/clamav-0.88.4 )
	f-prot? ( app-antivirus/f-prot )
	spamassassin? ( >=mail-filter/spamassassin-3.1.5 )"

S="${WORKDIR}/${PN}-${MY_PV}"
BASE="/usr"

src_unpack() {
	unpack ${A}
	unpack ./${PN}-install-${MY_PV}/perl-tar/${PN}-${MY_PVR}.tar.gz
}

src_compile() {
	cd "${S}"
	# setup MTA
	if use postfix ; then
		RUNASUSER='postfix'
		RUNASGROUP='postfix'
		INQUEUE='/var/spool/postfix.in/deferred'
		OUTQUEUE='/var/spool/postfix/incoming'
		MTA='postfix'
		SENDMAIL='/usr/lib/sendmail'
		SENDMAIL2='/usr/lib/sendmail'
	elif use exim ; then
		RUNASUSER='mail'
		RUNASGROUP='mail'
		INQUEUE='/var/spool/exim.in/input'
		OUTQUEUE='/var/spool/exim/input'
		MTA='exim'
		SENDMAIL='/usr/sbin/exim -oMr MailScanner'
		SENDMAIL2='/usr/sbin/exim -C /etc/exim/exim_out.conf -oMr MailScanner'
	else
	#	use sendmail as default, but we should add more as needed
	#	RUNASUSER='mail'
	#	RUNASGROUP='mail'
		INQUEUE='/var/spool/mqueue.in'
		OUTQUEUE='/var/spool/mqueue'
		MTA='sendmail'
		SENDMAIL='/usr/lib/sendmail'
		SENDMAIL2='/usr/lib/sendmail'
	fi

	# update init script parameters for selected MTA
	sed \
		-e "s|^\(MTA=\).*|\1${MTA}|g" \
		"${FILESDIR}/confd.mailscanner-mta" > "${S}/confd.mailscanner-mta"

	# setup virus scanner(s)
	VIRUS_SCANNERS=""
	use bitdefender && VIRUS_SCANNERS="bitdefender ${VIRUS_SCANNERS}"
	use clamav && VIRUS_SCANNERS="clamav ${VIRUS_SCANNERS}"
	use f-prot && VIRUS_SCANNERS="f-prot ${VIRUS_SCANNERS}"

	if [ "$VIRUS_SCANNERS" == "" ]; then
		VIRUS_SCANNERS="none"
		VIRUS_SCANNING="no"
	else
		VIRUS_SCANNING="yes"
	fi

	sed -i \
		-e "s/^\(Virus Scanning[ \t]*=\).*/\1 ${VIRUS_SCANNING}/" \
		-e "s/^\(Virus Scanners[ \t]*=\).*/\1 ${VIRUS_SCANNERS}/" \
		"${S}/etc/MailScanner.conf"

	# setup spamassassin
	if use spamassassin ; then
		sed -i \
			-e "s/^\(Use SpamAssassin[ \t]*=\).*$/\1 yes/" \
			"${S}/etc/MailScanner.conf"
	else
		sed -i \
			-e "s/^\(Use SpamAssassin[ \t]*=\).*$/\1 no/" \
			"${S}/etc/MailScanner.conf"
	fi

	# update bin files
	sed -i \
		-e "s#msbindir=/opt/MailScanner/bin#msbindir=/usr/sbin#g" \
		-e "s#config=/opt/MailScanner/etc/MailScanner.conf#config=/etc/MailScanner/MailScanner.conf#g" \
		"${S}/bin/check_mailscanner"
	sed -i \
		-e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
		"${S}/bin/update_virus_scanners"
	sed -i \
		-e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
		-e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#g" \
		"${S}/bin/MailScanner"

	# update cron files
	sed -i \
		-e "s#/opt/MailScanner/bin/check_mailscanner#/usr/sbin/check_MailScanner#g" \
		"${S}/bin/cron/check_MailScanner.cron"
	sed -i \
		-e "s#/etc/sysconfig/MailScanner#/etc/conf.d/mailscanner#g" \
		-e "s#/opt/MailScanner/bin/update_virus_scanners#/usr/sbin/update_virus_scanners#g" \
		"${S}/bin/cron/update_virus_scanners.cron"

	# Determine some things that may need to be changed in conf file
	# (need to arrive at sensible replacement for yoursite)
	YOURSITE=`dnsdomainname | sed -e "s/\./-/g"`
	BASEBIN="${BASE}/sbin"

	# ClamAV requires some specific changes to MailScanner.conf
	# when mailscanner is running as root (i.e. sendmail)
	if use clamav ; then
		if [ "$MTA" == "sendmail" ] ; then
			WORKGRP="clamav"
			WORKPERM="0640"
		else
			WORKGRP=""
			WORKPERM="0600"
		fi
	else
		WORKGRP=""
		WORKPERM="0600"
	fi

	# update conf files
	sed -i \
		-e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
		-e "s#/opt/MailScanner/bin#$BASEBIN#g" \
		-e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#g" \
		-e "s#^\(Run As User[ \t]*=\).*#\1 $RUNASUSER#" \
		-e "s#^\(Run As Group[ \t]*=\).*#\1 $RUNASGROUP#" \
		-e "s#^\(Incoming Queue Dir[ \t]*=\).*#\1 $INQUEUE#" \
		-e "s#^\(Outgoing Queue Dir[ \t]*=\).*#\1 $OUTQUEUE#" \
		-e "s#^\(MTA[ \t]*=\).*#\1 $MTA#" \
		-e "s/^#\(TNEF.*internal\)$/\1/" \
		-e "s/^\(TNEF.*0000\)$/#\1/" \
		-e "s#^\(PID file[ \t]=\).*#\1 /var/run/mailscanner.pid#" \
		-e "s#^\(%org-name%\)[ \t]*=.*#\1 = ${YOURSITE}#" \
		-e "s#^\(Sendmail[ \t]*=\).*#\1 ${SENDMAIL}#" \
		-e "s#^\(Sendmail2[ \t]*=\).*#\1 ${SENDMAIL2}#" \
		-e "s#^\(Incoming Work Group[ \t]*=\).*#\1 ${WORKGRP}#" \
		-e "s#^\(Incoming Work Permissions[ \t]*=\).*#\1 ${WORKPERM}#" \
		"${S}/etc/MailScanner.conf"

	# net-mail/clamav net-mail/f-prot package compatibility
	sed -i \
		-e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#" \
		-e 's#^\(clamav\t.*/usr\)/local$#\1#' \
		-e 's#^\(f-prot.*\)/usr/local/f-prot$#\1/opt/f-prot#' \
		"${S}/etc/virus.scanners.conf"

	# update lib files
	sed -i \
		-e "s#/opt/MailScanner/bin#$BASEBIN#g" \
		-e "s#/opt/MailScanner/etc#/etc/MailScanner#g" \
		-e "s#/opt/MailScanner/lib#/usr/lib/MailScanner#g" \
		"${S}/lib/MailScanner/ConfigDefs.pl"
	sed -i \
		-e "s#/etc/MailScanner#/etc/MailScanner#g" \
		"${S}/lib/MailScanner/CustomConfig.pm"

	# finally, change MailScanner.conf into MailScanner.conf.sample
	cp "${S}/etc/MailScanner.conf" "${S}/etc/MailScanner.conf.${MY_PV}"
	mv "${S}/etc/MailScanner.conf" "${S}/etc/MailScanner.conf.sample"

}

src_install() {
	cd "${S}"
	exeinto ${BASE}/sbin
	#newexe	bin/check_mailscanner.linux check_MailScanner
	newexe	bin/check_mailscanner check_MailScanner
	doexe	bin/df2mbox
	doexe	bin/MailScanner
	doexe	bin/update_virus_scanners
	doexe	bin/upgrade_MailScanner_conf
	newexe	bin/Sophos.install.linux Sophos.install

	insinto	/etc/MailScanner
	doins	etc/*.conf
	doins	etc/mailscanner.conf.with.mcp
	doins	etc/MailScanner.conf.${MY_PV}
	doins	etc/MailScanner.conf.sample

	insinto	/etc/MailScanner/rules
	doins	etc/rules/*
	insinto	/etc/MailScanner/mcp
	doins	etc/mcp/*

	for i in $(ls etc/reports/)
	do
		if [ $i != "cat" ]
		then
			insinto /etc/MailScanner/reports/$i
			doins etc/reports/$i/*
		fi
	done

	insinto	${BASE}/lib/MailScanner
	doins	lib/*.prf

	exeinto ${BASE}/lib/MailScanner
	doexe	lib/*-wrapper
	doexe	lib/*-autoupdate
	doexe	lib/*-autoupdate.old
	doexe	lib/*.pm

	exeinto	${BASE}/lib/MailScanner/MailScanner
	doexe	lib/MailScanner/*.pm
	doexe	lib/MailScanner/*.pl

	insinto	${BASE}/lib/MailScanner/MailScanner
	doins	lib/MailScanner/*.txt

	exeinto	${BASE}/lib/MailScanner/MailScanner/CustomFunctions
	doexe	lib/MailScanner/CustomFunctions/MyExample.pm

	newinitd "${FILESDIR}"/initd.mailscanner MailScanner
	newinitd "${FILESDIR}"/initd.mailscanner-mta MailScanner-mta
	newconfd "${FILESDIR}"/confd.mailscanner MailScanner
	newconfd "${S}/confd.mailscanner-mta" MailScanner-mta

	#Set up cron jobs
	exeinto /etc/cron.hourly
	newexe "${S}/bin/cron/check_MailScanner.cron" check_MailScanner
	newexe "${S}/bin/cron/update_virus_scanners.cron" update_virus_scanners

	exeinto /etc/cron.daily
	newexe "${S}/bin/cron/clean.quarantine.cron" clean.quarantine

	if use doc ; then
		dodir /usr/share/doc/${PF}/html
		cp -r docs/* "${D}usr/share/doc/${PF}/html"
	fi

	dodoc notes.txt docs/QuickInstall.txt docs/README.sql-logging

	keepdir /var/spool/MailScanner/incoming
	keepdir /var/spool/MailScanner/quarantine
	keepdir /var/spool/MailScanner/spamassassin
	keepdir /var/spool/MailScanner/archive
	keepdir ${BASE}/var

	if use postfix ; then
		chown -R postfix:postfix "${D}/var/spool/MailScanner/"
	elif use exim ; then
		chown -R mail:mail "${D}/var/spool/MailScanner/"
	else
		keepdir /var/spool/mqueue.in
	fi
}

pkg_postinst() {
	if [ -n "`grep -xE "[[:space:]]*provide[[:space:]]+(.*[[:space:]]+)*mta([[:space:]]+.*)*" /etc/init.d/${MTA}`" ]; then
		ewarn
		ewarn "Warning: your mta service startup script /etc/init.d/${MTA}"
		ewarn "seems to provide 'mta', this may give problems with /etc/init.d/MailScanner-mta."
		ewarn
		ewarn "The Installation is *NOT* Completed Yet, You still need Filesystem::Df"
		ewarn "Please use emerge g-cpan and run the following command"
		ewarn
		ewarn " # g-cpan -i Filesys::Df "
		ewarn

		echo
	fi
	elog "Remove the line containing 'provide mta' from your MTA's init script"
	elog "and take care that using etc-update will not insert this line after"
	elog "re-emerging / updating your mta!"
	elog "The related bug in bugs.gentoo.org is #46897"
	echo

	if [ -f "/etc/MailScanner/MailScanner.conf" ]; then
		einfo "Upgrading the MailScanner.conf file"
		cp /etc/MailScanner/MailScanner.conf /etc/MailScanner/MailScanner.conf.pre_upgrade.${MY_PV}
		/usr/sbin/upgrade_MailScanner_conf \
		/etc/MailScanner/MailScanner.conf.pre_upgrade.${MY_PV} \
		/etc/MailScanner/MailScanner.conf.${MY_PV} \
		> /etc/MailScanner/MailScanner.conf 2> /dev/null
	else
		cp /etc/MailScanner/MailScanner.conf.sample /etc/MailScanner/MailScanner.conf
	fi
}