diff mbox series

[V3,3/3] base-files: sysupgrade: add uci-defaults script disabling services #2

Message ID 20240228105102.3399-3-zajec5@gmail.com
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series [V3,1/3] base-files: sysupgrade: add tar.sh with helpers for building archives | expand

Commit Message

Rafał Miłecki Feb. 28, 2024, 10:51 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

Disabled services should be kept disabled after sysupgrade. This can be
easily handled using a proper uci-defaults script.

Extend sysupgrade to check for disabled services, generate uci-defaults
script disabling them and include it in backup.

Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Jo-Philipp Wich <jo@mein.io>
Cc: Jonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 package/base-files/files/sbin/sysupgrade | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Jo-Philipp Wich Feb. 29, 2024, 1:43 p.m. UTC | #1
Hi,

> [...]
> Extend sysupgrade to check for disabled services, generate uci-defaults
> script disabling them and include it in backup.
> 
> Cc: Christian Marangi <ansuelsmth@gmail.com>
> Cc: Jo-Philipp Wich <jo@mein.io>
> Cc: Jonas Gorski <jonas.gorski@gmail.com>
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Acked-by: Jo-Philipp Wich <jo@mein.io>

~ Jo
diff mbox series

Patch

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index a11e17615c..78ec455067 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -236,6 +236,7 @@  include /lib/upgrade
 
 create_backup_archive() {
 	local conf_tar="$1"
+	local disabled
 
 	[ "$(rootfs_type)" = "tmpfs" ] && {
 		echo "Cannot save config while running from ramdisk." >&2
@@ -250,6 +251,14 @@  create_backup_archive() {
 	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
 	sed -i -e 's,^/,,' "$CONFFILES"
 	{
+		for service in /etc/init.d/*; do
+			if ! $service enabled; then
+				disabled="$disabled$service disable\n"
+			fi
+		done
+		disabled="$disabled\nexit 0"
+		tar_print_member "/etc/uci-defaults/10_disable_services" "$(echo -e $disabled)"
+
 		# Part of archive with installed packages info
 		if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
 			# Format: pkg-name<TAB>{rom,overlay,unknown}