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

# Autogenerated by pycargoebuild 0.13.4

EAPI=8

CRATES="
"

inherit cargo linux-info systemd

MY_PV=${PV/_alpha/-alpha.}

DESCRIPTION="shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
HOMEPAGE="https://github.com/shadowsocks/shadowsocks-rust"
SRC_URI="
	https://github.com/shadowsocks/shadowsocks-rust/archive/v${MY_PV}.tar.gz -> ${P}.tar.gz
	${CARGO_CRATE_URIS}
"
if [[ ${PKGBUMPING} != ${PVR} ]]; then
	SRC_URI+="
		https://github.com/peeweep/gentoo-go-deps/releases/download/${P}/${P}-crates.tar.xz
	"
fi

S="${WORKDIR}/${PN}-${MY_PV}"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+="
	0BSD Apache-2.0 BSD-2 BSD CC0-1.0 ISC MIT MPL-2.0 Unicode-3.0
	WTFPL-2
"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
IUSE="redir tun"

QA_FLAGS_IGNORED="
	usr/bin/sslocal
	usr/bin/ssmanager
	usr/bin/ssurl
	usr/bin/ssservice
	usr/bin/ssserver
"

pkg_setup() {
	if use tun; then
		CONFIG_CHECK="~TUN"
		linux-info_pkg_setup
	fi
	rust_pkg_setup
}

src_configure() {
	local myfeatures=(
		$(usex redir local-redir "")
		$(usex tun local-tun "")
	)
	cargo_src_configure
}

src_install() {
	cargo_src_install

	newconfd "${FILESDIR}/shadowsocks-rust.confd" shadowsocks-rust
	dosym shadowsocks-rust /etc/conf.d/shadowsocks-rust.server
	dosym shadowsocks-rust /etc/conf.d/shadowsocks-rust.local
	newinitd "${FILESDIR}/shadowsocks-rust.initd" shadowsocks-rust
	dosym shadowsocks-rust /etc/init.d/shadowsocks-rust.server
	dosym shadowsocks-rust /etc/init.d/shadowsocks-rust.local

	systemd_newunit "${FILESDIR}/shadowsocks-rust_at.service" shadowsocks-rust@.service
	systemd_newunit "${FILESDIR}/shadowsocks-rust-server_at.service" shadowsocks-rust-server@.service

	insinto "/etc/${PN}"
	doins examples/*.json
}

pkg_postinst() {
	if has_version "<sys-apps/openrc-0.56[-caps]"; then
			einfo ""
			einfo "For OpenRC users using old version(<0.56):"
			einfo "Capabilities support for old version is needed."
			einfo "Enable it by set useflag [caps] for <sys-apps/openrc-0.56."
			einfo ""
	fi
}