cloud-init.yaml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #cloud-config
  2. # ---------------------------------------------------------------------------
  3. # Generic 3x-ui unattended install via cloud-init user-data.
  4. #
  5. # Works on any cloud-init platform: Hetzner, AWS, DigitalOcean, Vultr, GCP,
  6. # Azure, Oracle. Paste the whole file as the instance "user data".
  7. #
  8. # It installs the latest 3x-ui release NON-INTERACTIVELY, generating unique
  9. # random credentials per instance. Full credentials are surfaced ONLY on the
  10. # serial console (owner-only); /etc/motd (world-readable) shows just the access
  11. # URL + username. Nothing is baked in advance — every instance is unique.
  12. #
  13. # Requires the non-interactive install.sh (3x-ui with XUI_NONINTERACTIVE support).
  14. # Edit the exported XUI_* knobs in /opt/xui-bootstrap.sh below to customise.
  15. # ---------------------------------------------------------------------------
  16. package_update: true
  17. package_upgrade: false
  18. write_files:
  19. - path: /opt/xui-bootstrap.sh
  20. permissions: '0700'
  21. owner: root:root
  22. content: |
  23. #!/usr/bin/env bash
  24. set -euo pipefail
  25. export DEBIAN_FRONTEND=noninteractive
  26. # --- Non-interactive install knobs --------------------------------------
  27. export XUI_NONINTERACTIVE=1
  28. # SSL mode: none (plain HTTP, default) | ip | domain
  29. export XUI_SSL_MODE="${XUI_SSL_MODE:-none}"
  30. # Pin credentials instead of random (leave unset for secure random values):
  31. # export XUI_USERNAME="admin2"
  32. # export XUI_PASSWORD="change-me-please"
  33. # export XUI_PANEL_PORT="2053"
  34. # export XUI_WEB_BASE_PATH="panel"
  35. # Let's Encrypt domain certificate instead of plain HTTP:
  36. # export XUI_SSL_MODE="domain"
  37. # export XUI_DOMAIN="panel.example.com"
  38. # export XUI_ACME_EMAIL="[email protected]"
  39. # PostgreSQL instead of SQLite:
  40. # export XUI_DB_TYPE="postgres"
  41. # export XUI_DB_DSN="postgres://user:pass@host:5432/db?sslmode=disable"
  42. # ------------------------------------------------------------------------
  43. curl -fsSL https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh | bash
  44. # Surface the generated credentials. Full creds (incl. password + API token)
  45. # go ONLY to the serial console (/dev/console, owner-only). /etc/motd is
  46. # world-readable, so it gets just the access URL + username and a pointer
  47. # to the root-only env file.
  48. if [ -r /etc/x-ui/install-result.env ]; then
  49. {
  50. echo
  51. echo "=== 3x-ui panel credentials (generated on first boot) ==="
  52. cat /etc/x-ui/install-result.env
  53. echo "========================================================"
  54. echo "Change the password after first login."
  55. } > /dev/console 2>/dev/null || true
  56. # shellcheck disable=SC1091
  57. . /etc/x-ui/install-result.env
  58. {
  59. echo
  60. echo "=== 3x-ui panel (generated on first boot) ==="
  61. echo "URL: ${XUI_ACCESS_URL:-unknown}"
  62. echo "Username: ${XUI_USERNAME:-unknown}"
  63. echo "Password + API token: sudo cat /etc/x-ui/install-result.env"
  64. echo "============================================="
  65. echo "Change the password after first login."
  66. } >> /etc/motd 2>/dev/null || true
  67. fi
  68. runcmd:
  69. - [bash, /opt/xui-bootstrap.sh]
  70. final_message: "3x-ui installed — full credentials in /etc/x-ui/install-result.env (sudo); /etc/motd shows the URL + username only."