[Unit]
Description=CM4 eMMC provisioning (rpiboot + backup/deploy)
# Run after udev has settled; do not block boot
After=systemd-udevd.service
DefaultDependencies=yes

[Service]
Type=oneshot
# Delay so USB device is enumerated and udev permissions applied before we run
ExecStartPre=/bin/sleep 5
ExecStart=/opt/cm4-provisioning/flash-emmc-on-connect.sh
# Run as root; flash script logs to /var/lib/cm4-provisioning/flash.log
User=root
StandardOutput=journal
StandardError=journal
# Allow long run: rpiboot + wait for choice + dd 32GB (~20–35 min) + optional PiShrink (~15–30 min)
TimeoutStartSec=7200

[Install]
# Only started by udev trigger, not at boot
WantedBy=multi-user.target
