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 <b...@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(-)

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
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to