summaryrefslogtreecommitdiff
blob: 211b2614945646dcf0adf9d9c0b91df0a2d18b82 (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
324
325
326
327
328
329
330
331
332
333
334
335
336
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
##
## Created by Wolfram Schlich <wschlich@gentoo.org>
##
## TODO
## - install: shutdown running programs?
## - install: show EULA?!
## - config: setup avmailgate.acl?
## - install/config: copy keyfile?
## - config: setup mta config? -> show INSTALL.$mta file, at least
## - install/config: avguard? -> check if avspooldir is excluded in guard config
## - install/config: gui?
##

inherit eutils pax-utils multilib

DESCRIPTION="AVIRA AntiVir MailGate SMTP mail virus scanner"
MY_P="${PN}-prof-${PV/_p/-}"
SRC_URI="http://dl.antivir.de/down/unix/packages/${MY_P}.tar.gz"
HOMEPAGE="http://www.antivir.de/"
LICENSE="AVIRA-AntiVir"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="postfix spamfilter" # TODO: gui exim qmail sendmail smc
DEPEND=""
RDEPEND=">=app-antivirus/antivir-core-2.1.12_p19
	postfix? ( mail-mta/postfix )"
S="${WORKDIR}/${MY_P}"
# prevent installation functions from stripping binaries
# otherwise the antivir selfcheck fails. also don't try
# to fetch the distribution tarball from a mirror.
RESTRICT="strip mirror"

#
# Settings overridable by user supplied environment variables
#

AVHOMEDIR="${AVHOMEDIR:-/usr/lib/AntiVir}"
AVCONFDIR="${AVCONFDIR:-/etc}"
AVSPOOLDIR="${AVSPOOLDIR:-/var/spool/avmailgate}"
AVTMPDIR="${AVTMPDIR:-/var/tmp}"
AVPIDDIR="${AVPIDDIR:-/var/tmp}"
AVUSER="${AVUSER:-avgate}"
AVUID="${AVUID:-220}"
AVSH="${AVSH:--1}"
AVGROUP="${AVGROUP:-antivir}"
AVGID="${AVGID:-220}"
AVHOSTNAME="${AVHOSTNAME:-$(hostname -f)}"

#
# Standard ebuild functions
#

pkg_setup() {

	#
	# Add USER + GROUP
	#

	enewgroup "${AVGROUP}" "${AVGID}"
	enewuser "${AVUSER}" "${AVUID}" "${AVSH}" -1 "${AVGROUP}" -c AntiVir

}

src_unpack() {

	unpack ${A}
	cd "${S}"

	#
	# MTA specific config	
	#

	if use postfix; then
		pushd ./etc >/dev/null \
			&& epatch "${FILESDIR}/${PV}/avmailgate.conf.diff.postfix.bz2" \
			&& popd >/dev/null
	fi

}

src_install() {

	#
	# Base directories
	#

	if use spamfilter; then
		diropts -oroot -g"${AVGROUP}" -m0750
		dodir /var/lib/AntiVir
		dodir /var/tmp/AntiVir
		diropts -o"${AVUSER}" -g"${AVGROUP}" -m0750
		dodir /var/tmp/AntiVir/asmailgate
		dodir /var/lib/AntiVir/asmailgate
		diropts ""
		dosym /var/lib/AntiVir/asmailgate "${AVHOMEDIR}/mailgate-var"
	fi

	#
	# Executables, libraries and misc components
	#

	exeopts -oroot -g"${AVGROUP}" -m2750
	exeinto "${AVHOMEDIR}"
	doexe bin/linux_glibc22/avmailgate.bin
	diropts ""
	dodir \
		"${DESTTREE}/sbin"
	dosym "${AVHOMEDIR}/avmailgate.bin" "${DESTTREE}/sbin/avmailgate"

	if use spamfilter; then
		exeopts -o"${AVUSER}" -g"${AVGROUP}" -m2750
		exeinto "${AVHOMEDIR}"
		doexe contrib/asmailgate/bin/linux_glibc22/avmg_ext_filter.bin
		pax-mark -m "${D}${AVHOMEDIR}"/avmg_ext_filter.bin
		insopts -o"${AVUSER}" -g"${AVGROUP}" -m0644
		insinto "${AVHOMEDIR}"
		doins contrib/asmailgate/bin/linux_glibc22/libasmailgate.so
		doins contrib/asmailgate/data/asmailgate.dat
		insinto /var/lib/AntiVir/asmailgate
		doins contrib/asmailgate/var/as_sdk_features.yml
		doins contrib/asmailgate/var/asconfig.yml
		doins contrib/asmailgate/var/asmailgate.yml
	fi

	#
	# Init script
	#

	exeopts -oroot -groot -m0755
	exeinto /etc/init.d
	newexe "${FILESDIR}/${PV}/antivir-mailgate.init.d" antivir-mailgate

	#
	# Config
	#

	insopts -oroot -g"${AVGROUP}" -m0640
	insinto "${AVCONFDIR}"
	doins \
		etc/avmailgate.acl \
		etc/avmailgate.conf \
		etc/avmailgate.ignore \
		etc/avmailgate.scan \
		etc/avmailgate.warn
#	use gui && doins etc/avmailgate.conf-gui
	dosed "s:%AVHOMEDIR%:${AVHOMEDIR}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVCONFDIR%:${AVCONFDIR}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVSPOOLDIR%:${AVSPOOLDIR}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVTMPDIR%:${AVTMPDIR}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVPIDDIR%:${AVPIDDIR}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVUSER%:${AVUSER}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVGROUP%:${AVGROUP}:g" "${AVCONFDIR}/avmailgate.conf"
	dosed "s:%AVHOSTNAME%:${AVHOSTNAME}:g" "${AVCONFDIR}/avmailgate.conf"
	if use spamfilter; then
		dosed "s:^EnableSpamCheck NO:EnableSpamCheck YES:g" "${AVCONFDIR}/avmailgate.conf"
		touch "${T}/asmailgate.except"
		doins "${T}/asmailgate.except"
	fi

	#
	# Spool directory
	#

	diropts -o"${AVUSER}" -g"${AVGROUP}" -m0700
	dodir "${AVSPOOLDIR}"
	keepdir "${AVSPOOLDIR}"
	for dir in incoming outgoing rejected; do
		dodir "${AVSPOOLDIR}/${dir}"
		keepdir "${AVSPOOLDIR}/${dir}"
	done

	## TODO:GUI

	## TODO:SMC

	#
	# Documents
	#

	dodoc \
		LICENSE \
		LICENSE.DE \
		README \
		doc/CHANGELOG \
		doc/INSTALL \
		doc/INSTALL.DE \
		doc/MANUAL \
		doc/RELEASE_NOTES \
		doc/avmailgate_de.pdf \
		doc/avmailgate_en.pdf \
		legal/LICENSE.*
	use postfix && dodoc \
		doc/INSTALL.postfix
#	use exim && dodoc \
#		doc/INSTALL.exim
#	use sendmail && dodoc \
#		doc/INSTALL.sendmail
#	use qmail && dodoc \
#		doc/INSTALL.qmail
#	use qmail && use gui && dodoc \
#		doc/INSTALL.qmail.gui
	doman \
		doc/man/avmailgate.8 \
		doc/man/avmailgate.conf.5

	#
	# Templates
	#

	diropts ""
	dodir "${AVHOMEDIR}/templates.sample"
	insopts ""
	insinto "${AVHOMEDIR}/templates.sample"
	doins \
		templates/en/patho-administrator \
		templates/en/patho-recipient \
		templates/en/patho-sender \
		templates/en/alert-administrator \
		templates/en/alert-recipient \
		templates/en/alert-sender
	if use spamfilter; then
		doins \
			templates/spamfilter-subjects
	fi

}

pkg_preinst() {

	#
	# Check for legacy files
	#

	# Templates: virus-* -> alert-*
	for t in administrator recipient sender; do
		tf="${AVHOMEDIR}/templates/virus-${t}"
		new_tf="${AVHOMEDIR}/templates/alert-${t}"
		if [ -e "${tf}" ]; then
			ewarn
			ewarn "You have an old notification mail template file in ${AVHOMEDIR}/templates/:"
			ewarn " -> ${tf}"
			ewarn "Please rename it as follows:"
			ewarn " -> ${new_tf}"
			ewarn
		fi
	done

}

pkg_postinst() {

	#
	# Config
	#

	echo
	einfo ""
	einfo "Configuration"
	einfo "============="
	einfo ""
	einfo "Please run..."
	einfo ""
	einfo "\tebuild /var/db/pkg/${CATEGORY}/${PF}/${PF}.ebuild config"
	einfo ""
	einfo "...to configure the package!"
	einfo ""
	echo

}

pkg_config() {

	#
	# Init script
	#

	echo
	einfo ""
	einfo "Using the init script"
	einfo "====================="
	einfo ""
	einfo "Simply run..."
	einfo ""
	einfo "\trc-update add antivir-mailgate default"
	einfo ""
	einfo "...and your're done."
	einfo ""

	#
	# Templates
	#

	echo
	einfo ""
	einfo "Using the notification mail templates"
	einfo "====================================="
	einfo ""
	einfo "The sample templates were installed into"
	einfo ""
	einfo "\t${AVHOMEDIR}/templates.sample"
	einfo ""
	einfo "To use them, simply do..."
	einfo ""
	einfo "\tcd ${AVHOMEDIR}"
	einfo "\tmv templates.sample templates"
	einfo ""
	einfo "...and edit the files in the 'templates'-subdirectory."
	einfo ""

	#
	# MTA config
	# TODO: qmail exim sendmail
	#

	if use postfix; then
		echo
		einfo ""
		einfo "MTA configuration (Postfix)"
		einfo "==========================="
		einfo ""
		einfo "See INSTALL.postfix. Quickstart:"
		einfo ""
		einfo "1) Add the following line to /etc/postfix/main.cf:"
		einfo ""
		einfo "\tcontent_filter = smtp:127.0.0.1:10024"
		einfo ""
		einfo "2) Add the following line to /etc/postfix/master.cf:"
		einfo ""
		einfo "\tlocalhost:10025 inet n - y - - smtpd -o content_filter="
		einfo ""
	fi

}