# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=etcd
pkgver=3.5.18
pkgrel=3
pkgdesc="A highly-available key value store for shared configuration and service discovery"
url="https://github.com/etcd-io/etcd"
license="Apache-2.0"
arch="all"
makedepends="go bash"
install="$pkgname.pre-install"
provides="etcd-api"
provider_priority=2
options="net chmod-clean"
pkgusers="etcd"
pkggroups="etcd"
subpackages="$pkgname-doc $pkgname-ctl $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/etcd-io/etcd/archive/v$pkgver.tar.gz
	git-sha.patch
	fix_unsupported_arch.patch
	$pkgname.yaml
	$pkgname.confd
	$pkgname.initd
	"

build() {
	export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
	export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
	export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
	export GOFLAGS="$GOFLAGS -mod=mod"
	export CGO_ENABLED=1

	GIT_SHA="$(git ls-remote https://github.com/coreos/etcd.git refs/tags/v$pkgver | awk '{print $1}')" \
		bash -x ./build.sh
}

package() {
	install -d -o "$pkgusers" -g "$pkggroups" -m 700 "$pkgdir"/var/lib/$pkgname
	install -Dm755 bin/etcd "$pkgdir"/usr/bin/etcd
	install -Dm755 bin/etcdctl "$pkgdir"/usr/bin/etcdctl
	install -Dm644 $srcdir/$pkgname.yaml "$pkgdir"/etc/etcd/conf.yml
	install -Dm644 $srcdir/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -Dm755 $srcdir/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

ctl() {
	pkgdesc="A command-line client for etcd"
	amove usr/bin/etcdctl
}

sha512sums="
0d72c40d575997d70d9d4964e7ff4be75c77e13a40ea08fcc020fddc64dc420338f1853d5a51a2dbe3f4c2881ae196a7aa32565e4b41dbda77bc2b6ae2313104  etcd-3.5.18.tar.gz
0d7d8be227cd401748f6ac5d4621da2873c63d18816fa9102d2e6a2f718f6ba269083eddb82c37d704a083eedee726a23991c0a10eadd1b00e05bb549a580cc3  git-sha.patch
e9cfe6fa99f799ba4a498b42499536893d2f678cb7cd9c51f6afd2f06ace3baf8081a29528910a543e58a514e459246b1bc3a93441fa3648fe19cef824b46b47  fix_unsupported_arch.patch
92e6a22dfe12eef76c186c04a4aadca5318300c18aefc979cc03926fddf40e0e9b3bf2b40b75702f2f710dc65420da676c734cfe4d246d86e0728d6e99f43426  etcd.yaml
8b917d2b3a136a97dd9565a91377420ce1f812bfb10bb0caa95f1024dd366cb78ebb0539f16ddfbc399325d41a6664b856d49c5c9aa67bc27e36040f2227356e  etcd.confd
b67f7fd209a29ed2a6ef86d5a3c07cf5dc4138af7c61c3a928471cd79f5579ce7861fd21167db332727dfb2a8e554722366c6505e447f3b2feeae819f869aa11  etcd.initd
"
