#!/bin/bash # WaouW v2.0 - Démarrage 100% Automatique # Ce script s'exécute au boot et gère tout automatiquement LOG_FILE="/var/log/waouw-startup.log" exec > >(tee -a "$LOG_FILE") 2>&1 echo "=== WaouW v2.0 - Démarrage Automatique $(date) ===" # Fonction de logging log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" } # Attendre que le système soit prêt log "Attente initialisation système..." sleep 30 # Installer Docker si nécessaire if ! command -v docker &> /dev/null; then log "Installation de Docker..." if curl -fsSL https://get.docker.com | sh; then log "Docker installé avec succès" systemctl enable docker systemctl start docker sleep 5 else log "ERREUR: Échec installation Docker" exit 1 fi fi # Aller dans le répertoire de déploiement cd /opt/waouw/DEPLOY || { log "ERREUR: Répertoire /opt/waouw/DEPLOY introuvable" exit 1 } # Fonction de correction automatique auto_fix() { log "Application des corrections automatiques..." # 1. Corriger docker-compose vs docker compose if grep -q "docker-compose" auto-install.sh; then sed -i 's/docker-compose/docker compose/g' auto-install.sh log "Correction Docker Compose appliquée" fi # 2. Corriger les noms de services sed -i 's/waouw-backend/backend/g' auto-install.sh 2>/dev/null || true sed -i 's/waouw-ui/frontend/g' auto-install.sh 2>/dev/null || true # 3. Corriger Redis version conflict if [ -f "../BACKEND/requirements.txt" ]; then sed -i 's/redis==5.0.1/redis==4.5.4/' ../BACKEND/requirements.txt 2>/dev/null || true log "Version Redis corrigée" fi # 4. S'assurer que .env existe if [ ! -f "../.env" ]; then log "Création du fichier .env manquant..." cat > ../.env << 'EOF' WAOUW_DOMAIN=waouw.local ACME_EMAIL=ssl-agent@waouw.tech POSTGRES_PASSWORD=waouw123 DATABASE_URL=postgresql://waouw:waouw123@postgres:5432/waouw JWT_SECRET_KEY=auto-secret-key-2024 DEVICE_HMAC_SECRET=auto-device-secret-2024 REDIS_URL=redis://redis:6379/0 TZ=Europe/Paris EOF fi # 5. Corriger la configuration frontend pour accès direct if grep -q "7165:80" docker-compose.yml; then log "Correction configuration frontend pour accès direct..." sed -i '/ports:/,/7165:80/d' docker-compose.yml log "Configuration frontend corrigée" fi # 6. Vérifier la configuration Traefik if [ ! -d "/etc/waouw/traefik" ]; then mkdir -p /etc/waouw/traefik cat > /etc/waouw/traefik/traefik.yml << 'EOF' global: checkNewVersion: false sendAnonymousUsage: false log: level: INFO api: dashboard: true insecure: true entryPoints: web: address: ":80" websecure: address: ":443" providers: docker: endpoint: "unix:///var/run/docker.sock" exposedByDefault: false network: waouw_traefik file: directory: /config watch: true certificatesResolvers: letsencrypt: acme: email: admin@waouw.local storage: /certificates/acme.json httpChallenge: entryPoint: web EOF log "Configuration Traefik créée" fi } # Fonction de démarrage des services start_services() { log "Démarrage des services..." # PostgreSQL en premier log "Démarrage PostgreSQL..." docker compose up -d postgres sleep 15 # Redis log "Démarrage Redis..." docker compose up -d redis sleep 10 # Traefik log "Démarrage Traefik..." docker compose up -d traefik sleep 10 # Attendre que Traefik soit prêt # Backend log "Démarrage Backend..." docker compose up -d backend sleep 10 } # Fonction de vérification verify_services() { log "Vérification des services..." # Attendre que tout soit stable sleep 30 # Vérifier PostgreSQL if docker exec waouw_postgres pg_isready -U waouw >/dev/null 2>&1; then log "✅ PostgreSQL opérationnel" else log "❌ PostgreSQL problème" fi # Vérifier Redis if docker exec waouw_redis redis-cli ping | grep -q PONG; then log "✅ Redis opérationnel" else log "❌ Redis problème" fi # Vérifier Backend if curl -s http://localhost:8000/health >/dev/null 2>&1; then log "✅ Backend opérationnel" else log "❌ Backend problème" fi # Vérifier Traefik if curl -s -I http://localhost >/dev/null 2>&1; then log "✅ Traefik opérationnel" else log "❌ Traefik problème" fi # Test d'accès direct sur l'IP IP=$(hostname -I | awk '{print $1}') if curl -s --max-time 5 "http://$IP" >/dev/null 2>&1; then log "✅ Accès direct sur IP opérationnel: http://$IP" else log "❌ Accès direct sur IP problème" fi } # Fonction de feedback provide_feedback() { log "=== RAPPORT FINAL ===" log "WaouW v2.0 Status:" # État des conteneurs log "Conteneurs actifs:" docker ps --format "table {{.Names}}\t{{.Status}}" | while read line; do log " $line" done # Adresses d'accès IP=$(hostname -I | awk '{print $1}') log "" log "🌐 ACCÈS WAOUW:" log " Interface: http://$IP (accès direct)" log " Interface: http://waouw-pi.local (DNS)" log " API: http://$IP/api/health" log " API: http://waouw-pi.local/api/health" log " Login: admin / admin" # Informations système log "" log "📊 INFORMATIONS SYSTÈME:" log " IP: $(hostname -I | awk '{print $1}')" log " Utilisateur: waouw" log " Logs: /var/log/waouw-startup.log" log "" log "🎉 INSTALLATION TERMINÉE - WaouW v2.0 opérationnel !" } # Exécution principale main() { log "=== DÉMARRAGE WAOUW v2.0 ===" # Corrections automatiques auto_fix # Démarrage des services start_services # Vérifications verify_services # Feedback final provide_feedback log "=== FIN DU DÉMARRAGE AUTOMATIQUE ===" } # Lancer le processus automatique main