12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/lua
- local uci = require('luci.model.uci').cursor()
- local json = require 'luci.jsonc'
- local site_code = require('gluon.site_config').site_code
- local default = json.decode(io.open('/lib/gluon/site-select/default.json'):read('*a'))
- local groups = json.decode(io.open('/lib/gluon/site-select/groups.json'):read('*a'))
- local sites = json.decode(io.open('/lib/gluon/site-select/sites.json'):read('*a'))
- 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 currentsite = uci:get("currentsite", "current", "name")
- if site_code ~= currentsite then
- local configured = false
- for index, site in pairs(sites) do
- if site.site_code == currentsite then
- if 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)
- file = '/lib/gluon/site.conf'
- f = io.open(file, "w")
- io.write(f,json.encode(default))
- f:close()
- configured = true
- break
- end
- end
- if configured == false then
- uci:set("currentsite", "current", "name", site_code)
- uci:save('currentsite')
- uci:commit('currentsite')
- end
- end
|