# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=mautrix-slack
pkgver=0.1.0
pkgrel=0
pkgdesc="Matrix-Slack puppeting bridge"
url="https://go.mau.fi/mautrix-slack/"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install $pkgname.post-upgrade"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/slack/archive/v$pkgver.tar.gz
	mautrix-slack.initd
	mautrix-slack.confd
	"
builddir="$srcdir/slack-$pkgver"
options="net"

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

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"

	go build \
		-ldflags "-X main.Tag=$pkgver -X 'main.BuildTime=$(date -d @"$SOURCE_DATE_EPOCH" '+%b %_d %Y, %H:%M:%S')'" \
		./cmd/mautrix-slack

	./mautrix-slack -e
	sed -i 's|./logs/bridge.log|/var/log/mautrix-slack/mautrix-slack.log|g' config.yaml
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-slack \
		-t "$pkgdir"/usr/bin/
	install -Dm644 config.yaml \
		-t "$pkgdir"/etc/mautrix-slack/

	install -Dm755 "$srcdir"/mautrix-slack.initd \
		"$pkgdir"/etc/init.d/mautrix-slack
	install -Dm644 "$srcdir"/mautrix-slack.confd \
		"$pkgdir"/etc/conf.d/mautrix-slack

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

sha512sums="
b117f7c8a222c5d0688f31d3dc40848212053392a6c401dcb952d58c7b96a4f85dd3a1a6275b3c3480e8b53017a4be715fa5818763b8ae38ab6487c9ae22043d  mautrix-slack-0.1.0.tar.gz
d27fbc6c7ebe9d42eb8226e035649239e6a3e9fbdea21fd9930666da68be375df577fdf9fd6989152e3bee76c924cf77119c57056aff6def84408c4548e8c42a  mautrix-slack.initd
cda8cd828fa1e4e4c302adc79a51d9af99fb428a81639691afefad6b575f6d2ac75730ea2cc455be514fe65a9836bdeb530a86b553c34a47e4a56796ce843fe1  mautrix-slack.confd
"
