# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit git-r3 systemd

DESCRIPTION="Fetch various blocklists and generate a BIND zone from them."
HOMEPAGE="https://github.com/Trellmor/bind-adblock"

LICENSE="MIT"
SLOT="0"

EGIT_REPO_URI="https://github.com/Trellmor/bind-adblock.git"

IUSE="network-cron systemd"

RDEPEND="
	dev-python/pycryptodome
	dev-python/dnspython
	dev-python/requests
	dev-python/pyyaml
	dev-python/validators
"

src_install() {
	# Update script to load config file from /etc/bind-adblock for config protection
	sed -i -e "s@main_conf_file =.*@main_conf_file = '/etc/bind-adblock/config.yml'@" \
		update-zonefile.py
	# Update config.yml to include blocklist.txt from /etc/bind-adblock for
	# config protection
	sed -i -e 's@blocklist\.txt@/etc/bind-adblock/blocklist.txt@' \
		config.yml

	exeinto /opt/bind-adblock
	doexe update-zonefile.py
	doexe "${FILESDIR}/bind-adblock.sh"

	insinto /opt/bind-adblock
	doins README.md

	insinto /etc/bind-adblock
	doins blocklist.txt config.yml

	dosym ../bind-adblock/update-zonefile.py /opt/bin/update-zonefile.py
	dosym ../bind-adblock/bind-adblock.sh /opt/bin/bind-adblock.sh

	if use network-cron; then
		dosym ../../opt/bin/bind-adblock.sh /etc/cron.daily/bind-adblock.sh
	fi

	if use systemd; then
		systemd_dounit "${FILESDIR}"/bind-adblock.{service,timer}
	fi
}