# Contributor: Christian Kampka <christian@kampka.net>
# Contributor: Gennady Feldman <gena01@gmail.com>
# Maintainer:
pkgname=vault
pkgver=0.9.1
pkgrel=0
pkgdesc="Vault is a tool for securely accessing secrets"
url="https://www.vaultproject.io/"
arch="all"
license="MPL-2.0"
depends=""
makedepends="go"
install="$pkgname.pre-install"
pkgusers="vault"
pkggroups="vault"
options="!check"
source="$pkgname-$pkgver.tar.gz::https://github.com/hashicorp/$pkgname/archive/v$pkgver.tar.gz
	vault.confd
	vault.hcl
	vault.initd"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"

	mkdir -p "$builddir/src/github.com/hashicorp"
	ln -s "$builddir" "$builddir/src/github.com/hashicorp/vault"
	GOPATH="$builddir" go build -v -o bin/$pkgname --tags vault
}

package() {
	cd "$builddir"

	install -m755 -D "$srcdir/$pkgname.initd" \
		"$pkgdir/etc/init.d/$pkgname"

	install -m644 -D "$srcdir/$pkgname.confd" \
		"$pkgdir/etc/conf.d/$pkgname"

	install -m750 -o root -g vault -D bin/$pkgname \
		"$pkgdir/usr/sbin/$pkgname"

	# Allow vault to use mlock as "vault" user.
	setcap cap_ipc_lock=+ep \
		"$pkgdir/usr/sbin/$pkgname"

	install -m750 -o root -g vault -D "$srcdir/$pkgname.hcl" \
		"$pkgdir/etc/$pkgname.hcl"

	install -m750 -o vault -g vault -d "$pkgdir/var/lib/$pkgname"
}

sha512sums="f8362b3b3e09d5e4b63e58a31eb8791d5518b8a7f50758ee4b92d6a4ecdcb51cef15a45eeb2aa75c427dcc45686c81c332e563e9d6f4fb71b5233f4509a3d528  vault-0.9.1.tar.gz
6f3f30e5c9d9dd5117f18fce0e669f0cd752a6be4910405d6b394f15273372731ee887a5ba4c700293e5b8bc2bf40fd69d4337156f77b03549d2dc2c0a666bec  vault.confd
8c064aa5dcca84822c1fa85e9d0ff520df46f794b2e9c689a9b4f81f74279387b3aebc08b3ca26cf786c2fcf1a330e765bf5a511074c24f87e5346672346ba1c  vault.hcl
1e436932647b191e691f5c60bec4ad926588cee5119c7cbe61345249a6768472387b6dd8b19b954c8ac80fb97f6e68f93749229b216300b0438dbeb0bdb57957  vault.initd"
