#!/bin/sh

set -eu

VERSION="${1:?version is required}"
LINUX_INTEL_SHA="${2:?x86_64 Linux sha256 is required}"
LICENSE_SHA="${3:?license sha256 is required}"
OUT_DIR="${4:?output directory is required}"

mkdir -p "${OUT_DIR}"

cat >"${OUT_DIR}/PKGBUILD" <<EOF
# shellcheck shell=bash disable=SC2034,SC2154
# Generated by scripts/render-aur-bin-files.sh
pkgname=claudectl-bin
pkgver=${VERSION}
pkgrel=1
pkgdesc='Orchestrate a swarm of Claude Code agents with a learning local-LLM brain'
arch=('x86_64')
url='https://github.com/mercurialsolo/claudectl'
license=('MIT')
provides=('claudectl')
conflicts=('claudectl' 'claudectl-git')
source=(
  "claudectl-v\${pkgver}-x86_64-unknown-linux-musl.tar.gz::https://github.com/mercurialsolo/claudectl/releases/download/v\${pkgver}/claudectl-v\${pkgver}-x86_64-unknown-linux-musl.tar.gz"
  "LICENSE::https://raw.githubusercontent.com/mercurialsolo/claudectl/v\${pkgver}/LICENSE"
)
sha256sums=(
  '${LINUX_INTEL_SHA}'
  '${LICENSE_SHA}'
)

package() {
  install -Dm755 "\${srcdir}/claudectl" "\${pkgdir}/usr/bin/claudectl"
  install -Dm644 "\${srcdir}/LICENSE" "\${pkgdir}/usr/share/licenses/\${pkgname}/LICENSE"
}
EOF

cat >"${OUT_DIR}/.SRCINFO" <<EOF
pkgbase = claudectl-bin
	pkgdesc = Orchestrate a swarm of Claude Code agents with a learning local-LLM brain
	pkgver = ${VERSION}
	pkgrel = 1
	url = https://github.com/mercurialsolo/claudectl
	arch = x86_64
	license = MIT
	conflicts = claudectl
	conflicts = claudectl-git
	provides = claudectl
	source = claudectl-v${VERSION}-x86_64-unknown-linux-musl.tar.gz::https://github.com/mercurialsolo/claudectl/releases/download/v${VERSION}/claudectl-v${VERSION}-x86_64-unknown-linux-musl.tar.gz
	source = LICENSE::https://raw.githubusercontent.com/mercurialsolo/claudectl/v${VERSION}/LICENSE
	sha256sums = ${LINUX_INTEL_SHA}
	sha256sums = ${LICENSE_SHA}

pkgname = claudectl-bin
EOF
