Getting mac address in uci-defaults script

I need to get a mac address in the uci-defaults script and I've tried:
. /usr/share/libubox/jshn.sh; json_load "$(/bin/ubus call network.device status)";
but I get a command failed message, even tho
json_load "$(/bin/ubus call system board)";
works just fine.

So for now I ended up just screen scraping ifconfig, but I'm wondering if there's a better option?

you tried writing source instead of the dot? Should do the same in bash and was suggested for similar uses in the LEDE wiki.

If it mattered, then the call to system board would have also failed. But even with the source instead of the dot, it still fails:

+ source /usr/share/libubox/jshn.sh
+ /bin/ubus call network.device status
Command failed: Not found

The uci-defaults script runs before netifd is started, so you cannot query the ubus network namespace at this point in time. If you know the device name you can use cat /sys/class/net/$dev/address which is somewhat cleaner than screen scraping ifconfig.

2 Likes

Thank you!