# Contributor: Justin Berthault <justin.berthault@zaclys.net>
# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=blocky
# Also update documentation links in blocky.example.yml
pkgver=0.24
pkgrel=2
pkgdesc="DNS proxy as ad-blocker for local network"
pkggroups="blocky"
pkgusers="blocky"
url="https://github.com/0xERR0R/blocky"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install $pkgname.pre-upgrade $pkgname.post-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/0xERR0R/blocky/archive/v$pkgver.tar.gz
	busybox-date.patch
	blocky.initd
	blocky.confd
	blocky.example.yml
	"
# fail with new go for some reason, even with tzdata/goroot
options="!check net"

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

build() {
	make VERSION=$pkgver build
}

check() {
	make test
}

package() {
	install -Dvm755 bin/blocky -t "$pkgdir"/usr/bin/
	install -Dvm755 "$srcdir"/blocky.initd "$pkgdir"/etc/init.d/blocky
	install -Dvm644 "$srcdir"/blocky.confd "$pkgdir"/etc/conf.d/blocky
	install -Dvm644 "$srcdir"/blocky.example.yml "$pkgdir"/etc/blocky/config.example.yml

	# blocky will not start if its log directory is missing
	install -dvm750 -o blocky -g blocky "$pkgdir"/var/log/blocky
}

sha512sums="
d89e417157a2f45232f264eed597849bf38e4ad7407d215e5ebe9b2bd84e2b31f1c434b9df915c295272214a3398fb73302814503bca5ca41b748363ecc656e6  blocky-0.24.tar.gz
2f1e60037229ad2730f3d51a16e79f0ef93baf80fa73948d08d1216de5db454f10ea4081558f1c86db2e394948cfce62af20b802278dd89241b591e77bce8b4c  busybox-date.patch
d5507cedb0dab49c139ab4366d3b6428b23c8aa891a7f7d6caad567cfca53f8434f055d4c15d03899712b164a5f2a9e00e9df75ab0e428d205a4bd5bdc50b973  blocky.initd
3ddd8cd400f9c0f9999430e7fe2507ef5f9ac43bc2e9acbc1bf1b558d383bc891e36a6bf75e2031cd28da69e9dc875f0ac5ad3dac0cf35ce2076651d000e7981  blocky.confd
a9a5ba48e10cc17c579ceccbf4e77bbe815e8879d094af2b5ed7191aafdd65efd583d31900748380b5e7c19d869ace82c76347a4e9a1e9aa2bed868b0e9c50dd  blocky.example.yml
"
