Uci: ordering of config file?

In some projects (e.g. babeld) is important how sections are ordered. The arrangement represents at the end e.g. the passing through different rules.

Currently I'm doing this:

	uci add babeld filter
	uci set babeld.@filter[-1].type='redistribute'
	uci set babeld.@filter[-1].ip=$1
	uci set babeld.@filter[-1].local='true'
	uci set babeld.@filter[-1].action='deny'

This just appends to a config file and results that the rules never apply.

Is there another way?

If you don't use uci add you can just overwrite any currently existing filter using something like:

	uci set babeld.@filter["$n"].type='redistribute'
	uci set babeld.@filter["$n"].ip=$1
	uci set babeld.@filter["$n"].local='true'
	uci set babeld.@filter["$n"].action='deny'

You may also want to look at this: https://openwrt.org/docs/guide-developer/config-scripting

1 Like

Thanks a lot. I know that I can use set, but I want somehow to automatically add that to the front. Maybe I can extend rc.common or /lib/functions.sh.

Maybe you could contribute to the patch which would implement uci --insert add (a-la iptables -I option): use normal add, get n -- the number of matching sections, in the loop for i in n to 1 copy section options from [i-1] to [i] and delete options from [0].

Once you do uci --insert add, you can then write the new values to @filter[0].

UPDATE: Strike that, do what the post below says.

1 Like

Did you try uci reorder <config>.<section>=<position> ? Add a new config and move it to the top? Never tried it though.


Thanks for your help! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.