diff --git a/scripts/install-gitea-runner.sh b/scripts/install-gitea-runner.sh index 73cf870..18229be 100755 --- a/scripts/install-gitea-runner.sh +++ b/scripts/install-gitea-runner.sh @@ -26,15 +26,18 @@ if [ -z "$TOKEN" ] || [ -z "$NAME" ] || [ -z "$LABELS" ]; then exit 1 fi -# ── 0. Require root ──────────────────────────────────────────────── +# ── 0. Require root — auto-elevate if possible ──────────────────── if [ "$(id -u)" -ne 0 ]; then - echo "❌ This script must be run as root." - if [ -f /etc/alpine-release ]; then - echo " Use: doas $0 $*" + # Try to re-execute with available privilege escalation + if command -v sudo >/dev/null 2>&1; then + exec sudo "$0" "$@" + elif command -v doas >/dev/null 2>&1; then + exec doas "$0" "$@" else - echo " Use: sudo $0 $*" + echo "❌ This script must be run as root." + echo " Install sudo or doas, or run as root directly." + exit 1 fi - exit 1 fi # ── 0. Detect OS + privilege elevation method ──────────────────────