launch-script.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. #
  3. # Amazon Lightsail launch script for 3x-ui (self-service, per-instance creds).
  4. #
  5. # Use it one of two ways when creating an Ubuntu 24.04 Lightsail instance:
  6. # * Console: "Add launch script" -> paste this file.
  7. # * CLI: aws lightsail create-instances --user-data file://launch-script.sh ...
  8. #
  9. # It installs the latest 3x-ui release non-interactively and generates unique
  10. # random credentials for THIS instance. The full credentials land in
  11. # /etc/x-ui/install-result.env (mode 600); /etc/motd shows only the URL + username.
  12. #
  13. # IMPORTANT (Lightsail firewall): Lightsail only opens 22/80/443 by default. The
  14. # panel listens on a random high port, so after boot read the port from
  15. # /etc/x-ui/install-result.env and open it under the instance's Networking tab
  16. # (IPv4 Firewall), or pin a known port below and pre-open it.
  17. set -e
  18. export DEBIAN_FRONTEND=noninteractive
  19. # --- Non-interactive install knobs ------------------------------------------
  20. export XUI_NONINTERACTIVE=1
  21. export XUI_SSL_MODE="${XUI_SSL_MODE:-none}"
  22. # Pin a known panel port so you can pre-open it in the Lightsail firewall
  23. # (otherwise a random high port is chosen). Username/password stay random:
  24. # export XUI_PANEL_PORT="54321"
  25. # Other optional pins (unset => secure random):
  26. # export XUI_USERNAME="admin2"
  27. # export XUI_PASSWORD="change-me"
  28. # export XUI_WEB_BASE_PATH="panel"
  29. # Domain TLS instead of plain HTTP:
  30. # export XUI_SSL_MODE="domain" XUI_DOMAIN="panel.example.com" XUI_ACME_EMAIL="[email protected]"
  31. # ----------------------------------------------------------------------------
  32. curl -fsSL https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh | bash
  33. # /etc/motd is world-readable, so it gets ONLY non-secret info (URL + username);
  34. # the full credentials stay in the root-only /etc/x-ui/install-result.env
  35. # (mode 600) — read them with `sudo cat` over SSH.
  36. if [ -r /etc/x-ui/install-result.env ]; then
  37. # shellcheck disable=SC1091
  38. . /etc/x-ui/install-result.env
  39. {
  40. echo
  41. echo "=== 3x-ui panel (generated on first boot) ==="
  42. echo "URL: ${XUI_ACCESS_URL:-unknown}"
  43. echo "Username: ${XUI_USERNAME:-unknown}"
  44. echo "Password + API token: sudo cat /etc/x-ui/install-result.env"
  45. echo "Open the panel port in the Lightsail IPv4 firewall, then log in."
  46. echo "============================================="
  47. } >> /etc/motd 2>/dev/null || true
  48. fi