# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=rootlesskit
pkgver=2.2.0
pkgrel=0
pkgdesc="Linux-native fake root for implementing rootless containers"
url="https://github.com/rootless-containers/rootlesskit"
arch="all"
license="Apache-2.0"
depends="shadow-subids iproute2-minimal"
makedepends="go"
subpackages="
	$pkgname-docker-proxy:_docker_proxy
	$pkgname-doc
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/rootless-containers/rootlesskit/archive/refs/tags/v$pkgver.tar.gz"
options="net" # fetch dependencies

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

build() {
	mkdir -v build
	go build -v \
		-ldflags "-X github.com/rootless-containers/rootlesskit/pkg/version.Version=$pkgver" \
		-o build ./cmd/...
}

check() {
	# fork/exec /proc/self/exe: operation not permitted
	# shellcheck disable=2046
	go test $(go list ./... | grep -v pkg/port/builtin)
}

package() {
	install -Dm755 build/* -t "$pkgdir"/usr/bin/
	install -Dm644 docs/*.md -t "$pkgdir"/usr/share/doc/$pkgname
}

_docker_proxy() {
	pkgdesc="$pkgdesc - Docker proxy"
	install_if="$pkgname=$pkgver-r$pkgrel docker-engine"
	amove usr/bin/rootlesskit-docker-proxy
}

sha512sums="
b6eeb8be6c717f1075890d420fd9985f19a7b5efaebc202a61d2af8dae60dee574854ac176e8b1753406841e643298697e84e67adb0f0bf9d7ce95b94c112416  rootlesskit-2.2.0.tar.gz
"
