ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(scripts): resolve the agent repo's default branch instead of hardcoding it
Juan Denis1d5c226e5690
diff --git a/scripts/sync-agent-installers.sh b/scripts/sync-agent-installers.shindex 3cdd72da..578317e9 100644--- a/scripts/sync-agent-installers.sh+++ b/scripts/sync-agent-installers.sh@@ -24,21 +24,37 @@ set -uo pipefailREPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"AGENT_REPO="${SERVERKIT_AGENT_REPO:-jhd3197/serverkit-agent}"-# The agent repo's default branch is `master`; this repo's is `main`. Getting-# that backwards makes the raw.githubusercontent fetch 404, which reads as-# "cannot reach the canonical copy" rather than "wrong branch name".-AGENT_REF="${AGENT_REF:-master}"+AGENT_REF="${AGENT_REF:-}"SOURCE="${1:-}"INSTALLERS=(install.sh install.ps1)# Default source: a sibling checkout if there is one (so this works offline and# before the agent change is pushed), otherwise the published branch.+# Ask the repo which branch is its default rather than hardcoding one — see the+# same helper in scripts/test/check-installer-drift.sh. AGENT_REF pins it.+resolve_agent_ref() {+ if [ -n "$AGENT_REF" ]; then printf '%s' "$AGENT_REF"; return 0; fi++ local declared ref+ declared="$(curl -fsSL "https://api.github.com/repos/${AGENT_REPO}" 2>/dev/null \+ | grep -o '"default_branch": *"[^"]*"' | head -1 | sed -e 's/.*: *"//' -e 's/"$//')"+ if [ -n "$declared" ]; then printf '%s' "$declared"; return 0; fi++ for ref in main master; do+ if curl -fsSL -o /dev/null \+ "https://raw.githubusercontent.com/${AGENT_REPO}/${ref}/install.sh" 2>/dev/null; then+ printf '%s' "$ref"; return 0+ fi+ done+ printf 'main'+}+if [ -z "$SOURCE" ]; thenif [ -d "${REPO_ROOT}/../serverkit-agent" ]; thenSOURCE="$(cd "${REPO_ROOT}/../serverkit-agent" && pwd)"else- SOURCE="https://raw.githubusercontent.com/${AGENT_REPO}/${AGENT_REF}"+ SOURCE="https://raw.githubusercontent.com/${AGENT_REPO}/$(resolve_agent_ref)"fifidiff --git a/scripts/test/check-installer-drift.sh b/scripts/test/check-installer-drift.shindex 032b28e6..831a58dc 100644--- a/scripts/test/check-installer-drift.sh+++ b/scripts/test/check-installer-drift.sh@@ -23,10 +23,7 @@ set -uo pipefailREPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"AGENT_REPO="${SERVERKIT_AGENT_REPO:-jhd3197/serverkit-agent}"-# The agent repo's default branch is `master`; this repo's is `main`. Getting-# that backwards makes the raw.githubusercontent fetch 404, which reads as-# "cannot reach the canonical copy" rather than "wrong branch name".-AGENT_REF="${AGENT_REF:-master}"+AGENT_REF="${AGENT_REF:-}"SOURCE="${1:-}"INSTALLERS=(install.sh install.ps1)@@ -39,11 +36,34 @@ bad() { FAIL=$((FAIL + 1)); printf ' \033[31m✘\033[0m %s\n' "$1"; }WORK="$(mktemp -d)"trap 'rm -rf "$WORK"' EXIT+# Ask the repo which branch is its default rather than hardcoding one. The agent+# repo was renamed master -> main; a hardcoded name turns any such rename into a+# 404 that reads as "cannot reach the canonical copy" rather than "wrong branch+# name", which is a genuinely confusing way to fail. AGENT_REF pins it (e.g. to a+# tag) when you want a specific revision.+resolve_agent_ref() {+ if [ -n "$AGENT_REF" ]; then printf '%s' "$AGENT_REF"; return 0; fi++ local declared ref+ declared="$(curl -fsSL "https://api.github.com/repos/${AGENT_REPO}" 2>/dev/null \+ | grep -o '"default_branch": *"[^"]*"' | head -1 | sed -e 's/.*: *"//' -e 's/"$//')"+ if [ -n "$declared" ]; then printf '%s' "$declared"; return 0; fi++ # API unreachable or rate-limited — probe the two plausible names.+ for ref in main master; do+ if curl -fsSL -o /dev/null \+ "https://raw.githubusercontent.com/${AGENT_REPO}/${ref}/install.sh" 2>/dev/null; then+ printf '%s' "$ref"; return 0+ fi+ done+ printf 'main'+}+if [ -z "$SOURCE" ]; thenif [ -d "${REPO_ROOT}/../serverkit-agent" ]; thenSOURCE="$(cd "${REPO_ROOT}/../serverkit-agent" && pwd)"else- SOURCE="https://raw.githubusercontent.com/${AGENT_REPO}/${AGENT_REF}"+ SOURCE="https://raw.githubusercontent.com/${AGENT_REPO}/$(resolve_agent_ref)"fifi