summaryrefslogtreecommitdiff
blob: 841a9e301676c959d686d3cc707fbff1e02ce4aa (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
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils linux-info toolchain-funcs

MY_P=MoBlock-${PV}

DESCRIPTION="Blocks connections from/to hosts listed in a file in peerguardian format using iptables"
HOMEPAGE="http://moblock.berlios.de/"
SRC_URI="mirror://berlios/${PN}/${MY_P}-i586.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="logrotate network-cron paranoid"

DEPEND="net-libs/libnetfilter_queue
	net-libs/libnfnetlink"
RDEPEND="${DEPEND}
	net-firewall/iptables"

S=${WORKDIR}/${MY_P}

CONFIG_CHECK="NETFILTER NETFILTER_XTABLES NETFILTER_XT_TARGET_NFQUEUE
	IP_NF_IPTABLES IP_NF_FILTER NETFILTER_XT_MATCH_STATE"

src_unpack() {
	unpack ${A}
	epatch "${FILESDIR}"/${P}-{makefile,rename-stats-file,fix-nfq_unbind_pf-error,fix-broken-compile}.patch
}

src_compile() {
	emake CC=$(tc-getCC) || die "emake failed"
}

src_install() {
	dosbin moblock || die

	dosbin "${FILESDIR}/${PVR}/moblock-{update,stats}" || die

	newinitd "${FILESDIR}/${PVR}/init.d" moblock || die
	doconfd "${FILESDIR}/${PVR}/moblock.{paranoid,normal,minimal}.example" || die
	if use paranoid; then
		newconfd "${FILESDIR}/${PVR}/moblock.paranoid.example" moblock || die
	else
		newconfd "${FILESDIR}/${PVR}/moblock.normal.example" moblock || die
	fi

	dodir /var/{db,cache}/moblock || die
	touch "${D}/var/db/moblock/guarding.p2p" || die

	if use network-cron; then
		if use paranoid; then
			dosym /usr/sbin/moblock-update /etc/cron.daily/moblock-update || die
		else
			dosym /usr/sbin/moblock-update /etc/cron.weekly/moblock-update || die
		fi
	fi

	if use logrotate; then
		insinto /etc/logrotate.d || die
		newins "${FILESDIR}/${PVR}/logrotate" moblock || die
	fi

	dodoc Changelog README || die
}

pkg_postinst() {
	if use network-cron; then
		local cron_interval="$(use paranoid && echo daily || echo weekly)";
		elog "The script /usr/sbin/moblock-update will be run ${cron_interval} to update your"
		elog "blocklists.  You can change this by moving or removing the symlink"
		elog "/etc/cron.${cron_interval}/moblock-update or re-installing MoBlock without the"
		elog "network-cron USE flag."
	else
		elog "Run moblock-update to update your block list.  To have this happen"
		elog "automatically, re-install enabling the network-cron USE flag."
	fi
	elog ""
	elog "You can view or change your blocklist(s) and other options by editing"
	elog "/etc/conf.d/moblock."
}

pkg_postrm() {
	if ! [[ -e ${ROOT}/usr/sbin/moblock ]] && [[ -d ${ROOT}/var/cache/moblock ]] ; then
		elog "Removing leftover cache..."
		rm -rf "${ROOT}/var/cache/moblock" ||
			ewarn "Failed to remove ${ROOT}/var/cache/moblock"
	fi
}