002-domain-migration 722 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/lua
  2. local fs = require 'nixio.fs'
  3. local uci = require("simple-uci").cursor()
  4. local file = '/etc/config/currentsite'
  5. if not uci:get('gluon', 'core') then
  6. uci:section('gluon', 'core', 'core')
  7. end
  8. if uci:get('gluon', 'system') then
  9. uci:delete('gluon', 'system')
  10. end
  11. if fs.stat(file) then
  12. local domain = uci:get('currentsite', 'current', 'name')
  13. -- We can't use gluon.site yet, as it depends on gluon.core.domain to be set
  14. local json = require 'jsonc'
  15. local site = assert(json.load('/lib/gluon/site.json'))
  16. if (site.domain_migration or {}).match then
  17. domain = domain:match(site.domain_migration.match) or domain
  18. end
  19. uci:set('gluon', 'core', 'domain', domain)
  20. fs.remove(file)
  21. end
  22. uci:save('gluon')