gen-domains.lua 873 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/lua
  2. function replace_patterns(value, subst)
  3. for k, v in pairs(subst) do
  4. value = value:gsub(k, v)
  5. end
  6. return value
  7. end
  8. local site_dir = os.getenv('GLUON_SITEDIR')
  9. dofile(site_dir .. '/extra/sites.conf')
  10. dofile(site_dir .. '/extra/groups.conf')
  11. local template = io.open(site_dir .. '/domain.tmpl'):read('*a')
  12. os.execute('mkdir -p ' .. site_dir .. '/domains')
  13. for _, site in pairs(sites) do
  14. local path = site_dir .. '/domains/' .. site.site_code .. '.conf'
  15. local subst = {
  16. ['%%CO'] = site.site_code,
  17. ['%%NA'] = site.site_name,
  18. ['%%MI'] = site.site_select.group,
  19. ['%%HI'] = (site.site_select or {}).hidden and 'true' or 'false',
  20. }
  21. local config = replace_patterns(template, subst)
  22. config = replace_patterns(config, site.subst)
  23. config = replace_patterns(config, groups[site.site_select.group].subst)
  24. io.open(path, 'w'):write(config)
  25. end