From 62e71fbc407e745a5c81e15042cc39f57a654952 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Tue, 30 Jun 2020 20:17:38 +0200
Subject: [PATCH] gluon-core: run gluon-reconfigure on boot when
 gluon.core.need_reconfigure is set

---
 .../files/etc/init.d/gluon-core-reconfigure          | 12 ++++++++++++
 .../gluon/reload.d/710-gluon-core-reconfigure-start  |  2 ++
 .../gluon-core/files/lib/gluon/upgrade/998-commit    |  5 ++++-
 package/gluon-setup-mode/Makefile                    |  1 +
 4 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100755 package/gluon-core/files/etc/init.d/gluon-core-reconfigure
 create mode 100755 package/gluon-core/files/lib/gluon/reload.d/710-gluon-core-reconfigure-start

diff --git a/package/gluon-core/files/etc/init.d/gluon-core-reconfigure b/package/gluon-core/files/etc/init.d/gluon-core-reconfigure
new file mode 100755
index 000000000..0a5635718
--- /dev/null
+++ b/package/gluon-core/files/etc/init.d/gluon-core-reconfigure
@@ -0,0 +1,12 @@
+#!/bin/sh /etc/rc.common
+
+# Start right after S10boot
+START=10
+
+start() {
+	config_load gluon
+	config_get_bool reconfigure core reconfigure 0
+	if [ "$reconfigure" = 1 ]; then
+		gluon-reconfigure
+	fi
+}
diff --git a/package/gluon-core/files/lib/gluon/reload.d/710-gluon-core-reconfigure-start b/package/gluon-core/files/lib/gluon/reload.d/710-gluon-core-reconfigure-start
new file mode 100755
index 000000000..758bb9134
--- /dev/null
+++ b/package/gluon-core/files/lib/gluon/reload.d/710-gluon-core-reconfigure-start
@@ -0,0 +1,2 @@
+#!/bin/sh
+/etc/init.d/gluon-core-reconfigure start
diff --git a/package/gluon-core/files/lib/gluon/upgrade/998-commit b/package/gluon-core/files/lib/gluon/upgrade/998-commit
index db578a78e..8b4be6a9d 100755
--- a/package/gluon-core/files/lib/gluon/upgrade/998-commit
+++ b/package/gluon-core/files/lib/gluon/upgrade/998-commit
@@ -1,3 +1,6 @@
 #!/bin/sh
 
-exec uci commit
+uci -q batch <<-EOF
+	delete gluon.core.reconfigure
+	commit
+EOF
diff --git a/package/gluon-setup-mode/Makefile b/package/gluon-setup-mode/Makefile
index 67747957d..dfc1717a6 100644
--- a/package/gluon-setup-mode/Makefile
+++ b/package/gluon-setup-mode/Makefile
@@ -23,6 +23,7 @@ init_links := \
 	K99umount \
 	S00sysfixtime \
 	S10boot \
+	S10gluon-core-reconfigure \
 	S10system \
 	S11sysctl \
 	S12log \
-- 
GitLab