# Contributor: Michał Polański <michal@polanski.me>
# Contributor: jahway603 <jahway603@protonmail.com>
# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=dendrite
pkgver=0.14.1
pkgrel=5
pkgdesc="Second-generation Matrix homeserver written in Go"
url="https://github.com/element-hq/dendrite"
license="Apache-2.0"
arch="all"
makedepends="
	go
	olm-dev
	sqlite-dev
	"
subpackages="$pkgname-openrc"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/element-hq/dendrite/archive/refs/tags/v$pkgver.tar.gz
	dendrite.initd
	dendrite.confd
	"
options="net !check" # required to download go modules, fail in not-shipped demo bin

# secfixes:
#   0.14.1-r0:
#     - CVE-2024-52594

case "$CARCH" in
# Builder runs out of space in /tmp when running these tests.
loongarch64)	options="$options !check" ;;
esac

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	for cmd in dendrite generate-keys create-account; do
		go build -trimpath -v -o bin/$cmd ./cmd/$cmd
	done
}

check() {
	DENDRITE_TEST_SKIP_NODB=1 go test ./...
}

package() {
	install -Dm755 bin/dendrite "$pkgdir"/usr/bin/dendrite
	install -Dm755 bin/generate-keys "$pkgdir"/usr/bin/dendrite-generate-keys
	install -Dm755 bin/create-account "$pkgdir"/usr/bin/dendrite-create-account

	install -Dm644 dendrite-sample.yaml "$pkgdir"/etc/$pkgname/dendrite.yaml
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
4053b42038210ae630df2ba931a2f7290d5db525fd759d12232bd753cd7e650af0ed3a0450f48968533dcf11e7fbcdde037d3a444694e33cc51ca90f07a68b6b  dendrite-0.14.1.tar.gz
5d228aa3970a176e10e24dc5cd8611103c944de660a65cc1e6221ae65a804b1bfbe0a6465716ccda37c4d82670d0ff27f017c44c382ab9eb25b7bc6e037d01b0  dendrite.initd
a6a088683a6aebc431d3eb289bd0d4dbaede698d1a5da25d6af2aad79e9cd36db02ce9173ab6904249f23b88bca5d1630258736feef7e8266e6c22220d74fa1f  dendrite.confd
"
