6b180acd39
Fail clearly when curl/jq/python3 are missing, when the feed cannot be parsed, or when the PKGBUILD rewrite does not stick. A scheduled bump still commits PKGBUILD+.SRCINFO, tags v$pkgver, and pushes; a no-op is only an already-current pkgver.
88 lines
3.1 KiB
Bash
Executable File
88 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Bump PKGBUILD/.SRCINFO when Cursor publishes a newer linux-x64 Grok Bot.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
for cmd in curl jq python3 sha256sum; do
|
|
command -v "$cmd" >/dev/null || { echo "error: missing required command: $cmd" >&2; exit 1; }
|
|
done
|
|
|
|
FEED='https://api2.cursor.sh/updates/api/update/linux-x64/sand/0.0.0/00000000-0000-0000-0000-000000000000/stable'
|
|
resp=$(curl -fsSL "$FEED")
|
|
version=$(jq -r .version <<<"$resp")
|
|
commit=$(jq -r .url <<<"$resp" | sed -E 's#.*/stable/([^/]+)/.*#\1#')
|
|
current=$(sed -n 's/^pkgver=//p' PKGBUILD)
|
|
|
|
if [[ -z "$version" || "$version" == "null" || ! "$commit" =~ ^[0-9a-f]{40}$ ]]; then
|
|
echo "error: could not parse update feed: $resp" >&2
|
|
exit 1
|
|
fi
|
|
if [[ -z "$current" ]]; then
|
|
echo "error: could not read pkgver from PKGBUILD" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$version" == "$current" ]]; then
|
|
echo "Up to date at $version"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Bump $current -> $version (commit $commit)"
|
|
deb_url="https://downloads.cursor.com/grokbot/stable/${commit}/linux/x64/grok-bot_${version}_amd64.deb"
|
|
tmp=$(mktemp)
|
|
trap 'rm -f "$tmp"' EXIT
|
|
curl -fsSL --retry 3 "$deb_url" -o "$tmp"
|
|
deb_sha=$(sha256sum "$tmp" | cut -d' ' -f1)
|
|
shim_sha=$(sha256sum grok-bot-launch.sh | cut -d' ' -f1)
|
|
|
|
# Reset pkgrel on upstream version bumps.
|
|
sed -i \
|
|
-e "s/^pkgver=.*/pkgver=${version}/" \
|
|
-e "s/^_commit=.*/_commit=${commit}/" \
|
|
-e "s/^pkgrel=.*/pkgrel=1/" \
|
|
PKGBUILD
|
|
|
|
newver=$(sed -n 's/^pkgver=//p' PKGBUILD)
|
|
if [[ "$newver" != "$version" ]]; then
|
|
echo "error: PKGBUILD pkgver rewrite failed (got ${newver@Q}, expected ${version@Q})" >&2
|
|
exit 1
|
|
fi
|
|
|
|
python3 - "$deb_sha" "$shim_sha" <<'PY'
|
|
import pathlib, re, sys
|
|
deb_sha, shim_sha = sys.argv[1], sys.argv[2]
|
|
p = pathlib.Path("PKGBUILD")
|
|
text = p.read_text()
|
|
block = f"sha256sums=(\n '{deb_sha}'\n '{shim_sha}'\n)"
|
|
text2, n = re.subn(r"sha256sums=\([^\)]*\)", block, text, count=1, flags=re.S)
|
|
if n != 1:
|
|
raise SystemExit(f"sha256sums replace failed (n={n})")
|
|
p.write_text(text2)
|
|
PY
|
|
|
|
python3 - "$version" "$commit" "$deb_sha" "$shim_sha" <<'PY'
|
|
import pathlib, re, sys
|
|
version, commit, deb_sha, shim_sha = sys.argv[1:5]
|
|
p = pathlib.Path(".SRCINFO")
|
|
lines = []
|
|
saw_sha = False
|
|
for line in p.read_text().splitlines(True):
|
|
if line.startswith("\tpkgver ="):
|
|
lines.append(f"\tpkgver = {version}\n"); continue
|
|
if line.startswith("\tpkgrel ="):
|
|
lines.append("\tpkgrel = 1\n"); continue
|
|
if line.startswith("\tsource = https://downloads.cursor.com/grokbot/stable/"):
|
|
lines.append(f"\tsource = https://downloads.cursor.com/grokbot/stable/{commit}/linux/x64/grok-bot_{version}_amd64.deb\n"); continue
|
|
if line.startswith("\tnoextract = grok-bot_"):
|
|
lines.append(f"\tnoextract = grok-bot_{version}_amd64.deb\n"); continue
|
|
if line.startswith("\tsha256sums ="):
|
|
if not saw_sha:
|
|
lines.append(f"\tsha256sums = {deb_sha}\n")
|
|
lines.append(f"\tsha256sums = {shim_sha}\n")
|
|
saw_sha = True
|
|
continue
|
|
lines.append(line)
|
|
p.write_text("".join(lines))
|
|
PY
|
|
|
|
echo "Updated PKGBUILD and .SRCINFO to ${version} deb_sha=${deb_sha} shim_sha=${shim_sha}"
|