# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit git-r3

DESCRIPTION="Transparent UDP obfuscating proxy mainly for openvpn"
HOMEPAGE="https://github.com/kevinxucs/udpmask"
EGIT_REPO_URI="https://github.com/kevinxucs/${PN}"

if [[ ${PV} == *9999 ]]
then
	EGIT_BRANCH="master"
elif [[ ${PV} == 0.3.0 ]];
then
	# Use 3 commits ahead of 0.3.0 due to important patch
	EGIT_COMMIT="97194f0ff36a7abc7c8e5167d31d96c025dd78a0"
else
	die "No version commit for this version found"
fi

SLOT="0"
KEYWORDS="~amd64"
IUSE="server +client"
REQUIRED_USE="
	?? ( server client )
"

DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND=""

src_install() {
	emake DESTDIR="${D}" PREFIX="/usr" install

	dodoc "README.md"

	newinitd "${FILESDIR}/udpmask.init" udpmask
	if use client
	then
		echo "udpmask_args='-m client -c server.example.org -p 1194 -l 127.0.0.1'" | newconfd - udpmask
	elif use server
	then
		echo "udpmask_args='-m server -c localhost -o 1194'" | newconfd - udpmask
	fi
}