Sets up NUT from scratch for a USB UPS and serves it to a Synology, which is
otherwise fiddly because DSM's client cannot be configured: it always asks for
a UPS named "ups" and always logs in as monuser with the password "secret".
The script guarantees all three, plus a reachable LISTEN.
Detects the UPS with nut-scanner, writes nut.conf, ups.conf, upsd.conf,
upsd.users and upsmon.conf, then starts and verifies the stack.
Re-runnable: it reuses an existing admin password rather than churning it,
backs up anything it replaces, and prompts before overwriting unless given
--yes. --dry-run prints the files without writing, and --etc-dir writes
elsewhere so the output can be reviewed against a live config.
Warns when another process already holds the USB device, naming QEMU
specifically. That is what broke this host: a passthrough to a guest claimed
the UPS, and the driver crash-looped for months with a message that did not
point at the cause.
Drops nut-scanner's bus, device and busport keys, which change across replug,
and its ###NOTMATCHED-YET### markers.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>