OpenWrt Forum Archive

Topic: Replace one specific config file on sysupgrade but keep the rest

The content of this topic has been archived on 4 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

Working on a project where I would like to retain the current configuration when I flash the router with a new firmware, except for a specific config file which I would like to replace. I know that it's possible to add files in sysupgrade.conf to preserve them. But are there a way to force specific config files to be replaced?

Kind regards,
TeamT

tmo26 wrote:

Custom files seems to be what you are searching for:
https://wiki.openwrt.org/doc/howto/build#custom_files

Thanks, but I am using Custom files heavily. I want to preserve the users settings by the "Keep settings" check box in LuCI except when I am, due to design, need to replace a specific config file. I am look for a way to override the "Keep settings" option for a specific config file.

The "Keep settings" function overrides any Custom files provided in the upgrade.

E.g. I would like to provide a new crontab file in the upgrade but avoid that the user would need to redo all other settings.

(Last edited by TeamT on 27 Nov 2017, 00:06)

Surprisingly few people know that you can pass a tar.gz archive to sysupgrade containing files you want to keep (or, for that matter, any files you want to be there after the sysupgrade, they can be anywhere in the file system).

See the -f <config> option to submit that tar.gz archive to sysupgrade. If you want an example for that archive, run sysupgrade -b <file>. It may be easier to have a full backup archive generated and just remove the files you don't want to keep.

(Last edited by metai on 28 Nov 2017, 11:45)

Upon re-reading about your situation, I'm not sure the above would really help you since the user would have to manually supply the archive and add that parameter to sysupgrade on the command line.

Pragmatically speaking, what I can think of is a combination of two custom files in the image: one that contains the configuration in a different file/archive, and a small init script that copies/moves/extracts it to their intended location upon first boot (Edit: in /etc/uci-defaults, as hnyman describes below).

(Last edited by metai on 28 Nov 2017, 17:58)

TeamT wrote:

Working on a project where I would like to retain the current configuration when I flash the router with a new firmware, except for a specific config file which I would like to replace. I know that it's possible to add files in sysupgrade.conf to preserve them. But are there a way to force specific config files to be replaced?

1)
Use a uci-defaults script file that removes / replaces the one specific file (at the first boot after the flash).

So,
sysupgrade would preserve also the one unwanted file, but you would remove/overwrite it via a script at the first boot.
The uci-defaults script itself gets deleted after running once, so there is no remnants left for possible subsequent reboots.

https://wiki.openwrt.org/doc/uci#uci-defaults

2)
second option is that you manually replace the one config file just before the sysupgrade, so that the new file gets included in the sysupgrade archive.

(Last edited by hnyman on 28 Nov 2017, 11:54)

hnyman wrote:
TeamT wrote:

Working on a project where I would like to retain the current configuration when I flash the router with a new firmware, except for a specific config file which I would like to replace. I know that it's possible to add files in sysupgrade.conf to preserve them. But are there a way to force specific config files to be replaced?

1)
Use a uci-defaults script file that removes / replaces the one specific file (at the first boot after the flash).

So,
sysupgrade would preserve also the one unwanted file, but you would remove/overwrite it via a script at the first boot.
The uci-defaults script itself gets deleted after running once, so there is no remnants left for possible subsequent reboots.

https://wiki.openwrt.org/doc/uci#uci-defaults

2)
second option is that you manually replace the one config file just before the sysupgrade, so that the new file gets included in the sysupgrade archive.

Thank you!

Option 1 - uci-defaults script was what I was looking for.

/ TeamT

The discussion might have continued from here.