In the GitHUB post (above last linked one) uci set web. ... .roles was used and it worked (so no need for replace_list or set_list). Unfortunately it also wiped out any other settings for those roles in the modem, say the guest setting. That approach wasn't useful with 'web.ruleset_main.rules='.
As it is my script will add a new section but will not update it if it exists. (I don't think if ... fi blocks are reasonable on most lines.)
I'm interested in any workarounds without wrapping most lines in if ... fi (unless maybe as part of a subroutine). Is the -m option useful?
I still think default operation should be no duplicates.
UCI is cool but it blindly messes up config files. So you don't have to be a newbie to need Failsafe Mode after uci [via Luci] mashes up the network configs.
Indeed, being able to sort entries, have no more duplicate entries and roll back updates, would be killer features. But achieving these might require UCI complying with a higher data model/schema?
I agree, but then it should not be called add_list. As I said, if you want idempotent behavior, precede your add operation with a matching delete operation.
To be fair, some of the points raised are to improve the comparability of produced configurations and it makes sense to not require special tooling for diffing plaintext files.
It's probably niche stuff, not normal operation needed by every application, but I had to do that some times.
I've used my system to deal with modifying entries by name, or by the content of the entry itself, without knowing the node ID. Like "find the mount point /aaa/bb/cc and change its option to enabled in the config".
Doing the same with UCI alone is not really possible as I don't know the node number thing of the mount point I'm looking for beforehand.
And if I need to filter UCI output to find the node first I might as well do it all manually in the script anyway.
I've also used manual scripting for batch operations on multiple nodes where I don't know the node or name beforehand. Like changing all DNS servers on multiple interfaces at once, or things like that.
I mean it's just a sed to replace a string with another in a text file.
I think having a uci searchID "keyword" that returns the ID thing I should use to edit that entry would solve that.
Something like
# uci searchID "/aaa/bbb/ccc"
with output
# 0
if it is in fstab.@mount[0]
Or multiple numbers if it is in multiple places.
This way I can just do
for i in $( uci searchID xxx ) ; do
<uci command to do stuff>
done