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 }