I am tired of sitting for hours to make manual configurations every time I install a new OpenWRT (keeping settings doesn't work, in fact not even the password works so I can't even log in to the router after the update).
So I have now during the Christmas vacation made a big UCI compatible config file and I have run every line one by one so I know it is working.
Then the moment came to make some system to bulk install the config file in the UCI system. https://openwrt.org/docs/guide-user/base-system/uci almost down at the bottom there are the headline 'UCI defaults'. Yesterday I tried some small amount of the config code with this method and it wrote the actual code about 30% of the times and removed the *.sh file about 60% of the times. But the big problem is that every time the code actually written it was always corrupt in the same way.
I tried again today but now with the exact example as in the UCI instruction:
uci set network.lan.ipaddr='192.168.178.1'
uci commit network
Rebooted the router and the file was read and deleted, so good everything was fine.
Run in the serial console: “uci show network” and this is what the “UCI defaults” system had written:
Actually, the same result as last night. The '-symbol that should be written after the IP address is always placed in the front of the whole line (or sometimes yesterday as a completely new line after the line that was changed) and the "n" in network is removed. I can promise it didn't help to restart the router!
It does this fault every single time for every config line I want to automatically write to the UCI system.
How can I bulk install my UCI config file and trust the result?
Or else I must copy paste every single line because this problem never appears when doing it by manual labor.
uci batch << EOF
If I don't use script at all and only run the text as a batch command install instead. Everything seems to be written ok in the config files every time.
Are you sure you don't have any funny characters lingering in your script? Nothing weird showing when you open it in Vim or enable 'show special characters' in a graphical text editor?
There is no network configuration file /etc/config/network in the ROM of a fresh install. If an existing configuration was not copied into the overlay by a "save settings" sysupgrade, a new file is built during the first run(1) by another script. There could be a race between the two processes both modifying the same configuration, with uncertain results.
- This script is always present (it doesn't delete itself after first boot) and will check during every reboot to see if /etc/config/network exists, and rebuilt it if it does not.
I made the *.sh file in notepad and that is exactly the same as Vim. But just to be sure I looked at it in Word and there is nothing there. I actually tried last night to put a space at every line end before the enter in case that was the problem, without any luck.
But I copied the text right from the UCI instruction site so in that case the instruction would be at fault also.
I don’t run the script at install, I installed the OpenWRT so it works and then rewrite all the configs so the whole network work (just as the UCI manual specifies.
To set some system defaults the first time the device boots, create a script in the folder /etc/uci-defaults/.
All scripts in that folder are automatically executed by /etc/init.d/boot and if they exited with code 0 deleted afterwards (scripts that did not exit with code 0 are not deleted and will be re-executed during the next boot until they also successfully exit).
In a live router you can see the existing uci-defaults scripts in /rom/etc/uci-defaults , as /etc/uci-defaults itself is typically empty (after all scripts have been run ok and have been deleted).
Windows and UN*X have different line endings, which often leads to very 'funny' results.
Unix line end.
Windows line end.
Wow, every day is a possibility to learn something new
Made some "Duck Duck Go:ing" (the same as googling) on this thing with line ending. And found a Windows program called Notepad++ that can show this and also convert between the two standards.
Tried the script again with Unix line ends and now it works every time!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.