When uci is used with ubus, how to specify path for config file

I want to save my config files in another location instead of /etc/config. Lets say, I am saving a config called test_network in /etc/test_config/, then the following command works for me and gets me the required ifname

uci -c /etc/test_config/ get test_network.test_lan.ifname

However I am unable to do the same when combining uci with ubus. For example the following command does not work for me:

/bin/ubus -S call uci -c /etc/test_config/ get '{"config":"test_network", "section":"test_lan", "option":"ifname"}'

Is there a way I can specify the path for my config files in the ubus command ?

I believe that you can set $UCI_CONFIG_DIR to accomplish this.

Not tested, but I think it looks like this for just the one liner:

UCI_CONFIG_DIR=/etc/test_config/ ubus -S call uci get ...

or this for "permanent" redirection:

export UCI_CONFIG_DIR=/etc/test_config/
ubus -S call uci get ...

Take a look in /lib/config/uci.sh for some hints...

1 Like

I tried both ways, neither of them are working. Any more suggestions would be highly appreciated

Looking at this:

indicates that there's a way to specify the path in the config part of the get, and indeed some experimenting shows it works!

$ uci get network.lan.device
$ uci get /etc/config/network.lan.device

$ uci get /etc/fred/network.lan.device
uci: Entry not found

$ mkdir /etc/fred
$ cp /etc/config/network /etc/fred

$ uci get /etc/fred/network.lan.device

But when we try to pass that through ubus call...

$ ubus call uci get '{"config":"network", "section":"lan", "option":"device"}'
        "value": "br-lan"

$ ubus call uci get '{"config":"/etc/config/network", "section":"lan", "option":"device"}'
$ ubus call uci get '{"config":"/etc/fred/network", "section":"lan", "option":"device"}'

$ ubus call uci get '{"config":"/etc/bork/network", "section":"lan", "option":"device"}'
Command failed: Not found

So, I don't know what to say here.

1 Like

Yeah, the environment variable route was a failed side quest. My hopes were that ubus used the helper scripts, but it appears that it makes direct calls to libuci for this info, where the environment is not used, so another mechanism is required.

1 Like