firstrun.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. set -eux
  3. exec >/boot/firstrun.log 2>&1
  4. date
  5. # 1) SSH + utilisateur pi (hash déjà connu)
  6. if [ -x /usr/lib/userconf-pi/userconf ]; then
  7. /usr/lib/userconf-pi/userconf 'pi' '$5$VOr2jdaVXo$nZI1v259hiMq0IM0KpPu8pDI/Zu08Yh5/ZQEOrHTP11' || true
  8. if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
  9. /usr/lib/raspberrypi-sys-mods/imager_custom enable_ssh || true
  10. else
  11. systemctl enable ssh || true
  12. fi
  13. else
  14. FIRSTUSER="$(getent passwd 1000 | cut -d: -f1 || echo pi)"
  15. echo "$FIRSTUSER:"'$5$VOr2jdaVXo$nZI1v259hiMq0IM0KpPu8pDI/Zu08Yh5/ZQEOrHTP11' | chpasswd -e || true
  16. [ "$FIRSTUSER" = "pi" ] || {
  17. usermod -l pi "$FIRSTUSER" || true
  18. usermod -m -d /home/pi pi || true
  19. groupmod -n pi "$FIRSTUSER" || true
  20. }
  21. systemctl enable ssh || true
  22. fi
  23. # 2) Locale/clavier/fuseau (best-effort, sans bloquer)
  24. if command -v raspi-config >/dev/null 2>&1; then
  25. raspi-config nonint do_change_locale fr_FR.UTF-8 || true
  26. raspi-config nonint do_configure_keyboard fr || true
  27. raspi-config nonint do_change_timezone Europe/Paris || true
  28. fi
  29. # 3) Préparer /home/pi/install-waouw + y déposer le zip
  30. inst=/home/pi/install-waouw
  31. mkdir -p "$inst"
  32. chown -R pi:pi "$inst" || true
  33. if [ -f /boot/waouw-deploy.zip ]; then
  34. mv -f /boot/waouw-deploy.zip "$inst/" || cp -f /boot/waouw-deploy.zip "$inst/"
  35. chown pi:pi "$inst/waouw-deploy.zip" || true
  36. if command -v unzip >/dev/null 2>&1; then
  37. (cd "$inst" && unzip -o waouw-deploy.zip) || true
  38. fi
  39. fi
  40. # 4) Installer/activer le service one-shot
  41. cat >/etc/systemd/system/check-waouwinit.service <<'EOF'
  42. [Unit]
  43. Description=Vérifie /boot/.waouwinit puis lance init_host.sh (une seule fois)
  44. After=network-online.target
  45. Wants=network-online.target
  46. [Service]
  47. Type=oneshot
  48. ExecStart=/bin/bash -lc 'if [ ! -f /boot/.waouwinit ] && [ ! -f /boot/firmware/.waouwinit ]; then INIT=$(find /home/pi/install-waouw -maxdepth 5 -name "init_host.sh" -type f 2>/dev/null | head -1); [ -n "$INIT" ] && [ -x "$INIT" ] && /bin/bash "$INIT"; fi'
  49. RemainAfterExit=yes
  50. [Install]
  51. WantedBy=multi-user.target
  52. EOF
  53. systemctl daemon-reload
  54. systemctl enable check-waouwinit.service || true
  55. # 5) Nettoyage cmdline pour ne PAS reboucler sur firstrun
  56. for f in /boot/cmdline.txt /boot/firmware/cmdline.txt; do
  57. [ -f "$f" ] && sed -i 's| systemd.run[^ ]*||g;s| systemd.run_success_action[^ ]*||g;s| systemd.unit[^ ]*||g' "$f" || true
  58. done
  59. rm -f /boot/firstrun.sh
  60. touch /boot/FIRSTRUN_DONE
  61. exit 0