smoke-noninteractive.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env bash
  2. #
  3. # smoke-noninteractive.sh — verify the non-interactive install path.
  4. #
  5. # Runs install.sh inside an Ubuntu container with NO TTY (piped) and
  6. # XUI_NONINTERACTIVE=1, then asserts:
  7. # * /etc/x-ui/install-result.env exists (mode 600) with random, non-default creds
  8. # * the panel reports hasDefaultCredential: false (no admin/admin remains)
  9. # * the panel HTTP server actually serves on the generated port/base path
  10. # * with a [version] argument: the installed binary reports exactly that version
  11. #
  12. # Requires Docker and network access (install.sh downloads the released binary).
  13. # Usage: bash deploy/test/smoke-noninteractive.sh [version]
  14. # With no argument install.sh resolves releases/latest. Pass an explicit tag
  15. # (e.g. v3.4.2) to verify that exact release — the tag-triggered CI run does
  16. # this so it cannot silently validate the previous release (#5756).
  17. set -euo pipefail
  18. REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
  19. IMAGE="${SMOKE_IMAGE:-ubuntu:24.04}"
  20. XUI_SMOKE_VERSION="${1:-}"
  21. if ! command -v docker > /dev/null 2>&1; then
  22. echo "ERROR: docker is required for this smoke test." >&2
  23. exit 1
  24. fi
  25. echo "== non-interactive install smoke test (image: $IMAGE, version: ${XUI_SMOKE_VERSION:-latest}) =="
  26. docker run --rm \
  27. -v "${REPO_ROOT}/install.sh:/root/install.sh:ro" \
  28. -e XUI_NONINTERACTIVE=1 \
  29. -e XUI_SSL_MODE=none \
  30. -e XUI_SMOKE_VERSION="$XUI_SMOKE_VERSION" \
  31. -e DEBIAN_FRONTEND=noninteractive \
  32. "$IMAGE" bash -euo pipefail -c '
  33. apt-get update -qq
  34. apt-get install -y -qq curl tar openssl ca-certificates > /dev/null
  35. echo "--- running install.sh piped (no TTY), version: ${XUI_SMOKE_VERSION:-latest} ---"
  36. # Piping guarantees stdin is not a TTY, exercising the auto non-interactive path.
  37. if [ -n "${XUI_SMOKE_VERSION:-}" ]; then
  38. cat /root/install.sh | bash -s -- "$XUI_SMOKE_VERSION"
  39. else
  40. cat /root/install.sh | bash
  41. fi
  42. echo "--- assertions ---"
  43. if [ -n "${XUI_SMOKE_VERSION:-}" ]; then
  44. installed=$(/usr/local/x-ui/x-ui -v)
  45. [ "$installed" = "${XUI_SMOKE_VERSION#v}" ] \
  46. || { echo "FAIL: installed version $installed, want ${XUI_SMOKE_VERSION#v}"; exit 1; }
  47. fi
  48. RESULT=/etc/x-ui/install-result.env
  49. test -f "$RESULT" || { echo "FAIL: $RESULT missing"; exit 1; }
  50. perms=$(stat -c %a "$RESULT")
  51. [ "$perms" = "600" ] || { echo "FAIL: $RESULT perms=$perms (want 600)"; exit 1; }
  52. # shellcheck disable=SC1090
  53. . "$RESULT"
  54. [ -n "${XUI_USERNAME:-}" ] && [ "$XUI_USERNAME" != "admin" ] \
  55. || { echo "FAIL: username missing or still admin"; exit 1; }
  56. [ -n "${XUI_PASSWORD:-}" ] && [ "$XUI_PASSWORD" != "admin" ] \
  57. || { echo "FAIL: password missing or still admin"; exit 1; }
  58. [ -n "${XUI_PANEL_PORT:-}" ] || { echo "FAIL: port missing"; exit 1; }
  59. # No default admin in the DB.
  60. /usr/local/x-ui/x-ui setting -show | grep -q "hasDefaultCredential: false" \
  61. || { echo "FAIL: hasDefaultCredential is not false"; exit 1; }
  62. echo "--- verifying the panel serves HTTP ---"
  63. cd /usr/local/x-ui
  64. ./x-ui > /tmp/xui.log 2>&1 &
  65. xpid=$!
  66. for _ in $(seq 1 15); do
  67. code=$(curl -s -o /dev/null -w "%{http_code}" \
  68. "http://127.0.0.1:${XUI_PANEL_PORT}/${XUI_WEB_BASE_PATH}/" 2>/dev/null || true)
  69. case "$code" in 200|301|302|307|308) break ;; esac
  70. sleep 1
  71. done
  72. kill "$xpid" 2>/dev/null || true
  73. echo "panel HTTP status: ${code:-none}"
  74. case "${code:-}" in
  75. 200|301|302|307|308) : ;;
  76. *) echo "FAIL: panel did not serve (status ${code:-none})"; tail -n 30 /tmp/xui.log; exit 1 ;;
  77. esac
  78. echo "SMOKE_PASS: user=$XUI_USERNAME port=$XUI_PANEL_PORT path=$XUI_WEB_BASE_PATH"
  79. '
  80. echo "== non-interactive smoke test PASSED =="