#!/usr/bin/lua local uci = require('luci.model.uci').cursor() local site = require 'gluon.site_config' local config = require 'gluon.sites' function serialize (f,o,d) if type(o) == "number" then f:write(o) elseif type(o) == "string" then f:write(string.format("%q", o)) elseif type(o) == "boolean" then f:write(o and 1 or 0) elseif type(o) == "table" then f:write("{\n") for k,v in pairs(o) do f:write(string.rep (" ", d+1)) if type(k) == "string" then f:write(k, " = ") end serialize(f,v,d+1) f:write(",\n") end f:write(string.rep (" ", d), "}") else f:write("ERROR: cannot serialize a " .. type(o)) end end local currentsite = uci:get("currentsite", "current", "name") if site.site_code ~= currentsite then local configured = false for index, tmp in pairs(config) do if tmp.site_code == currentsite then local new = {} new.hostname_prefix = site.hostname_prefix new.site_name = tmp.site_name new.site_code = tmp.site_code new.prefix4 = site.prefix4 new.prefix6 = site.prefix6 new.additional_prefix6 = site.additional_prefix6 new.timezone = site.timezone new.ntp_servers = site.ntp_servers new.opkg_repo = site.opkg_repo new.regdom = site.regdom new.wifi24 = site.wifi24 new.wifi5 = site.wifi5 new.next_node = site.next_node new.fastd_mesh_vpn = site.fastd_mesh_vpn new.autoupdater = site.autoupdater new.simple_tc = site.simple_tc new.debugserver = site.debugserver new.batman_on_wan = site.batman_on_wan file = '/lib/gluon/site.conf' f = io.open(file, "w") serialize(f,new,0) f:write('\n') f:close() configured = true break end end if configured == false then uci:set("currentsite", "current", "name", site.site_code) uci:save('currentsite') uci:commit('currentsite') end end