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(cli): wrapper parity with backend/cli.py + bash tab-completion
Juan Denisad73f0c58138
diff --git a/install.sh b/install.shindex 854470b4..c53056f1 100644--- a/install.sh+++ b/install.sh@@ -1467,6 +1467,12 @@ install_service() {chmod +x "$INSTALL_DIR/serverkit"ln -sf "$INSTALL_DIR/serverkit" /usr/local/bin/serverkit+ # Bash tab-completion (best-effort — not every distro ships bash-completion).+ if [ -d /etc/bash_completion.d ]; then+ bash "$INSTALL_DIR/serverkit" completion > /etc/bash_completion.d/serverkit 2>/dev/null \+ || rm -f /etc/bash_completion.d/serverkit+ fi+# Without systemd (LXC/WSL/containers) we can't enable the unit — say so# clearly instead of failing cryptically (Goal G5). The probe is inline# (svc_has_systemd) so it holds even when scripts/lib never made it todiff --git a/scripts/lib/uninstall.sh b/scripts/lib/uninstall.shindex eac2b6a3..4eaf4ecf 100644--- a/scripts/lib/uninstall.sh+++ b/scripts/lib/uninstall.sh@@ -154,8 +154,9 @@ serverkit_uninstall_core() {# ---- apt lock-wait drop-in (only the installer creates this) -----------_u_try rm -f /etc/apt/apt.conf.d/99-serverkit-lock-wait.conf- # ---- CLI symlink -------------------------------------------------------+ # ---- CLI symlink + bash completion -------------------------------------_u_try rm -f /usr/local/bin/serverkit+ _u_try rm -f /etc/bash_completion.d/serverkit# ---- Code: install dir + blue/green slots + backup snapshot ------------_u_info "Removing installation files..."diff --git a/scripts/test/test_cli.sh b/scripts/test/test_cli.shindex 65af061f..29a48732 100644--- a/scripts/test/test_cli.sh+++ b/scripts/test/test_cli.sh@@ -560,6 +560,101 @@ elsebad "executed-mode dispatch broken: version=$rc help=$rc_help bogus=$rc_bogus"fi+# --------------------------------------------------------------------------+# T17 — migrate-db must forward to the Click verb `db-migrate`. The old code+# forwarded the wrapper's own name (`migrate-db`), which cli.py never defined,+# so `serverkit migrate-db` died with "No such command" on every real box.+# --------------------------------------------------------------------------+out="$(+ set -Eeuo pipefail+ check_installed() { :; }+ run_cli() { printf 'CLI:%s' "$*"; }+ cmd_migrate_db 2>&1+)"+rc=$?+if [ "$rc" -eq 0 ] && [ "$out" = "CLI:db-migrate" ]; then+ ok "migrate-db forwards to the Click verb 'db-migrate'"+else+ bad "migrate-db forwarding wrong: rc=$rc out=[$out]"+fi++# --------------------------------------------------------------------------+# T18 — panel-CLI forwarding: every Click-only verb must be dispatched (reach+# run_cli / fail on the missing venv), never rejected as "Unknown command".+# `completion` is pure output and must succeed anywhere.+# --------------------------------------------------------------------------+t="$WORK/t18"; mkdir -p "$t/install"+unknown=""+for c in manifest services apps repair login-url support-bundle \+ db-migrate db-status db-history panel-status panel-doctor; do+ out="$(SERVERKIT_DIR="$t/install" bash "$CLI" "$c" 2>&1)" || true+ if printf '%s' "$out" | grep -q 'Unknown command'; then+ unknown="$unknown $c"+ fi+done+out_comp="$(SERVERKIT_DIR="$t/install" bash "$CLI" completion 2>&1)"+rc_comp=$?+if [ -z "$unknown" ] && [ "$rc_comp" -eq 0 ] \+ && printf '%s' "$out_comp" | grep -q 'complete -F _serverkit serverkit'; then+ ok "panel-CLI verbs are all dispatched; completion prints a complete(1) script"+else+ bad "forwarding gaps:[$unknown] completion rc=$rc_comp"+fi++# --------------------------------------------------------------------------+# T19 — parity guards (the drift that hid the migrate-db bug for months):+# (a) every top-level Click verb in backend/cli.py is reachable from the+# wrapper — as itself, as panel-<verb>, or via a documented exception;+# (b) every wrapper dispatch label is offered by `serverkit completion`.+# --------------------------------------------------------------------------+cli_cmds="$(awk '+ /^@cli\.(command|group)\(/ {+ if (match($0, /\047[a-z0-9-]+\047/)) {+ print substr($0, RSTART + 1, RLENGTH - 2)+ } else {+ pending = 1+ }+ next+ }+ pending && /^def / {+ name = $2+ sub(/\(.*/, "", name)+ gsub(/_/, "-", name)+ print name+ pending = 0+ }+' "$SCRIPT_DIR/../../backend/cli.py")"+dispatch_labels="$(sed -n '/^case "\${1:-help}" in/,/^esac$/p' "$CLI" \+ | sed -n 's/^[[:space:]]*\([a-z][a-z0-9|-]*\))$/\1/p' | tr '|' '\n')"+missing=""+for c in $cli_cmds; do+ case "$c" in+ drop-db) continue ;; # deliberately unexposed (factory-reset is the supported flow)+ esac+ if ! printf '%s\n' "$dispatch_labels" | grep -qx "$c" \+ && ! printf '%s\n' "$dispatch_labels" | grep -qx "panel-$c"; then+ missing="$missing $c"+ fi+done+if [ -n "$cli_cmds" ] && [ -z "$missing" ]; then+ ok "every backend/cli.py verb is reachable through the wrapper dispatch"+else+ bad "cli.py verbs missing from the wrapper dispatch:[$missing]"+fi+comp_words="$(cmd_completion | sed -n 's/^ *commands="\(.*\)"$/\1/p')"+not_completed=""+for label in $dispatch_labels; do+ case "$label" in -*) continue ;; esac+ if ! printf ' %s ' "$comp_words" | grep -qF " $label "; then+ not_completed="$not_completed $label"+ fi+done+if [ -n "$comp_words" ] && [ -z "$not_completed" ]; then+ ok "every dispatch label is offered by 'serverkit completion'"+else+ bad "dispatch labels missing from completion:[$not_completed]"+fi+# --------------------------------------------------------------------------printf '\n%d passed, %d failed, %d skipped\n\n' "$PASS" "$FAIL" "$SKIP"[ "$FAIL" -eq 0 ]diff --git a/scripts/test/test_update.sh b/scripts/test/test_update.shindex 62f87f31..702633f9 100644--- a/scripts/test/test_update.sh+++ b/scripts/test/test_update.sh@@ -897,6 +897,44 @@ elsebad "contract: regression path rc=$t28_rc (must be 0, with the loud warning): [$out]"fi+# --------------------------------------------------------------------------+# T29 — refresh_bash_completion: regenerates the completion file from the+# switched-in CLI, honours DRY_RUN, and no-ops on boxes without a+# bash-completion directory. (SERVERKIT_COMPLETION_DIR is the test seam.)+# --------------------------------------------------------------------------+t="$WORK/t29"; mkdir -p "$t/comp" "$t/comp-dry"+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"+t29_rc=0+out="$(+ {+ set -Eeuo pipefail+ SERVERKIT_COMPLETION_DIR="$t/comp"; INSTALL_DIR="$REPO_ROOT"; DRY_RUN=0+ refresh_bash_completion+ } 2>&1+)" || t29_rc=$?+t29b_rc=0+out_dry="$(+ {+ set -Eeuo pipefail+ SERVERKIT_COMPLETION_DIR="$t/comp-dry"; INSTALL_DIR="$REPO_ROOT"; DRY_RUN=1+ refresh_bash_completion+ } 2>&1+)" || t29b_rc=$?+t29c_rc=0+(+ set -Eeuo pipefail+ SERVERKIT_COMPLETION_DIR="$t/absent"; INSTALL_DIR="$REPO_ROOT"; DRY_RUN=0+ refresh_bash_completion+) >/dev/null 2>&1 || t29c_rc=$?+if [ "$t29_rc" -eq 0 ] && grep -q 'complete -F _serverkit serverkit' "$t/comp/serverkit" \+ && [ "$t29b_rc" -eq 0 ] && printf '%s' "$out_dry" | grep -q 'dry-run' \+ && [ ! -f "$t/comp-dry/serverkit" ] \+ && [ "$t29c_rc" -eq 0 ]; then+ ok "refresh_bash_completion writes the file, honours dry-run, skips absent dirs"+else+ bad "refresh_bash_completion broken: rc=$t29_rc/$t29b_rc/$t29c_rc out=[$out] dry=[$out_dry]"+fi+# --------------------------------------------------------------------------printf '\n%d passed, %d failed, %d skipped\n\n' "$PASS" "$FAIL" "$SKIP"[ "$FAIL" -eq 0 ]diff --git a/scripts/update.sh b/scripts/update.shindex 99f19d26..000e6079 100644--- a/scripts/update.sh+++ b/scripts/update.sh@@ -1212,6 +1212,20 @@ ensure_firewall() {good "Firewall ensured ($backend): 80/tcp and 443/tcp open"}+refresh_bash_completion() {+ # Regenerate bash tab-completion from the switched-in CLI so new commands+ # complete immediately after an update. Best-effort: boxes without the+ # bash-completion package simply skip it.+ local dir="${SERVERKIT_COMPLETION_DIR:-/etc/bash_completion.d}"+ [ -d "$dir" ] || return 0+ if [ "$DRY_RUN" = "1" ]; then+ info "[dry-run] would refresh $dir/serverkit"+ return 0+ fi+ bash "$INSTALL_DIR/serverkit" completion > "$dir/serverkit" 2>/dev/null \+ || { rm -f "$dir/serverkit"; warn "Could not refresh bash completion (non-fatal)"; }+}+# ---------------------------------------------------------------------------# All-Docker deployment (compose) detection + update path# ---------------------------------------------------------------------------@@ -1638,6 +1652,9 @@ fi# Keep the firewall in sync (idempotent, best-effort).ensure_firewall || true+# Keep bash tab-completion in sync with the updated CLI (best-effort).+refresh_bash_completion || true+# Cleanup.cleanupdiff --git a/serverkit b/serverkitindex fd7dcf7f..5a88e95a 100644--- a/serverkit+++ b/serverkit@@ -238,7 +238,9 @@ cmd_help() {echo ""echo "Database Commands:"echo " init-db Initialize the database"- echo " migrate-db Apply database migrations"+ echo " migrate-db Apply database migrations (alias: db-migrate [--no-backup])"+ echo " db-status Show migration status (--json)"+ echo " db-history List all migration revisions"echo " backup-db Backup the database"echo " restore-db Restore database from backup"echo ""@@ -270,9 +272,20 @@ cmd_help() {echo " doctor Check for common issues"echo " doctor --fix Auto-fix detected issues"echo ""+ echo "Panel Commands (talk to the running panel API; most support --json):"+ echo " panel-status Panel health and version"+ echo " panel-doctor Panel-side diagnostics ([--repair] [--yes])"+ echo " repair Repair a single drift finding (repair <type> <id>)"+ echo " services list | restart <name> — monitored system services"+ echo " apps list — applications known to the panel"+ echo " manifest plan | diff | apply — a project's serverkit.yaml"+ echo " login-url Mint a one-time panel login link"+ echo " support-bundle Build a scrubbed diagnostic zip"+ echo ""echo "Utility Commands:"echo " generate-keys Generate secure keys for .env"echo " config Edit configuration"+ echo " completion Print bash tab-completion (serverkit completion > /etc/bash_completion.d/serverkit)"echo ""echo "Examples:"echo " sudo serverkit start"@@ -282,6 +295,48 @@ cmd_help() {echo ""}+cmd_completion() {+ # Print a bash tab-completion script for `serverkit`.+ # Install: serverkit completion > /etc/bash_completion.d/serverkit+ # Ad-hoc: eval "$(serverkit completion)"+ # The word lists are static on purpose (no venv/Python needed to complete);+ # scripts/test/test_cli.sh guards them against drifting from the dispatch.+ cat <<'COMPLETION_EOF'+# bash completion for the serverkit CLI (generated by `serverkit completion`)+_serverkit() {+ local cur commands+ cur="${COMP_WORDS[COMP_CWORD]}"+ commands="help start stop restart status logs update branch version check-update uninstall create-admin reset-password unlock-user list-users make-admin deactivate-user activate-user init-db migrate-db db-migrate db-status db-history backup-db restore-db cleanup-apps factory-reset generate-keys config setup-proxy create-app deploy-template list-servers deployment-status list-apps start-app stop-app app-logs add-site list-sites remove-site doctor manifest services apps repair login-url support-bundle panel-status panel-doctor completion"++ if [ "$COMP_CWORD" -eq 1 ]; then+ COMPREPLY=( $(compgen -W "$commands" -- "$cur") )+ return+ fi++ case "${COMP_WORDS[1]}" in+ manifest) COMPREPLY=( $(compgen -W "plan diff apply --project --file --json --yes" -- "$cur") ) ;;+ services) COMPREPLY=( $(compgen -W "list restart --json" -- "$cur") ) ;;+ apps) COMPREPLY=( $(compgen -W "list --json" -- "$cur") ) ;;+ logs) COMPREPLY=( $(compgen -W "backend frontend all" -- "$cur") ) ;;+ update) COMPREPLY=( $(compgen -W "--branch --release --force --dry-run" -- "$cur") ) ;;+ uninstall) COMPREPLY=( $(compgen -W "--purge --delete-volumes --keep-data --yes --dry-run" -- "$cur") ) ;;+ doctor) COMPREPLY=( $(compgen -W "--fix" -- "$cur") ) ;;+ panel-doctor) COMPREPLY=( $(compgen -W "--repair --yes --json" -- "$cur") ) ;;+ panel-status|list-users|list-servers|db-status) COMPREPLY=( $(compgen -W "--json" -- "$cur") ) ;;+ cleanup-apps) COMPREPLY=( $(compgen -W "--delete-volumes --keep-db" -- "$cur") ) ;;+ list-apps) COMPREPLY=( $(compgen -W "--all --json" -- "$cur") ) ;;+ deployment-status) COMPREPLY=( $(compgen -W "--logs --json" -- "$cur") ) ;;+ db-migrate|migrate-db) COMPREPLY=( $(compgen -W "--no-backup" -- "$cur") ) ;;+ login-url) COMPREPLY=( $(compgen -W "--ttl --ip --user" -- "$cur") ) ;;+ support-bundle) COMPREPLY=( $(compgen -W "--out --passphrase" -- "$cur") ) ;;+ deploy-template) COMPREPLY=( $(compgen -W "--name --target --var --wait" -- "$cur") ) ;;+ *) COMPREPLY=() ;;+ esac+}+complete -F _serverkit serverkit+COMPLETION_EOF+}+cmd_start() {check_rootcheck_installed@@ -609,7 +664,16 @@ cmd_init_db() {cmd_migrate_db() {check_installed- run_cli migrate-db+ # The Click verb is `db-migrate`; `migrate-db` is the legacy wrapper name.+ run_cli db-migrate+}++cmd_panel_cli() {+ # Forward a command verbatim to the Python admin CLI (backend/cli.py) so+ # every Click verb is reachable as `serverkit <verb> …` without a wrapper+ # function per command (that pattern is how migrate-db silently broke).+ check_installed+ run_cli "$@"}cmd_cleanup_apps() {@@ -1398,6 +1462,20 @@ case "${1:-help}" inmigrate-db)cmd_migrate_db;;+ manifest|services|apps|repair|login-url|support-bundle|db-migrate|db-status|db-history)+ cmd_panel_cli "$@"+ ;;+ panel-status)+ shift+ cmd_panel_cli status "$@"+ ;;+ panel-doctor)+ shift+ cmd_panel_cli doctor "$@"+ ;;+ completion)+ cmd_completion+ ;;cleanup-apps)shiftcmd_cleanup_apps "$@"