#!/bin/bash
# Builds omarchycn-keyring in a clean archlinux container; output to packages/out/

set -euo pipefail

ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)

docker run --rm -v "$ROOT:/src:ro" -v "$ROOT/packages/out:/out" archlinux/archlinux:latest bash -c '
set -euo pipefail
pacman -Syu --noconfirm --quiet base-devel > /dev/null
useradd -m builder
cp -r /src/packages/omarchycn-keyring /home/builder/pkg
cp /src/cn/keys/omarchycn-registry.asc /home/builder/pkg/omarchycn-registry.key
cp /src/cn/keys/omarchycn-release.asc /home/builder/pkg/omarchycn-release.key
chown -R builder /home/builder/pkg
cd /home/builder/pkg
sudo -u builder makepkg --noconfirm
install -m644 omarchycn-keyring-*.pkg.tar.zst /out/
'
echo "Built: $(ls "$ROOT"/packages/out/omarchycn-keyring-*.pkg.tar.zst)"
