#!/bin/bash
# Publish a release: run.py (source clients) + run.so (compiled clients) + panel.html.
# Usage: [SO_SRC=/root/run.so] ./publish.sh <version> ["notes"]
set -e
REL=/opt/nova-release; BASE_URL="http://103.195.238.54:8090"
VER="${1:?usage: publish.sh <version> [notes]}"; NOTES="${2:-}"; SO_SRC="${SO_SRC:-/root/run.so}"
cp /opt/webpanel/run.py "$REL/run.py" 2>/dev/null || true
cp /opt/webpanel/panel.html "$REL/panel.html"
SR=$(sha256sum "$REL/run.py" 2>/dev/null | awk '{print $1}'); SH=$(sha256sum "$REL/panel.html" | awk '{print $1}')
SS=""; [ -f "$SO_SRC" ] && { cp "$SO_SRC" "$REL/run.so"; SS=$(sha256sum "$REL/run.so" | awk '{print $1}'); }
cat > "$REL/version.json" <<JSON
{
  "version": "$VER",
  "run_py": "$BASE_URL/run.py",
  "run_so": "$BASE_URL/run.so",
  "panel_html": "$BASE_URL/panel.html",
  "notes": "$NOTES",
  "released": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
  "sha256_run": "$SR",
  "sha256_so": "$SS",
  "sha256_html": "$SH"
}
JSON
sed 's#http://103.195.238.54:8090#http://127.0.0.1:8090#g' "$REL/version.json" > "$REL/version-local.json"
echo "Published v$VER (run.so sha=$SS)"
