# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
LUA_COMPAT=( lua5-{1..4} )
inherit lua git-r3
DESCRIPTION="zapret"
EGIT_REPO_URI="https://github.com/bol-van/zapret2.git"
HOMEPAGE="https://github.com/bol-van/zapret2"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="systemd nftables"
REQUIRED_USE="${LUA_REQUIRED_USE}"
DEPEND="
${LUA_DEPS}
net-libs/libnetfilter_queue
net-firewall/ipset
net-firewall/iptables
dev-lang/luajit
nftables? ( net-firewall/nftables )
net-dns/ldns-tools
!!net-dns/bind
net-analyzer/openbsd-netcat
net-misc/curl
net-firewall/nftables
"
# bind contains mdig, which zapret also builds
# other than that, bind could have been alternative to ldns-tools
RDEPEND="${DEPEND}"
src_compile() {
if use systemd; then
make systemd
else
make
fi
}
src_install() {
rm -rf ${S}/nfq2/windows
rm -rf ${S}/*install*
dodir opt/ || die
dodir opt/"${PN}" || die
cp -r "${S}"/* "${ED}"/opt/"${PN}"/ || die
dosym ${EPREFIX}${INSTALL_PREFIX}/opt/"${PN}"/binaries/my/ip2net /usr/bin/ip2net || die
dosym ${EPREFIX}${INSTALL_PREFIX}/opt/"${PN}"/binaries/my/mdig /usr/bin/mdig || die
dosym ${EPREFIX}${INSTALL_PREFIX}/opt/"${PN}"/binaries/my/nfqws2 /usr/bin/nfqws2 || die
if use systemd; then
dosym -r ${EPREFIX}${INSTALL_PREFIX}/opt/"${PN}"/init.d/systemd/* /lib/systemd/system/
else
dosym ${EPREFIX}${INSTALL_PREFIX}/opt/"${PN}"/init.d/openrc/zapret2 /etc/init.d/zapret2
fi
}
pkg_pretend() {
if use systemd; then
ewarn Note, systemd use flag was not tested
fi
}