PROCÉDURE DE DÉPLOIEMENT AUTOMATIQUE WAOUW SUR CARTE SD
=======================================================

OBJECTIF : Installer WaouW v2.0 COMPLETE automatiquement sur Raspberry Pi
         sans intervention manuelle sur le Pi (installation au premier boot)

PRÉREQUIS :
- Carte SD avec Raspberry Pi OS (partition boot accessible)
- Connexion Internet sur le Pi
- Windows avec 7-Zip installé

MISE À JOUR (scripts corrigés) :
=================================
Les scripts supportent désormais /boot et /boot/firmware.
Les prérequis (curl, wget, jq, unzip) sont installés au démarrage de waouw-install.sh.
init_host.sh disponible pour le flow firstrun (extraction dans /home/pi/install-waouw).
Système de log unifié : waouw-deploy.log et waouw-deploy-status.txt sur la partition boot.
→ Voir PROCEDURE-LOGS-DEPLOIEMENT.md pour suivre l'installation et diagnostiquer les erreurs.

ÉTAPES DE DÉPLOIEMENT :
=================================

1. CRÉER L'IMAGE DE DÉPLOIEMENT
   -----------------------------
   Depuis la racine du projet WaouW :
   ```
   build-windows.bat
   ```
   → Génère : dist/waouw-v2-image-latest.zip
   → Contient : BACKEND, DEPLOY, DEVICE_AGENT, docs, etc.

2. CONFIGURER L'AUTO-INSTALLATION SUR LA SD
   -----------------------------------------
   Depuis le dossier DEPLOY :
   ```
   setup-autoinstall.bat
   ```
   → Détecte automatiquement la carte SD
   → Copie waouw-v2-image-latest.zip → waouw-deploy.zip sur la SD
   → Copie firstrun.sh sur la SD
   → Crée WAOUW-README.txt avec instructions

3. QUAND PRÉPARER LA SD
   --------------------
   Préparation AVANT le premier boot du Raspberry Pi. L'expansion du système
   (firstboot) se fait au premier démarrage et n'affecte pas la partition boot.
   Si cmdline.txt est absent (Raspberry Pi OS Lite récent), config.txt suffit
   pour la détection. Lancez ensuite install.sh manuellement via SSH.

4. INSTALLATION AUTOMATIQUE
   -------------------------
   - Insérer la SD dans le Raspberry Pi
   - Démarrer le Pi (avec connexion Internet)
   - Attendre 20-40 minutes
   → L'installation se fait ENTIÈREMENT automatiquement !

DÉTAILS TECHNIQUES :
===================

Scripts impliqués :
- build-windows.bat : Crée l'archive de déploiement
- setup-autoinstall.bat : Configure la SD
- firstrun.sh : Script d'auto-installation (s'exécute au premier boot)
- install-complete.sh : Installation complète des services

Fichiers sur la SD après configuration :
- waouw-deploy.zip : Archive complète WaouW
- firstrun.sh : Script d'auto-installation
- WAOUW-README.txt : Instructions
- cmdline.txt OU /boot/firmware/cmdline.txt : Configuration boot

Fichiers de statut créés après installation :
- waouw-install-success.txt : Installation réussie
- waouw-install-error.txt : Erreur d'installation

PROBLÈME ACTUEL À RÉSOUDRE :
============================

Les scripts configure-autoboot.bat et fix-firstrun-path.bat ne fonctionnent pas
sur les nouvelles versions de Raspberry Pi OS car ils cherchent /boot/cmdline.txt
alors que le fichier est maintenant dans /boot/firmware/cmdline.txt

SOLUTION TEMPORAIRE :
====================

1. Vérifier la structure de la SD :
   - /boot/cmdline.txt (ancienne version)
   - /boot/firmware/cmdline.txt (nouvelle version)

2. Modifier manuellement le bon fichier cmdline.txt :
   - Ajouter : systemd.run=/boot/firstrun.sh
   - Ou utiliser une méthode alternative d'auto-exécution

3. Alternative : Utiliser SSH pour lancer l'installation manuellement :
   ```bash
   ssh pi@[IP-PI]
   cd /opt/waouw/waouw-deploy
   ./install.sh
   ```

ACCÈS APRÈS INSTALLATION :
==========================

Interface web :
- https://IP-DU-PI ou https://waouw.local
- Finaliser l'onboarding avec les identifiants client waouw-admin
- Les identifiants admin locaux sont envoyés après validation du boîtier

Services inclus :
- Interface web complète (React + FastAPI)
- Serveur email (Postfix + Dovecot + Roundcube)
- Cloud personnel (Nextcloud)
- Sécurité (Fail2ban + OpenVPN + Firewall)
- Monitoring (Grafana + Graylog + Prometheus)
- Administration (Webmin + phpMyAdmin)

VÉRIFICATION :
=============

1. Après installation, remettre la SD dans Windows
2. Vérifier la présence de waouw-install-success.txt
3. Ou tester https://waouw.local depuis un navigateur

AVANTAGES DE CETTE MÉTHODE :
===========================

✅ Installation 100% automatique (quand ça fonctionne)
✅ Aucune intervention manuelle sur le Pi
✅ Configuration réseau automatique (waouw.local)
✅ Récupération d'erreur avec logs détaillés
✅ Package complet et autonome

NOTES IMPORTANTES :
==================

- Le Pi doit avoir une connexion Internet pour l'installation
- L'installation prend 20-40 minutes selon la connexion
- Toujours changer le mot de passe admin après installation
- Les logs sont disponibles dans /var/log/waouw-*.log
- PROBLÈME : Les scripts ne gèrent pas les nouvelles versions de Raspberry Pi OS

Version : WaouW v2.0 COMPLETE
Date : $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
STATUT : PROBLÈME IDENTIFIÉ - CORRECTION REQUISE
