1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/usr/bin/lua
- local uci = require('simple-uci').cursor()
- local site_code = require('gluon.site').site_code()
- local tools = require 'gluon.site_generate'
- 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 config = io.open('/lib/gluon/site-select/template.json'):read('*a')
- 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.set_site_code(site_code, true)
- end
- end
|