#!/bin/bash # ============================================================================== # ACTION REPLAY - CLIENT DOWNLOADER (In-Folder Edition) # ============================================================================== set -e VPS_HOST="actionreplay.mekadata.fr" AR_SCHEME="${AR_SCHEME:-https}" AR_BASE="${AR_SCHEME}://${VPS_HOST}" echo "================================================" echo " 🎮 ACTION REPLAY - INSTALLATION " echo "================================================" # 0. Mot de passe porte d'entrée → token 5 min if [ -z "${DOWNLOADER_PWD:-}" ] && [ -n "${AR_BOOT_PASS:-}" ]; then DOWNLOADER_PWD="$AR_BOOT_PASS" fi if [ -z "${DOWNLOADER_PWD:-}" ]; then printf "🔑 Mot de passe installateur : " # -s si TTY if [ -t 0 ]; then stty -echo 2>/dev/null || true read -r DOWNLOADER_PWD < /dev/tty stty echo 2>/dev/null || true echo else # Prefer /dev/tty even under curl|bash so prompt works when possible if [ -r /dev/tty ]; then stty -echo < /dev/tty 2>/dev/null || true read -r DOWNLOADER_PWD < /dev/tty stty echo < /dev/tty 2>/dev/null || true echo else read -r DOWNLOADER_PWD fi fi fi if [ -z "${DOWNLOADER_PWD:-}" ]; then echo "❌ Mot de passe requis (saisie interactive)." exit 1 fi echo "🔐 Demande de token downloader..." DL_JSON=$(curl -sSf --connect-timeout 8 \ -X POST "${AR_BASE}/api/v1/downloader-pwd" \ -H "Content-Type: application/json" \ -d "{\"password\":\"${DOWNLOADER_PWD}\"}") || { echo "⛔ Mot de passe refusé ou VPS injoignable." exit 1 } DL_TOKEN=$(printf '%s' "$DL_JSON" | sed -n 's/.*"token"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') if [ -z "$DL_TOKEN" ]; then echo "⛔ Réponse downloader-pwd invalide." exit 1 fi AR_Q="token=${DL_TOKEN}" echo "✅ Token obtenu (valable ~5 min)." # 1. Scan et sélection interactive de la cartouche AVAILABLE_CARTS=($(curl -sSf --connect-timeout 2 --max-time 3 "${AR_BASE}/cartridges/?${AR_Q}" 2>/dev/null | grep -o 'href="[^"/]*/"' | sed 's/href="//;s/\/"//' | grep -v '^\.\.' || true)) if [ ${#AVAILABLE_CARTS[@]} -eq 0 ]; then AVAILABLE_CARTS=("true-lies") fi echo "📦 Cartouches disponibles :" select CART_NAME in "${AVAILABLE_CARTS[@]}"; do if [ -n "$CART_NAME" ]; then break; fi echo "Choix invalide." done < /dev/tty echo "" echo "⚙️ Choix de l'environnement pour [$CART_NAME] :" select TARGET_ENV in "DEV" "TEST" "PROD"; do case $TARGET_ENV in DEV|TEST|PROD) break ;; *) echo "Choix invalide." ;; esac done < /dev/tty # 2. Contrôle de cohérence avec le répertoire d'exécution TARGET_ENV_LOWER=$(echo "$TARGET_ENV" | tr '[:upper:]' '[:lower:]') EXPECTED_DIR="${CART_NAME}-${TARGET_ENV_LOWER}" CURRENT_DIR=$(basename "$PWD") if [ "$CURRENT_DIR" != "$EXPECTED_DIR" ]; then echo "" echo "❌ [ERREUR] Emplacement invalide." echo "👉 Cartouche choisie : $CART_NAME" echo "👉 Environnement choisi : $TARGET_ENV" echo "👉 Dossier attendu : $EXPECTED_DIR" echo "👉 Dossier actuel : $CURRENT_DIR" echo "👉 Place-toi directement dans le dossier cible : cd ~/docker/nes/$EXPECTED_DIR" echo "" exit 1 fi echo "================================================" echo "📦 Cartouche : $CART_NAME" echo "⚙️ Environnement : $TARGET_ENV" echo "📂 Dossier : $PWD" echo "================================================" # 3. Client bootstrap (HWID only) — le binaire runtime reste celui de la cartouche scellée echo "⬇️ Téléchargement du client (bootstrap HWID)..." curl -sSf --connect-timeout 5 "${AR_BASE}/client?${AR_Q}" -o ./client.hwid chmod +x ./client.hwid # 4. Calcul HWID via le binaire officiel HWID=$(./client.hwid hwid "$CART_NAME" "$TARGET_ENV" "$PWD") # 5. Handshake d'autorisation (HWID_guard.go) echo "🔐 Vérification des droits auprès du Control Plane..." AUTH_URL="${AR_BASE}/api/v1/auth/verify?hwid=${HWID}&cartridge=${CART_NAME}&env=${TARGET_ENV}&actor=downloader" HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 "$AUTH_URL" || echo "000") if [ "$HTTP_STATUS" != "200" ]; then rm -f ./client.hwid echo "" echo "⛔ ACCÈS REFUSÉ : Instance non autorisée ou révoquée (Code HTTP: $HTTP_STATUS)." echo "👉 HWID calculé : $HWID" echo "👉 Veuillez contacter le support Fluyde." echo "" exit 1 fi echo "✅ Autorisation validée par le Control Plane." rm -f ./client.hwid # 6. Déploiement de la cartouche (client scellé inclus — ne pas écraser) echo "📦 Téléchargement de l'archive [$CART_NAME]..." curl -sSf --connect-timeout 5 "${AR_BASE}/cartridges/${CART_NAME}/${CART_NAME}.tar.gz?${AR_Q}" | tar -xz --no-same-owner if [ ! -x console/sidecars/client/client ]; then echo "❌ Client scellé absent dans la cartouche." exit 1 fi chmod +x console/deploy/*.sh game/etl_custom/*.sh console/build/*.sh 2>/dev/null || true # 7. Lancement de l'installation echo "🚀 Lancement de l'instance ($TARGET_ENV)..." ./console/deploy/install.sh