[RFC PATCH 2/2] base-files: sysupgrade: fine-tune preserved files during upgrade

Adrian Schmutzler freifunk at adrianschmutzler.de
Fri Jul 10 06:47:50 EDT 2020


For some downstream projects it is desirable not to keep the whole
set of configuration files, but to have most of them reset during
upgrade (and reconfigured afterwards) and just keep a small subset
in /etc/sysupgrade.conf.

With this patch, the subset of files kept during upgrade is made
configurable, while default setup remains untouched:

By setting the appropriate variables or providing command line
options, one can now selectively disable keeping ...

... the files in /lib/upgrade/keep.d/* by
    setting SAVE_CONFIG_KEEPD=0 or providing --no-keepd

... the files managed by opkg accessible via /usr/lib/opkg/status by
    setting SAVE_CONFIG_OPKG=0 or providing --no-opkg

If a file is listed in multiple locations, it is kept until it is
"disabled" everywhere.

Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
 package/base-files/files/sbin/sysupgrade | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 4ecea5a303..e48870497e 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -10,6 +10,8 @@ export MTD_CONFIG_ARGS=""
 export INTERACTIVE=0
 export VERBOSE=1
 export SAVE_CONFIG=1
+export SAVE_CONFIG_KEEPD=1
+export SAVE_CONFIG_OPKG=1
 export SAVE_OVERLAY=0
 export SAVE_OVERLAY_PATH=
 export SAVE_PARTITIONS=1
@@ -32,6 +34,8 @@ while [ -n "$1" ]; do
 		-v) export VERBOSE="$(($VERBOSE + 1))";;
 		-q) export VERBOSE="$(($VERBOSE - 1))";;
 		-n) export SAVE_CONFIG=0;;
+		--no-keepd) export SAVE_CONFIG_KEEPD=0;;
+		--no-opkg) export SAVE_CONFIG_OPKG=0;;
 		-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
 		-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
 		-p) export SAVE_PARTITIONS=0;;
@@ -73,6 +77,8 @@ upgrade-option:
 	             from packages but including changed confs.
 	-u           skip from backup files that are equal to those in /rom
 	-n           do not save configuration over reflash
+	--no-keepd   do not save (exclude) keep.d configuration files over reflash
+	--no-opkg    do not save (exclude) opkg-managed configuration files over reflash
 	-p           do not attempt to restore the partition table after flash.
 	-k           include in backup a list of current installed packages at
 	             $INSTALLED_PACKAGES
@@ -123,6 +129,8 @@ list_conffiles() {
 }
 
 list_changed_conffiles() {
+	[ $SAVE_CONFIG_OPKG = 1 ] || return
+
 	# Cannot handle spaces in filenames - but opkg cannot either...
 	list_conffiles | while read file csum; do
 		[ -r "$file" ] || continue
@@ -133,9 +141,11 @@ list_changed_conffiles() {
 
 list_static_conffiles() {
 	local filter=$1
+	local filelist=/etc/sysupgrade.conf
+	[ $SAVE_CONFIG_KEEPD = 1 ] && filelist="$filelist /lib/upgrade/keep.d/*"
 
 	find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
-		/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
+		$filelist 2>/dev/null) \
 		\( -type f -o -type l \) $filter 2>/dev/null
 }
 
-- 
2.20.1




More information about the openwrt-devel mailing list