# maintainer: cinnaboot <cinnaboot at proton dot me>

pkgname=age-plugin-tkey
pkgver=e524299
pkgrel=1
pkgdesc="Age Plugin for the  Tillitis TKey"
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
url="https://github.com/quite/age-plugin-tkey"
license=('GPL2')
makedepends=('fuse-overlayfs' 'git' 'go' 'podman')
conflicts=("${pkgname}")
provides=("${pkgname}")
source=("git+https://github.com/quite/age-plugin-tkey#branch=rework"
        "Makefile-patch")
b2sums=('SKIP'
	'c90546b17ad8e3c15c1c7c2d303372afabbf910a04d541c691f8d6ede0191c840fea3c6bc1613474c3804b1456daf267e6aded68051d41bd54c364dfa71f659e'
)


prepare() {
        echo "-----------------------------------------"
        echo "WARNING: you must have /etc/subuid, and /etc/subgid files configured"
        echo "  for root, and your user to build with podman"
        echo "  see) https://wiki.archlinux.org/title/Podman#Rootless_Podman"

        user_subuid=$(grep $USER /etc/subuid)
        user_subgid=$(grep $USER /etc/subgid)
        root_subuid=$(grep root /etc/subuid)
        root_subgid=$(grep root /etc/subgid)

        if [[ $user_subuid =~ $USER \
                && $user_subgid =~ $USER \
                && $root_subuid =~ root \
                && $root_subgid =~ root ]]; then
                echo found
        else
                exit 1
        fi

        patch "$pkgname/Makefile" Makefile-patch
}

build() {
        cd "$pkgname/contrib"
        make
}

package() {
        destbin="${pkgdir}/usr/bin"
        cd "${srcdir}/${pkgname}"
        install -Dm755 age-plugin-tkey "${destbin}/age-plugin-tkey"
        strip "${destbin}"/age-plugin-tkey
}
