I have been working on setting up uci-defaults scripts with my custom images (created with the imagebuilder), so that if something happens and I have to fully wipe my router, I can get partially restored automatically.
I've run into a somewhat odd issue, where one very simple script seems to break quite a bit, even if I'm just loading a new image, and preserving the existing settings. When I add this script, the router seems to boot up fine, and I can see its WiFi network (since that setting is being restored from the previous load), but I don't have internet, and I can't even seem to connect to the routers internal LuCI web page, whether I'm connecting via ethernet or WiFi.
Here's the full script (which I have named 99-{SSID}-network, replacing {SSID} with the name of my WiFi network),:
# Set the routers address on LAN
uci set network.lan.ipaddr='10.0.0.1'
uci set network.lan.netmask='255.255.255.0'
# Disable ipv6 auto-start on boot
# Doing this since IPv6 seems really
# flakey on my network for some reason
# uci set network.wan6.auto='0'
# Enable packet steering so we can use both cores
# This lets me hit 500mbps
uci set network.globals.packet_steering='1'
exit 0
I'm really confused by the fact that this seems to be causing such a failure, as I already have the router configured to use that address and netmask (I actually copied the configuration settings right out of the "listed changes" menu in LuCI).
I originally had it with uci commit, but I thought that was not necessary for uci-defaults scripts.
I'll try the network restart logic (probably tomorrow), but seeing as this continues to happen even after I reboot the router, I'm not sure that's the issue either.
As pointed above, without the uci commit at the end, the script does exactly nothing.
You should, however, check if there's still anything in /etc/uci-defaults/ once the router is booted up. The presence of any script in that directory once booted up is an indication something did not run/complete normally (so exit 0 at the end may unintentionally mask any errors) on boot.
From my testing, presence of uci commit makes no difference (And the documentation seems to agree. Notice the example does not use uci commit: https://openwrt.org/docs/guide-developer/uci-defaults). I originally had it with that, and I tried removing it before I made the forum post.
I'll try removing the exit 0 this week and see what happens.
I have found the commit isn't always necessary, but I have also ran into cases (which i still can't explain) in which the settings would not retain without the commit. So now I always include it regaurdless, it will not produce any negative results and just may end up saving you hours of pointless debugging ... to each their own i guess.
this won't really tell you much, you need to check that your changes are applied before exiting with 0. If you just remove the exit 0, the script will just remain in uci-defaults rather than being removed ... which tells you absolutely nothing
I would suggest you use logger to find out what is going on and add a check before exiting 0.
# Set the routers address on LAN
uci set network.lan.ipaddr='10.0.0.1'
uci set network.lan.netmask='255.255.255.0'
# Disable ipv6 auto-start on boot
# Doing this since IPv6 seems really
# flakey on my network for some reason
# uci set network.wan6.auto='0'
# Enable packet steering so we can use both cores
# This lets me hit 500mbps
uci set network.globals.packet_steering='1'
uci commit network
lan_ip=$(uci get network.lan.ipaddr)
netmask=$(uci get network.lan.netmask)
logger "Updated Lan IP: $lan_ip"
logger "Updated Lan Netmask: $lan_mask"
if [ "$lan_ip" = "10.0.0.1" ]; then
exit 0
fi
The is a crude example but it demonstrates the principles of how to go about debugging default scripts.
note that logger will print your debug messages to syslog. you can view them via logread or in realtime with logread -f, in a second terminal while executing the script in the first terminal.
The docs you reference suggest something similar ...
we recommend you implement a test at the top of your script - e.g. probe for a custom setting your script would normally configure:
[ "$(uci -q get system.@system[0].zonename)" = "America/New York" ] && exit 0
This will make sure, when the key has the correct value set, that the script exits cleanly and gets removed from /etc/uci-defaults as explained above.