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

# Auto-Generated by cargo-ebuild 0.5.4-r1

EAPI=8

EGIT_REPO_URI="https://gitlab.com/famedly/${PN}.git"
inherit cargo git-r3 systemd

DESCRIPTION="A Matrix homeserver written in Rust"
# Double check the homepage as the cargo_metadata crate
# does not provide this value so instead repository is used
HOMEPAGE="https://gitlab.com/famedly/conduit https://conduit.rs"

# License set may be more restrictive as OR is not respected
# use cargo-license for a more accurate license picture
LICENSE="0BSD Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD BSD-1 BSD-2 Boost-1.0 CC0-1.0 ISC MIT MIT-0 MPL-2.0 Unicode-DFS-2016 Unlicense ZLIB"
SLOT="0"

RDEPEND="${DEPEND}
	acct-user/conduit"
BDEPEND="sys-devel/clang"

# rust does not use *FLAGS from make.conf, silence portage warning
# update with proper path to binaries this crate installs, omit leading /
QA_FLAGS_IGNORED="usr/bin/${PN}"

src_unpack() {
	git-r3_fetch
	git-r3_checkout
	cargo_live_src_unpack
}

src_install() {
	newbin target/release/conduit matrix-conduit
	systemd_dounit "${FILESDIR}/${PN}.service"

	insinto /etc/matrix-conduit
	newins "${FILESDIR}/conduit-example.toml" conduit.toml
	fowners conduit:conduit /etc/matrix-conduit
	fperms 0750 /etc/matrix-conduit

	keepdir /var/lib/matrix-conduit
	fowners conduit:conduit /var/lib/matrix-conduit
	fperms 0700 /var/lib/matrix-conduit
}

pkg_postinst() {
	elog "Check the configuration file at /etc/matrix-conduit/conduit.toml"
	elog "and adapt it to your needs. Consult the documentation at"
	elog "https://famedly.gitlab.io/conduit/deploying/generic.html"
	elog "for information and configuration options. Also, do not forget"
	elog "to set up a reverse proxy (Apache, Nginx or the like)."
	elog "Additionally, you may want to install net-im/coturn for"
	elog "TURN/STUN support."
	elog
	elog "Have fun!"
}