#!/usr/bin/env bash set -euo pipefail if [[ "${EUID}" -ne 0 ]]; then echo "Run as root: sudo bash scripts/install-system.sh" exit 1 fi SOURCE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" APP_DIR="${XLX_APP_DIR:-/opt/xlx-server}" install_app_files() { local source_real target_real mkdir -p "$APP_DIR" source_real="$(realpath "$SOURCE_ROOT")" target_real="$(realpath "$APP_DIR")" if [[ "$source_real" != "$target_real" ]]; then tar --exclude='.git' -C "$SOURCE_ROOT" -cf - . | tar -C "$APP_DIR" -xf - fi chown -R root:www-data "$APP_DIR" find "$APP_DIR" -type d -exec chmod 755 {} \; find "$APP_DIR" -type f -exec chmod 644 {} \; } REPO_ROOT="$SOURCE_ROOT" PUBLIC_DIR="$REPO_ROOT/public" detect_host() { if [[ -n "${XLX_PUBLIC_HOST:-}" ]]; then echo "$XLX_PUBLIC_HOST" return fi local fqdn fqdn="$(hostname -f 2>/dev/null || true)" if [[ -n "$fqdn" && "$fqdn" != "localhost" && "$fqdn" != "localhost.localdomain" ]]; then echo "$fqdn" return fi local ip ip="$(hostname -I 2>/dev/null | awk '{print $1}')" if [[ -n "$ip" ]]; then echo "$ip" return fi echo "127.0.0.1" } port_is_busy() { local port="$1" ss -ltnH "sport = :${port}" 2>/dev/null | grep -q . } detect_panel_port() { if [[ -n "${XLX_PANEL_PORT:-}" ]]; then echo "$XLX_PANEL_PORT" return fi for port in 80 8088 8090 8091; do if ! port_is_busy "$port"; then echo "$port" return fi done echo "8099" } random_token() { local token token="$(tr -dc 'A-Za-z0-9' "$REPO_ROOT/config/config.php" < /etc/xlx/xlxd.env < /etc/apache2/ports.conf < /etc/apache2/sites-available/xlx-panel.conf a2dissite 000-default.conf >/dev/null 2>&1 || true a2ensite xlx-panel.conf systemctl restart apache2 echo "Building and installing xlxd reflector. This can take a few minutes..." bash "$REPO_ROOT/scripts/install-xlxd.sh" XLXD_START_STATUS="not started" if command -v timeout >/dev/null 2>&1; then if timeout 20s systemctl start xlxd; then XLXD_START_STATUS="started" else XLXD_START_STATUS="start failed or timed out; run: sudo systemctl status xlxd --no-pager" fi else if systemctl start xlxd; then XLXD_START_STATUS="started" else XLXD_START_STATUS="start failed; run: sudo systemctl status xlxd --no-pager" fi fi cat <