#!/usr/bin/env bash
set -euo pipefail

INSTALLER_URL="https://sngine-live.fluttercrafters.com/installer/live-server-installer.php.txt"

if ! command -v php >/dev/null 2>&1; then
  echo "[error] PHP CLI is required to run the live server installer." >&2
  exit 1
fi

TMP_FILE="$(mktemp /tmp/fc-live-installer.XXXXXX.php)"

cleanup() {
  rm -f "$TMP_FILE"
}
trap cleanup EXIT

echo "[info] Downloading FlutterCrafters Live Pro installer..."

if command -v curl >/dev/null 2>&1; then
  curl -fsSL "$INSTALLER_URL" -o "$TMP_FILE"
elif command -v wget >/dev/null 2>&1; then
  wget -qO "$TMP_FILE" "$INSTALLER_URL"
else
  echo "[error] curl or wget is required to download the installer." >&2
  exit 1
fi

echo "[info] Starting installer..."
php "$TMP_FILE" "$@"
