ImageBuilder: How to preserve a config file when settings are not saved

My writings below are are based on this statement: DSA change advising to not keep settings, but no need for factory image (like with kernel size changes).

No, the sysupgrade process is based on files of the router, not in the image contents.

Regarding stangri's proposal:
I have done that kind of device id sniffing and config scripting some 11 years ago for WiFi config, base on MAC addresses read from flash art partition (Macs, WiFi calib data etc.. The parition name varies)
Example in Best way to automate OpenWrt configuration - #14 by hnyman

But other angle for you:

DSA change usually only invalidates /etc/config/network and /etc/config/system (LED definitions).

At least with mvebu wrt3200acm I was able just go back and forth over the DSA change barrier by deleting the network and system config files, replacing them with the DSA/non-DSA corrected version, and then sysupgrading with setting kept. (If the system and network files are missing at first boot, the system creates the with defaults.)

From that perspective, ideas for you.

  • Make script that removes or modifies the network and system config files for DSA, run that before sysupgrade and then sysupgrade with settings.
  • If you have a uci-defaults script that modifies all else, make a script that modifies the "kept files" list in the router so that everything else is removed for the list but only wireless is left to be kept. Then after running that before sysupgrade, you could sysupgrade "with settings" (=only wireless) and everything else would be created by your already existing config script. (But note that the keep list is not only /etc/sysupgrade.conf as there are other sources for info).

The possible scenarios depend a bit on whois doing the sysupgrade, and they follow additional instructions.

EDIT:
In case you go to the "keep wireless, drop other config" strategy, here are some hints for you regarding the rules which files are kept. the /etc/sysupgrade.conf is meant as additional user stuff, while the main system ruels are in /lib/upgrade/keep.d/. Already removing the /etc/config related lines from /lib/upgrade/keep.d/base-files would help you a lot:

root@router1:/etc# ls /lib/upgrade/keep.d/
base-files            collectd              luci-base             ppp
base-files-essential  dnsmasq               netifd                uboot-envtools
block-mount           firewall4             odhcp6c               uhttpd
busybox               libopenssl-conf       opkg                  unetd

root@router1:/etc# cat /lib/upgrade/keep.d/*
/etc/config/
/etc/config/network
/etc/config/system
/etc/dropbear/
/etc/profile.d
# Essential files that will be always kept
/etc/hosts
/etc/inittab
/etc/group
/etc/passwd
/etc/profile
/etc/shadow
/etc/shells
/etc/shinit
/etc/sysctl.conf
/etc/rc.local
/etc/config/fstab
/etc/crontabs/
/etc/collectd.conf
/etc/dnsmasq.d/
/etc/nftables.d/
/etc/ssl/engines.cnf.d/devcrypto.cnf
/etc/ssl/engines.cnf.d/padlock.cnf
/etc/luci-uploads
/etc/udhcpc.user.d/
/etc/odhcp6c.user.d/
/etc/opkg/keys/
/etc/ppp/ip-down
/etc/ppp/ip-up
/etc/ppp/ipv6-down
/etc/ppp/ipv6-up
/etc/config/ubootenv
/etc/fw_env.config
/etc/fw_sys.config
/etc/uhttpd.crt
/etc/uhttpd.key
/etc/unetd

root@router1:/etc# cat /lib/upgrade/keep.d/base-files
/etc/config/
/etc/config/network
/etc/config/system
/etc/dropbear/
/etc/profile.d
3 Likes