002-set-site-config 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/lua
  2. local uci = require 'luci.model.uci'
  3. local site = require 'gluon.site_config'
  4. local fs = require "nixio.fs"
  5. local c = uci.cursor()
  6. local config = require 'gluon.sites'
  7. local currentsite = c:get("currentsite", "current", "name")
  8. function serialize (f,o,d)
  9. if type(o) == "number" then
  10. f:write(o)
  11. elseif type(o) == "string" then
  12. f:write(string.format("%q", o))
  13. elseif type(o) == "boolean" then
  14. f:write(o and 1 or 0)
  15. elseif type(o) == "table" then
  16. f:write("{\n")
  17. for k,v in pairs(o) do
  18. f:write(string.rep (" ", d+1))
  19. if type(k) == "string" then
  20. f:write(k, " = ")
  21. end
  22. serialize(f,v,d+1)
  23. f:write(",\n")
  24. end
  25. f:write(string.rep (" ", d), "}")
  26. else
  27. error("cannot serialize a " .. type(o))
  28. end
  29. end
  30. if site.site_code ~= currentsite then
  31. if type(config[currentsite]) == "table" then
  32. local new = {}
  33. new.hostname_prefix = site.hostname_prefix
  34. new.site_name = config[currentsite].site_name
  35. new.site_code = config[currentsite].site_code
  36. new.prefix4 = site.prefix4
  37. new.prefix6 = site.prefix6
  38. new.additional_prefix6 = site.additional_prefix6
  39. new.timezone = site.timezone
  40. new.ntp_servers = site.ntp_servers
  41. new.opkg_repo = site.opkg_repo
  42. new.regdom = site.regdom
  43. new.wifi24 = site.wifi24
  44. new.wifi5 = site.wifi5
  45. new.wifi24.ssid = config[currentsite].ssid
  46. new.wifi5.ssid = config[currentsite].ssid
  47. new.next_node = site.next_node
  48. new.fastd_mesh_vpn = site.fastd_mesh_vpn
  49. new.autoupdater = site.autoupdater
  50. new.simple_tc = site.simple_tc
  51. new.debugserver = site.debugserver
  52. new.batman_on_wan = site.batman_on_wan
  53. file = '/lib/gluon/site.conf'
  54. f = io.open(file, "w")
  55. serialize(f,new,0)
  56. f:write('\n')
  57. f:close()
  58. else
  59. c:set("currentsite", "current", "name", site.site_code)
  60. c:save('currentsite')
  61. c:commit('currentsite')
  62. end
  63. end