Deleting array-like openwrt uci config sections
https://github.com/Mic92/dotfiles/blob/05c0dbc5ba882fbe4d51cffe6e124cdfcd924983/openwrt/nix_uci/init.py#L109
If you rely solely on uci batch commands, it's not possible to do. If you make use of some form of on-device scripting, it's trivial, and this is what both OpenWRT's documentation and scripts do currently. For example, deleting all existing network devices with ash:
while uci -q del network.@device[-1] 2>/dev/null; do :; done
There shouldn't really be much of an issue interspersing uci batch commands and segments of shell script; so long as you don't uci commit the changes until everything is done, any failure in the script won't be persisted and could be trivially reverted.
As a possibly more interesting alternative, ucode is now on every OpenWRT image from 22.03 and on, so you could directly ship the uci.json onto the router, along with a ucode script to parse & act on it directly on the target.
ucode sounds nice. Thank you. I check it out.