#!/bin/bash # WaouW init_host.sh — exécuté par firstrun.sh / check-waouwinit (flow SD alternative) # Installe les prérequis puis lance l'installation complète set -euo pipefail INST_DIR="${INST_DIR:-/home/pi/install-waouw}" DEST="/opt/waouw" BOOTDIR="/boot" [ -d "/boot/firmware" ] && BOOTDIR="/boot/firmware" mkdir -p /var/log/waouw-deploy LOG_SCRIPT="" [ -f "$(dirname "$0")/waouw-deploy-log.sh" ] && LOG_SCRIPT="$(dirname "$0")/waouw-deploy-log.sh" [ -z "$LOG_SCRIPT" ] && LOG_SCRIPT=$(find "$INST_DIR" -maxdepth 5 -name "waouw-deploy-log.sh" -type f 2>/dev/null | head -1) [ -n "$LOG_SCRIPT" ] && _WAOUW_SCRIPT="init_host" . "$LOG_SCRIPT" _log() { waouw_deploy_log "INFO" "$@" 2>/dev/null || echo "[WAOUW-INIT] $*"; } _step() { waouw_deploy_step "$@" 2>/dev/null || echo "[STEP] $*"; } _err() { waouw_deploy_error "$@" 2>/dev/null || echo "[ERROR] $*"; } exec > >(tee -a /var/log/waouw-deploy/waouw-deploy.log) 2>&1 _step "init_host" "running" "Démarrage" _log "init_host démarré $(date -u)" # 1) Prérequis OS _log "Installation des prérequis..." apt-get update -qq 2>/dev/null || true for p in curl wget jq unzip; do command -v $p >/dev/null 2>&1 || apt-get install -y $p done # 2) Localiser et extraire l'archive ZIP="$INST_DIR/waouw-deploy.zip" [ ! -f "$ZIP" ] && ZIP="$BOOTDIR/waouw-deploy.zip" [ ! -f "$ZIP" ] && ZIP="/boot/firmware/waouw-deploy.zip" if [ ! -f "$ZIP" ]; then _err "waouw-deploy.zip introuvable" exit 1 fi _step "init_host" "running" "Extraction archive" _log "Extraction de $ZIP vers $DEST" mkdir -p "$DEST" unzip -oq "$ZIP" -d "$DEST" # 3) Lancer install-complete.sh (structure zip selon build) INSTALLER="" INSTALLER=$(find "$DEST" -maxdepth 4 -name "install-complete.sh" -type f -executable 2>/dev/null | head -1) if [ -n "$INSTALLER" ]; then _step "init_host" "running" "Lancement install-complete.sh" bash "$INSTALLER" || { _err "install-complete.sh a échoué"; exit 1; } else _err "install-complete.sh introuvable" exit 2 fi # 4) Marquer succès _step "init_host" "ok" "Installation terminée avec succès" touch "$BOOTDIR/.waouwinit" echo "ok" >"$BOOTDIR/waouw-install-success.txt"