diff mbox

[OpenWrt-Devel] base-files: Add preinit option to disable config restore

Message ID 1436796857-16666-1-git-send-email-br1@einfach.org
State Rejected
Headers show

Commit Message

Bruno Randolf July 13, 2015, 2:14 p.m. UTC
Sometimes it's desirable to be sure that config files from a new firmware image
overwrite the config files from the previously running firmware and we can not
always expect the user to use 'sysupgrade -n'. In this case the option
TARGET_PREINIT_CONFIG_RESTORE can be set to 'n'.

This is more useful with a custom uci-default scripts which can selectively
migrate config options, since the the old configuration still exists during the
first boot in /sysupgrade.tgz until /etc/init.d/done is called.

Signed-off-by: Bruno Randolf <br1@einfach.org>
---
 package/base-files/Makefile                        | 3 ++-
 package/base-files/files/etc/preinit               | 1 +
 package/base-files/files/lib/preinit/80_mount_root | 2 +-
 package/base-files/image-config.in                 | 7 +++++++
 4 files changed, 11 insertions(+), 2 deletions(-)

Comments

Felix Fietkau July 14, 2015, 9:09 a.m. UTC | #1
On 2015-07-13 16:14, Bruno Randolf wrote:
> Sometimes it's desirable to be sure that config files from a new firmware image
> overwrite the config files from the previously running firmware and we can not
> always expect the user to use 'sysupgrade -n'. In this case the option
> TARGET_PREINIT_CONFIG_RESTORE can be set to 'n'.
> 
> This is more useful with a custom uci-default scripts which can selectively
> migrate config options, since the the old configuration still exists during the
> first boot in /sysupgrade.tgz until /etc/init.d/done is called.
> 
> Signed-off-by: Bruno Randolf <br1@einfach.org>
Unless I'm missing something, this seems like a rarely needed special
case to me. How about simply adding a custom preinit file to your
firmware through files/ instead?
Since the preinit script runs boot_run_hook preinit_mount_root just
before the config restore, you should be able to add your code in the
right place and use it to delete or move sysupgrade.tgz.

- Felix
Bruno Randolf July 14, 2015, 10:41 a.m. UTC | #2
Hi Felix,

On 07/14/2015 10:09 AM, Felix Fietkau wrote:
> Unless I'm missing something, this seems like a rarely needed special
> case to me. How about simply adding a custom preinit file to your
> firmware through files/ instead?
> Since the preinit script runs boot_run_hook preinit_mount_root just
> before the config restore, you should be able to add your code in the
> right place and use it to delete or move sysupgrade.tgz.

Yes, you are right, this is a simpler way. Forget my patch then.

Greetings,
bruno
diff mbox

Patch

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index a5f15fa..94a6f26 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -11,7 +11,7 @@  include $(INCLUDE_DIR)/kernel.mk
 include $(INCLUDE_DIR)/version.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=157
+PKG_RELEASE:=158
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
 PKG_BUILD_DEPENDS:=opkg/host usign/host
@@ -79,6 +79,7 @@  define ImageConfigOptions
 	echo 'pi_broadcast=$(if $(CONFIG_TARGET_PREINIT_BROADCAST),$(CONFIG_TARGET_PREINIT_BROADCAST),"192.168.1.255")' >>$(1)/lib/preinit/00_preinit.conf
 	echo 'pi_preinit_net_messages="$(CONFIG_TARGET_PREINIT_SHOW_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf
 	echo 'pi_preinit_no_failsafe_netmsg="$(CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf
+	echo 'pi_config_restore="$(CONFIG_TARGET_PREINIT_CONFIG_RESTORE)"' >>$(1)/lib/preinit/00_preinit.conf
 endef
 endif
 
diff --git a/package/base-files/files/etc/preinit b/package/base-files/files/etc/preinit
index 9cc8a9a..c0b3168 100755
--- a/package/base-files/files/etc/preinit
+++ b/package/base-files/files/etc/preinit
@@ -20,6 +20,7 @@  fs_failsafe_wait_timeout=2
 
 pi_suppress_stderr="y"
 pi_init_suppress_stderr="y"
+pi_config_restore="y"
 pi_init_path="/bin:/sbin:/usr/bin:/usr/sbin"
 pi_init_cmd="/sbin/init"
 
diff --git a/package/base-files/files/lib/preinit/80_mount_root b/package/base-files/files/lib/preinit/80_mount_root
index f3fe788..770c845 100644
--- a/package/base-files/files/lib/preinit/80_mount_root
+++ b/package/base-files/files/lib/preinit/80_mount_root
@@ -5,7 +5,7 @@ 
 do_mount_root() {
 	mount_root
 	boot_run_hook preinit_mount_root
-	[ -f /sysupgrade.tgz ] && {
+	[ "$pi_config_restore" = "y" ] && [ -f /sysupgrade.tgz ] && {
 		echo "- config restore -"
 		cd /
 		tar xzf /sysupgrade.tgz
diff --git a/package/base-files/image-config.in b/package/base-files/image-config.in
index fd0ead6..832bf43 100644
--- a/package/base-files/image-config.in
+++ b/package/base-files/image-config.in
@@ -86,6 +86,13 @@  config TARGET_PREINIT_BROADCAST
 		Broadcast address to which to send preinit network messages, as
 		as failsafe messages
 
+config TARGET_PREINIT_CONFIG_RESTORE
+	bool
+	prompt "Restore configuration from sysupgrade" if PREINITOPT
+	default y
+	help
+		Restore configuration from previous firmware when doing
+		sysupgrade. Normally this should be 'y'.
 
 menuconfig INITOPT
 	bool "Init configuration options" if IMAGEOPT