# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=vouch-proxy
pkgver=0.40.0
pkgrel=4
pkgdesc="An SSO solution for Nginx using the auth_request module"
url="https://github.com/vouch/vouch-proxy"
arch="all"
license="MIT"
makedepends="go"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
pkgusers="vouch"
pkggroups="vouch"
options="!check chmod-clean net" # no test suite
source="$pkgname-$pkgver.tar.gz::https://github.com/vouch/vouch-proxy/archive/refs/tags/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.logrotate
	"

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

build() {
	go build -ldflags="-X main.semver=v$pkgver"
}

package() {
	install -d -o vouch -g vouch "$pkgdir"/etc/vouch-proxy
	cp "$builddir"/config/config.* "$pkgdir"/etc/vouch-proxy

	install -Dm755 vouch-proxy "$pkgdir"/usr/sbin/vouch-proxy
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname

	install -d "$pkgdir"/usr/share/webapps/$pkgname/data
	cp -r static "$pkgdir"/usr/share/webapps/$pkgname
	cp -r templates "$pkgdir"/usr/share/webapps/$pkgname
	install -Dm644 .defaults.yml "$pkgdir"/usr/share/webapps/$pkgname/.defaults.yml

	ln -s /etc/vouch-proxy "$pkgdir"/usr/share/webapps/vouch-proxy/config

	install -Dm644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/vouch-proxy
}

doc() {
	install -d "$subpkgdir"/usr/share/doc/$pkgname
	cp -r "$builddir"/examples "$subpkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
4831100ce37128c9b50f629ecce07d0229b85b21e661428e3fde4e48e2f48f51281e19e04e985fedd3c188fe7281460eae7ed1501cdd7de5b83c50dc5d571f94  vouch-proxy-0.40.0.tar.gz
943460815cba76f1686c8646a735105c8f5a538ed51521a3c662b4c0b181e6035e9965951e508b75e28ca4c6ada5c4a4f523c18299be338ff105cd9c0fccd5ee  vouch-proxy.initd
8c0af0effb316d62c2153ff1ac49f85a84248478f4f42f20981f6343ce09c12be64afee592d4d17695eb5551c7c5dc1f040443754bd3448757899c046c222985  vouch-proxy.logrotate
"
