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

EAPI=8
inherit go-module systemd shell-completion

DESCRIPTION="One-stop ZFS backup & replication solution"
HOMEPAGE="https://zrepl.github.io/"
BDEPEND=">=dev-lang/go-1.12"
SRC_URI="https://github.com/zrepl/zrepl/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"
SRC_URI+=" https://share.terinstock.com/${P}-deps.tar.xz"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"

src_compile() {
	ego build -trimpath .

	./zrepl gencompletion bash "${PN}.bash" || die
	./zrepl gencompletion zsh "${PN}.zsh" || die
}

src_install() {
	dobin zrepl
	einstalldocs

	newbashcomp "${PN}.bash" "${PN}"
	newzshcomp "${PN}.zsh" "_${PN}"

	sed -i -e 's:/usr/local/bin/zrepl:/usr/bin/zrepl:' dist/systemd/zrepl.service || die
	systemd_dounit dist/systemd/zrepl.service
}