1
0

waouw-stage-init.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. set -e
  3. exec >/boot/waouw-stage-init.log 2>&1
  4. echo "== waouw-stage-init (PID1) start: $(date) =="
  5. # Determine source boot dir
  6. SRC_BOOT="/boot"
  7. if [ -d "/boot/firmware" ] && [ -f "/boot/firmware/waouw-firstboot.service" ]; then
  8. SRC_BOOT="/boot/firmware"
  9. fi
  10. echo "Using SRC_BOOT=$SRC_BOOT"
  11. # Deploy service and scripts into systemd
  12. mkdir -p /etc/systemd/system /etc/systemd/system/multi-user.target.wants
  13. cp "$SRC_BOOT/waouw-firstboot.service" /etc/systemd/system/waouw-firstboot.service
  14. chmod 0644 /etc/systemd/system/waouw-firstboot.service
  15. INSTALL_SCRIPT="$SRC_BOOT/waouw-install.sh"
  16. chmod +x "$INSTALL_SCRIPT" 2>/dev/null || true
  17. # Enable service via symlink (systemctl not available yet)
  18. ln -sf /etc/systemd/system/waouw-firstboot.service \
  19. /etc/systemd/system/multi-user.target.wants/waouw-firstboot.service
  20. ## Keep it minimal: no mounts, no apt here; firstboot service will handle install
  21. echo "Cleaning cmdline to avoid re-running on next boot"
  22. # Try to clean from either /boot or /boot/firmware
  23. for BOOTDIR in /boot /boot/firmware; do
  24. if [ -f "$BOOTDIR/cmdline.txt" ]; then
  25. # Remove our flags safely (match with a leading space)
  26. sed -i \
  27. -e 's| systemd.run=[^ ]*||g' \
  28. -e 's| systemd.run_success_action=[^ ]*||g' \
  29. -e 's| systemd.unit=[^ ]*||g' \
  30. "$BOOTDIR/cmdline.txt" || true
  31. echo "cmdline cleaned in $BOOTDIR"
  32. echo "ok" > "$BOOTDIR/waouw-stage-init.ok" || true
  33. fi
  34. done
  35. sync
  36. echo "Stage-init complete; letting success_action=reboot take over"
  37. sync
  38. sleep 1
  39. exit 0