[PATCH] base-files: sysupgrade: fix generating backup to stdout

Rafał Miłecki zajec5 at gmail.com
Sun Mar 3 23:15:58 PST 2024


From: Rafał Miłecki <rafal at milecki.pl>

Before recent change "tar" command was called with an "-f" argument
which accepts "-" for stdout output. Bring back support for that feature
with new code.

Fixes: e36cc530927c ("base-files: sysupgrade: use tar helper to include installed_packages.txt")
Fixes: https://github.com/openwrt/openwrt/issues/14773
Cc: Jo-Philipp Wich <jo at mein.io>
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 package/base-files/files/sbin/sysupgrade | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 78ec455067..b1a7335bc0 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -236,12 +236,15 @@ include /lib/upgrade
 
 create_backup_archive() {
 	local conf_tar="$1"
+	local output_file=""
 	local disabled
 
+	[ "$conf_tar" != "-" ] && output_file="$conf_tar"
+
 	[ "$(rootfs_type)" = "tmpfs" ] && {
 		echo "Cannot save config while running from ramdisk." >&2
 		ask_bool 0 "Abort" && exit
-		rm -f "$conf_tar"
+		[ -n "$output_file" ] && rm -f "$output_file"
 		return 0
 	}
 	run_hooks "$CONFFILES" $sysupgrade_init_conffiles
@@ -272,12 +275,12 @@ create_backup_archive() {
 
 		# Rest of archive with config files and ending padding
 		tar c${TAR_V} -C / -T "$CONFFILES"
-	} | gzip > "$conf_tar"
+	} | gzip > "${output_file:-/dev/stdout}"
 
 	local err=$?
 	if [ "$err" -ne 0 ]; then
 		echo "Failed to create the configuration backup."
-		rm -f "$conf_tar"
+		[ -n "$output_file" ] && rm -f "$output_file"
 	fi
 
 	rm -f "$CONFFILES"
-- 
2.35.3




More information about the openwrt-devel mailing list