123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/usr/bin/lua
- local uci = require('luci.model.uci').cursor()
- local json = require 'luci.json'
- local site_code = require('gluon.site_config').site_code
- local tools = require 'gluon.site_generate'
- function add_var_to_table(table, var)
- if type(var) == "table" and type(table) == "table" then
- for name, value in pairs(var) do
- if table[name] and type(value) == "table" then
- table[name] = add_var_to_table(table[name], value)
- else
- table[name]=value
- end
- end
- end
- return table
- end
- local default = tools.get_config('/lib/gluon/site-select/default.json')
- local groups = tools.get_config('/lib/gluon/site-select/groups.json')
- local sites = tools.get_config('/lib/gluon/site-select/sites.json')
- local currentsite = uci:get("currentsite", "current", "name")
- if site_code ~= currentsite then
- local configured = false
- for _, site in pairs(sites) do
- if site.site_code == currentsite then
- if site.site_select and site.site_select.group and groups and groups[site.site_select.group] then
- default = add_var_to_table(default, groups[site.site_select.group])
- end
- default = add_var_to_table(default, site)
- local file = '/lib/gluon/site.json'
- local f = io.open(file, "w")
- f:write(json.encode(default))
- f:close()
- configured = true
- break
- end
- end
- if configured == false then
- tools.force_site_code(site_code)
- end
- end
|