#!/bin/bash # /boot/waouw-activate.sh — Boot 1 (via cloud-init runcmd ou systemd.run) # But : créer l’utilisateur 'waouw' (bypass wizard), activer le service firstboot, puis reboot. set -eu BOOTDIR="/boot" [ -d "/boot/firmware" ] && BOOTDIR="/boot/firmware" LOGF="$BOOTDIR/waouw-activate.log" [ -f "$BOOTDIR/waouw-deploy-log.sh" ] && _WAOUW_SCRIPT="waouw-activate" . "$BOOTDIR/waouw-deploy-log.sh" _log() { waouw_deploy_log "INFO" "$@" 2>/dev/null || echo "[INFO] $*" | tee -a "$LOGF"; } _step() { waouw_deploy_step "$@" 2>/dev/null || echo "[STEP] $*" | tee -a "$LOGF"; } # Ne pas relancer si déjà exécuté (cloud-init peut re-exécuter runcmd) if [ -f "$BOOTDIR/waouw-activate.ok" ]; then _log "waouw-activate déjà exécuté, skip" exit 0 fi _log "waouw-activate démarré" { echo "=== $(date -u) ===" set -x # DNS fiable (le DNS de la box peut timeout sur les gros téléchargements) if ! grep -q '8.8.8.8' /etc/resolv.conf 2>/dev/null; then echo "nameserver 8.8.8.8" >> /etc/resolv.conf fi mkdir -p /etc/systemd/resolved.conf.d echo -e "[Resolve]\nDNS=8.8.8.8 8.8.4.4\nFallbackDNS=1.1.1.1" > /etc/systemd/resolved.conf.d/waouw-dns.conf systemctl restart systemd-resolved 2>/dev/null || true # 1) Crée l’utilisateur si absent (bypass wizard) if ! id -u waouw >/dev/null 2>&1; then # useradd (Debian) if command -v useradd >/dev/null 2>&1; then useradd -m -s /bin/bash waouw || true elif command -v adduser >/dev/null 2>&1; then adduser --disabled-password --gecos "" waouw || true fi # Mot de passe par défaut (à changer ensuite) echo 'waouw:waouw' | chpasswd || true # sudo et docker s’ils existent if getent group sudo >/dev/null 2>&1; then usermod -aG sudo waouw || true; fi if getent group docker >/dev/null 2>&1; then usermod -aG docker waouw || true; fi echo "waouw ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/waouw || true chmod 440 /etc/sudoers.d/waouw || true fi # 2) (Optionnel) expand FS si outil dispo if command -v raspi-config >/dev/null 2>&1; then raspi-config nonint do_expand_rootfs || true fi # 3) Déploie/active le service firstboot (boot 2) install -D -m 0644 "$BOOTDIR/waouw-firstboot.service" /etc/systemd/system/waouw-firstboot.service systemctl daemon-reload || true systemctl enable waouw-firstboot.service || true # 4) Fichier témoin echo "ok" >"$BOOTDIR/waouw-activate.ok" _step "activate-boot1" "ok" "Utilisateur waouw créé, firstboot activé" # 5) Nettoyer cmdline.txt si systemd.run= était utilisé (ancien mécanisme) if [ -f "$BOOTDIR/cmdline.txt" ] && grep -q 'systemd\.run=' "$BOOTDIR/cmdline.txt" 2>/dev/null; then sed -i \ -e 's| systemd.run=[^ ]*||g' \ -e 's| systemd.run_success_action=[^ ]*||g' \ -e 's| systemd.unit=[^ ]*||g' \ "$BOOTDIR/cmdline.txt" || true _log "cmdline.txt nettoyé (ancien mécanisme systemd.run)" fi set +x _log "Redémarrage..." } | tee -a "$LOGF" # Flush les écritures sur la partition boot (FAT32) avant reboot sync sleep 2 reboot