# Maintainer: instantOS <hello@instantos.io>
pkgname=instantos-keyring
# Date-based pkgver, bump whenever the key material below changes.
# Epoch 1 sorts above the old date-time pkgvers generated from the
# discontinued git sources.
epoch=1
pkgver=20260825
pkgrel=1
pkgdesc="instantOS pacman keyring"
arch=('any')
url="https://github.com/instantOS/packages"
license=('GPL')
install=$pkgname.install
depends=('bash' 'pacman')

# Key material vendored in this directory:
#   instantos.gpg     exported public key(s): gpg --export <MASTER_FPR>
#   instantos-trusted master key fingerprint(s), one '<FPR>:4:' per line
#   instantos-revoked fingerprints of revoked keys, if any
# See README.md ("Package signing") for how to (re)generate these.
source=(
    'instantos.gpg'
    'instantos-trusted'
    'instantos-revoked'
    'instantos-keyring-wkd-sync'
    'instantos-keyring-wkd-sync.service'
    'instantos-keyring-wkd-sync.timer'
)
sha256sums=(
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
)

prepare() {
    if [ ! -s instantos.gpg ] || [ ! -s instantos-trusted ]; then
        echo "ERROR: $pkgname key material is missing (placeholder files)." >&2
        echo "Populate instantos.gpg and instantos-trusted first," >&2
        echo "see README.md section 'Package signing'." >&2
        return 1
    fi
}

package() {
    install -Dm644 instantos.gpg "$pkgdir/usr/share/pacman/keyrings/instantos.gpg"
    install -Dm644 instantos-trusted "$pkgdir/usr/share/pacman/keyrings/instantos-trusted"
    install -Dm644 instantos-revoked "$pkgdir/usr/share/pacman/keyrings/instantos-revoked"

    install -Dm755 instantos-keyring-wkd-sync \
        "$pkgdir/usr/bin/instantos-keyring-wkd-sync"
    install -Dm644 instantos-keyring-wkd-sync.service \
        "$pkgdir/usr/lib/systemd/system/instantos-keyring-wkd-sync.service"
    install -Dm644 instantos-keyring-wkd-sync.timer \
        "$pkgdir/usr/lib/systemd/system/instantos-keyring-wkd-sync.timer"

    # Vendor-enable the timer, matching archlinux-keyring's WKD refresh timer.
    install -dm755 "$pkgdir/usr/lib/systemd/system/timers.target.wants"
    ln -s ../instantos-keyring-wkd-sync.timer \
        "$pkgdir/usr/lib/systemd/system/timers.target.wants/instantos-keyring-wkd-sync.timer"
}
