From cf0dc244633a7645e60df1d1783bb5d2372bdafc Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 21:27:53 +0200 Subject: [PATCH 1/8] gluon-setup-mode: create symlinks in install script The package rebuild logic of OpenWrt only checks regular files. Avoid symlinks in the files directory to make rebuilds more robust. --- package/gluon-setup-mode/Makefile | 21 +++++++++++++++++++ .../files/lib/gluon/setup-mode/rc.d/K89log | 1 - .../lib/gluon/setup-mode/rc.d/K90network | 1 - .../files/lib/gluon/setup-mode/rc.d/K98boot | 1 - .../files/lib/gluon/setup-mode/rc.d/K99umount | 1 - .../lib/gluon/setup-mode/rc.d/S00sysfixtime | 1 - .../files/lib/gluon/setup-mode/rc.d/S10boot | 1 - .../files/lib/gluon/setup-mode/rc.d/S10system | 1 - .../files/lib/gluon/setup-mode/rc.d/S11sysctl | 1 - .../files/lib/gluon/setup-mode/rc.d/S12log | 1 - .../files/lib/gluon/setup-mode/rc.d/S95done | 1 - 11 files changed, 21 insertions(+), 10 deletions(-) delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K89log delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K98boot delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K99umount delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S00sysfixtime delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10boot delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10system delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11sysctl delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S12log delete mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S95done diff --git a/package/gluon-setup-mode/Makefile b/package/gluon-setup-mode/Makefile index ff1c730b..67747957 100644 --- a/package/gluon-setup-mode/Makefile +++ b/package/gluon-setup-mode/Makefile @@ -17,4 +17,25 @@ define Package/gluon-setup-mode/description Offline mode to perform basic setup in a secure manner. endef +init_links := \ + K89log \ + K98boot \ + K99umount \ + S00sysfixtime \ + S10boot \ + S10system \ + S11sysctl \ + S12log \ + S95done + +define Package/gluon-setup-mode/install + $(Gluon/Build/Install) + + $(LN) S20network $(1)/lib/gluon/setup-mode/rc.d/K90network + + for link in $(init_links); do \ + $(LN) "/etc/init.d/$$$${link:3}" "$(1)/lib/gluon/setup-mode/rc.d/$$$${link}"; \ + done +endef + $(eval $(call BuildPackageGluon,gluon-setup-mode)) diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K89log b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K89log deleted file mode 120000 index 1e0c5ac0..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K89log +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/log \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network deleted file mode 120000 index 0a43e66b..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network +++ /dev/null @@ -1 +0,0 @@ -S20network \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K98boot b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K98boot deleted file mode 120000 index 64aea5e8..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K98boot +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/boot \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K99umount b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K99umount deleted file mode 120000 index b02f4892..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K99umount +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/umount \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S00sysfixtime b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S00sysfixtime deleted file mode 120000 index a4fb1d5b..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S00sysfixtime +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/sysfixtime \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10boot b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10boot deleted file mode 120000 index 64aea5e8..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10boot +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/boot \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10system b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10system deleted file mode 120000 index 81e8836f..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S10system +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/system \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11sysctl b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11sysctl deleted file mode 120000 index b4ac535e..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11sysctl +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/sysctl \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S12log b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S12log deleted file mode 120000 index 1e0c5ac0..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S12log +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/log \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S95done b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S95done deleted file mode 120000 index c9f30277..00000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S95done +++ /dev/null @@ -1 +0,0 @@ -/etc/init.d/done \ No newline at end of file From 62e71fbc407e745a5c81e15042cc39f57a654952 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 20:17:38 +0200 Subject: [PATCH 2/8] 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 00000000..0a563571 --- /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 00000000..758bb913 --- /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 db578a78..8b4be6a9 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 67747957..dfc1717a 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 \ From 60351a1f1934105c7628cda18946fe7a268b3ee0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 22:06:59 +0200 Subject: [PATCH 3/8] gluon-core: allow to switch domains during reconfiguration When gluon.core.switch_domain is set, it replaces the old domain. This also replaces an unnecessary uci:commit() with uci:save(). --- .../luasrc/lib/gluon/upgrade/005-set-domain | 48 +++++++++++++++++++ .../luasrc/lib/gluon/upgrade/005-site-domain | 27 ----------- 2 files changed, 48 insertions(+), 27 deletions(-) create mode 100755 package/gluon-core/luasrc/lib/gluon/upgrade/005-set-domain delete mode 100755 package/gluon-core/luasrc/lib/gluon/upgrade/005-site-domain diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/005-set-domain b/package/gluon-core/luasrc/lib/gluon/upgrade/005-set-domain new file mode 100755 index 00000000..680eab23 --- /dev/null +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/005-set-domain @@ -0,0 +1,48 @@ +#!/usr/bin/lua + +local unistd = require 'posix.unistd' + + +if not unistd.access('/lib/gluon/domains/') then + return +end + + +local function domain_exists(domain) + return unistd.access('/lib/gluon/domains/' .. domain .. '.json') == 0 +end + + +local uci = require('simple-uci').cursor() + +local domain = uci:get('gluon', 'core', 'switch_domain') +if domain and not domain_exists(domain) then + io.stderr:write( + string.format("Warning: invalid mesh domain switch to '%s' configured, not switching\n", domain) + ) + domain = nil +end + +if not domain then + domain = uci:get('gluon', 'core', 'domain') +end +if domain and not domain_exists(domain) then + io.stderr:write( + string.format("Warning: invalid mesh domain '%s' configured, resetting to default...\n", domain) + ) + domain = nil +end + +if not domain then + + -- We can't use gluon.site yet, as it depends on gluon.core.domain to be set + local json = require 'jsonc' + local site = assert(json.load('/lib/gluon/site.json')) + + domain = site.default_domain + +end + +uci:set('gluon', 'core', 'domain', domain) +uci:delete('gluon', 'core', 'switch_domain') +uci:save('gluon') diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/005-site-domain b/package/gluon-core/luasrc/lib/gluon/upgrade/005-site-domain deleted file mode 100755 index 2014dce6..00000000 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/005-site-domain +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/lua - -local unistd = require 'posix.unistd' - - -if not unistd.access('/lib/gluon/domains/') then - return -end - - -local uci = require('simple-uci').cursor() - -local domain = uci:get('gluon', 'core', 'domain') -if domain and not unistd.access('/lib/gluon/domains/' .. domain .. '.json') then - io.stderr:write(string.format("Warning: invalid mesh domain '%s' configured, resetting to default...\n", domain)) - domain = nil -end - -if domain then return end - - --- We can't use gluon.site yet, as it depends on gluon.core.domain to be set -local json = require 'jsonc' -local site = assert(json.load('/lib/gluon/site.json')) - -uci:set('gluon', 'core', 'domain', site.default_domain) -uci:commit('gluon') From 8a79d0249f7e2654706a9d542a283d41cf452235 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 23:10:49 +0200 Subject: [PATCH 4/8] gluon-scheduled-domain-switch: move gluon-switch-domain to /lib/gluon/scheduled-domain-switch This script is an implementation detail - let's not clutter the global $PATH namespace with a script with such a generic name. --- .../gluon/scheduled-domain-switch/switch-domain} | 0 .../luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename package/gluon-scheduled-domain-switch/luasrc/{usr/bin/gluon-switch-domain => lib/gluon/scheduled-domain-switch/switch-domain} (100%) diff --git a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/scheduled-domain-switch/switch-domain similarity index 100% rename from package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain rename to package/gluon-scheduled-domain-switch/luasrc/lib/gluon/scheduled-domain-switch/switch-domain diff --git a/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch index c221eeda..77803eee 100755 --- a/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch +++ b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch @@ -14,5 +14,5 @@ end -- Only in case domain switch is scheduled local f = io.open(cronfile, "w") f:write("* * * * * /usr/bin/gluon-check-connection\n") -f:write("*/5 * * * * /usr/bin/gluon-switch-domain\n") +f:write("*/5 * * * * /lib/gluon/scheduled-domain-switch/switch-domain\n") f:close() From 6750aef0178eecfd53742d16a53e18bdc918f8af Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 22:39:44 +0200 Subject: [PATCH 5/8] gluon-core: add gluon-switch-domain utility --- .../luasrc/usr/bin/gluon-switch-domain | 56 +++++++++++++++++++ .../files/lib/preinit/90_setup_mode | 4 ++ 2 files changed, 60 insertions(+) create mode 100755 package/gluon-core/luasrc/usr/bin/gluon-switch-domain diff --git a/package/gluon-core/luasrc/usr/bin/gluon-switch-domain b/package/gluon-core/luasrc/usr/bin/gluon-switch-domain new file mode 100755 index 00000000..a964bde9 --- /dev/null +++ b/package/gluon-core/luasrc/usr/bin/gluon-switch-domain @@ -0,0 +1,56 @@ +#!/usr/bin/lua + +local unistd = require 'posix.unistd' + + +local function shift() + table.remove(arg, 1) +end + +local reboot = true +if arg[1] == '--no-reboot' then + reboot = false + shift() +end + +local setup_mode = unistd.access('/var/gluon/setup-mode') == 0 + +if #arg ~= 1 then + io.stderr:write('Usage: gluon-switch-domain [--no-reboot] \n') + os.exit(1) +end +local domain = arg[1] + + +if not unistd.access('/lib/gluon/domains/') then + io.stderr:write('This Gluon firmware does not support multiple mesh domains.\n') + os.exit(1) +end + + +local function domain_exists(dom) + return unistd.access('/lib/gluon/domains/' .. dom .. '.json') == 0 +end + +if not domain_exists(domain) then + io.stderr:write(string.format("Error: invalid mesh domain '%s'\n", domain)) + os.exit(1) +end + + +local uci = require('simple-uci').cursor() +uci:set('gluon', 'core', 'switch_domain', domain) +uci:set('gluon', 'core', 'reconfigure', true) +uci:save('gluon') + +local cmd +if setup_mode then + cmd = 'gluon-reconfigure' +elseif reboot then + uci:commit('gluon') + cmd = 'reboot' +else + cmd = 'gluon-reload' +end + +unistd.execp(cmd, {[0] = cmd}) diff --git a/package/gluon-setup-mode/files/lib/preinit/90_setup_mode b/package/gluon-setup-mode/files/lib/preinit/90_setup_mode index c38ac281..b9365be1 100644 --- a/package/gluon-setup-mode/files/lib/preinit/90_setup_mode +++ b/package/gluon-setup-mode/files/lib/preinit/90_setup_mode @@ -7,6 +7,10 @@ setup_mode_enable() { if [ "$enabled" = 1 ] || [ "$configured" != 1 ]; then echo '/lib/gluon/setup-mode/rc.d' > /tmp/rc_d_path + + # This directory is a marker for scripts to know that we're + # in config mode, but it is also used for temporary files + mkdir -p /var/gluon/setup-mode fi } From 6ab9d3415dd2e5c280ae5273d578a37bdb1b4378 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 22:49:08 +0200 Subject: [PATCH 6/8] gluon-hoodselector: use gluon-switch-domain --- .../luasrc/usr/lib/lua/hoodselector/util.lua | 4 +--- package/gluon-hoodselector/luasrc/usr/sbin/hoodselector | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua b/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua index b93097a6..af079f36 100644 --- a/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua +++ b/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua @@ -67,9 +67,7 @@ end function M.set_domain_config(domain) if uci:get('gluon', 'core', 'domain') ~= domain.domain_code then - uci:set('gluon', 'core', 'domain', domain.domain_code) - uci:commit('gluon') - os.execute('gluon-reconfigure') + os.execute(string.format("exec gluon-switch-domain --no-reboot '%s'", domain.domain_code)) M.log('Set domain "'..domain.domain.domain_names[domain.domain_code]..'"') return true end diff --git a/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector b/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector index 12125da7..03852272 100755 --- a/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector +++ b/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector @@ -40,7 +40,6 @@ if geo.lat ~= nil and geo.lon ~= nil then local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo) if geo_base_domain ~= nil then if hoodutil.set_domain_config(geo_base_domain) then - os.execute("gluon-reload") hoodutil.log('Domain set by geolocation mode.\n') end return @@ -51,6 +50,4 @@ else end -- default domain mode -if hoodutil.set_domain_config(hoodutil.get_default_domain(hoodutil.get_domains())) then - os.execute("gluon-reload") -end +hoodutil.set_domain_config(hoodutil.get_default_domain(hoodutil.get_domains())) From 02c8650bae03f76774a536b653993b9a6fae7034 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 23:08:37 +0200 Subject: [PATCH 7/8] gluon-scheduled-domain-switch: use gluon-switch-domain --- .../luasrc/lib/gluon/scheduled-domain-switch/switch-domain | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/scheduled-domain-switch/switch-domain b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/scheduled-domain-switch/switch-domain index 31fcea36..1d7e5898 100755 --- a/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/scheduled-domain-switch/switch-domain +++ b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/scheduled-domain-switch/switch-domain @@ -60,8 +60,5 @@ if not switch_after_min_reached() and not switch_time_passed() then os.exit(0) end -uci:set("gluon", "core", "domain", target_domain) -uci:commit("gluon") - -os.execute("gluon-reconfigure") -os.execute("reboot") +local cmd = {[0] = 'gluon-switch-domain', target_domain} +unistd.execp(cmd[0], cmd) From 813f89a60b9e89014c3c16aa998c661217df3bc2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Jun 2020 23:43:17 +0200 Subject: [PATCH 8/8] docs: features/multidomain: update docs to mention gluon-switch-domain --- docs/features/multidomain.rst | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/features/multidomain.rst b/docs/features/multidomain.rst index 1f9a729e..7abd59a8 100644 --- a/docs/features/multidomain.rst +++ b/docs/features/multidomain.rst @@ -88,18 +88,25 @@ domain of a router, if and only if one of the above conditions matches. Switching the domain -------------------- -**via commandline**: +Via commandline +^^^^^^^^^^^^^^^ :: - uci set gluon.core.domain="newdomaincode" - gluon-reconfigure - reboot + gluon-switch-domain 'newdomaincode' -**via config mode:** +When the node is not in config mode, ``gluon-switch-domain`` will automatically +reboot the node by default. This can be suppressed by passing ``--no-reboot``:: -To allow switching the domain via config mode, ``config-mode-domain-select`` -has to be added to GLUON_FEATURES in the site.mk. + gluon-switch-domain --no-reboot 'newdomaincode' + +Switching the domain without reboot is currently **experimental**. + +Via config mode +^^^^^^^^^^^^^^^ + +To allow switching the domain via config mode, add ``config-mode-domain-select`` +to GLUON_FEATURES in site.mk. |image0|