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'
- local config = io.open('/lib/gluon/site-select/template.json'):read('*a')
- 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
- local subst = {}
- subst['%%SN'] = site.site_name
- subst['%%SC'] = site.site_code
- if site.subst then
- config = tools.replace_patterns(config, site.subst)
- end
- if (site.site_select or {}).group and groups and groups[site.site_select.group] then
- group = groups[site.site_select.group]
- subst['%%GN'] = site.site_select.group
- if group.subst then
- config = tools.replace_patterns(config, group.subst)
- end
- end
- config = tools.replace_patterns(config, subst)
- local file = '/lib/gluon/site.json'
- local f = io.open(file, "w")
- f:write(config)
- f:close()
- configured = true
- break
- end
- end
- if configured == false then
- tools.force_site_code(site_code)
- end
- end
|