c_josie_overlay

#!/usr/bin/env bash
# Report pinned-in-tree vs upstream-latest for every josie-overlay package.
# Report-only and cheap: run it first; only a "behind" row is worth spending
# attention on. Requires network. Exits 0 always.
set -euo pipefail

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

# newest ebuild version in a package dir (e.g. "2.0.30")
cur() {
	local newest; newest=$(ls "$1"/*.ebuild | sort -V | tail -1)
	local name; name=$(basename "$newest" .ebuild)
	printf '%s' "${name##*-}"
}

gh_rel_latest() { curl -fsSL "https://api.github.com/repos/$1/releases/latest" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p'; }
# newest version-looking token matching $2 in the HTML directory listing $1
dir_newest() { curl -fsSL "$1" | grep -oE "$2" | sort -V | tail -1 | grep -oE '[0-9]+(\.[0-9]+)+'; }

latest_opencode() { curl -fsSL https://registry.npmjs.org/@opencode/cli-linux-x64 | python3 -c 'import sys,json;print(json.load(sys.stdin)["dist-tags"]["latest"])'; }
latest_radiance() { curl -fsSL "https://codeberg.org/api/v1/repos/StillDeadcode/radiance/tags?limit=100" | python3 -c 'import sys,json;v=[t["name"].lstrip("v") for t in json.load(sys.stdin)];print(sorted(v,key=lambda s:[int(x) for x in s.split(".")])[-1])'; }
latest_vesktop()  { gh_rel_latest Vencord/Vesktop | sed 's/^v//'; }
latest_fah()      { dir_newest "https://download.foldingathome.org/releases/public/fah-client/debian-10-64bit/release/" 'fah-client_[0-9.]+_amd64\.deb'; }
latest_fah_web()  { dir_newest "https://download.foldingathome.org/releases/public/fah-web-control/debian-13-64bit/release/" 'fah-web-control_[0-9.]+\.zip'; }
latest_therock()  { curl -fsSL "https://api.github.com/repos/ROCm/rocm-systems/releases?per_page=100" | python3 -c 'import sys,json;t=[r["tag_name"] for r in json.load(sys.stdin) if r["tag_name"].startswith("therock-10.")];print(sorted(t,key=lambda s:[int(x) for x in s.split("-")[1].split(".")])[-1].removeprefix("therock-"))'; }

status=0
printf '%-32s %-10s %-10s %s\n' PACKAGE IN-TREE UPSTREAM STATUS
printf '%-32s %-10s %-10s %s\n' -------------------------------- --------- --------- ------
report() { # report <label> <current> <latest>
	local mark="ok"; [ "$2" = "$3" ] || { mark="BEHIND"; status=1; }
	printf '%-32s %-10s %-10s %s\n' "$1" "$2" "$3" "$mark"
}

report dev-util/opencode-bin        "$(cur dev-util/opencode-bin)"        "$(latest_opencode)"
report dev-util/radiance            "$(cur dev-util/radiance)"            "$(latest_radiance)"
report net-im/vesktop-bin           "$(cur net-im/vesktop-bin)"           "$(latest_vesktop)"
report sci-biology/fah-client-bin   "$(cur sci-biology/fah-client-bin)"   "$(latest_fah)"
report sci-biology/fah-web-control-bin "$(cur sci-biology/fah-web-control-bin)" "$(latest_fah_web)"
report rocm-therock-chain           "$(cur dev-libs/rocm-core)"           "$(latest_therock)"

exit 0