# Contributor: Mark Pashmfouroush <mark@markpash.me>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Mark Pashmfouroush <mark@markpash.me>
pkgname=coredns
pkgver=1.11.3
pkgrel=5
pkgdesc="fast and flexible DNS server"
url="https://github.com/coredns/coredns"
license="Apache-2.0"
arch="all"
makedepends="go unbound-dev"
options="chmod-clean net"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="https://github.com/coredns/coredns/archive/v$pkgver/coredns-$pkgver.tar.gz
	coredns.confd
	coredns.initd
	coredns.logrotated
	plugin.cfg.enabled
	"
# secfixes:
#   1.9.3-r0:
#     - CVE-2022-27191
#     - CVE-2022-28948

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

prepare() {
	default_prepare
	cp "$srcdir"/plugin.cfg.enabled "$builddir"/plugin.cfg
}

build() {
	CGO_ENABLED=1 make
}

check() {
	cd "$builddir"/request; go test ./...
	cd "$builddir"/core; go test ./...
	cd "$builddir"/coremain; go test ./...
	cd "$builddir"/plugin; go test ./...
}

package() {
	install -Dm755 coredns "$pkgdir"/usr/bin/coredns

	install -Dm755 "$srcdir"/coredns.initd "$pkgdir"/etc/init.d/coredns
	install -Dm644 "$srcdir"/coredns.confd "$pkgdir"/etc/conf.d/coredns
	install -Dm 644 "$srcdir"/coredns.logrotated "$pkgdir"/etc/logrotate.d/coredns

	install -d "$pkgdir"/etc/coredns
	install -d "$pkgdir"/var/log/coredns
}

sha512sums="
3ec9296626a2994d1259329e50b032d2972ef8e05bfed742c0ee570414adbfa8f296046b9356ef73d885a1f1c1e3660421762267535ec2d3f357c3064a75d405  coredns-1.11.3.tar.gz
90300a3035b00b58f362b2c12dfaeee21b889e10e90600523b5785c907dfbd7e515c3269dd29a9d4c758990e78ede8343edfac0bc022bd3a23652543ba2d42d3  coredns.confd
802ac66ea27ac71001706b0994a579e0ab3f608a89d0a03f92490f4b73c4bd202745fd13b34d957122c8f1439be2709604c7931ff2a7be003c573e746c9d98b9  coredns.initd
c697c08c3b1153ae224a1eeb3521f9ee594de4852bc6ef78d94dc7f6f680517659a653ab5c13ea03918deb79e6654ef11512ba4c90fe06ea4591fefbab876ece  coredns.logrotated
4cce898cfe2bd9891e4ac638c30bc04cffe560044240dd608fa64ffdf6320d488da0d0505920889db41e25f592b74b759fb01830528c46bea6adb37919eca629  plugin.cfg.enabled
"
