002-set-site-config 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/lua
  2. local uci = require('luci.model.uci').cursor()
  3. local site = require 'gluon.site_config'
  4. local config = require 'gluon.sites'
  5. function serialize (f,o,d)
  6. if type(o) == "number" then
  7. f:write(o)
  8. elseif type(o) == "string" then
  9. f:write(string.format("%q", o))
  10. elseif type(o) == "boolean" then
  11. f:write(o and 1 or 0)
  12. elseif type(o) == "table" then
  13. f:write("{\n")
  14. for k,v in pairs(o) do
  15. f:write(string.rep (" ", d+1))
  16. if type(k) == "string" then
  17. f:write(k, " = ")
  18. end
  19. serialize(f,v,d+1)
  20. f:write(",\n")
  21. end
  22. f:write(string.rep (" ", d), "}")
  23. else
  24. f:write("ERROR: cannot serialize a " .. type(o))
  25. end
  26. end
  27. local currentsite = uci:get("currentsite", "current", "name")
  28. if site.site_code ~= currentsite then
  29. local configured = false
  30. for index, tmp in pairs(config) do
  31. if tmp.site_code == currentsite then
  32. local new = {}
  33. new.hostname_prefix = site.hostname_prefix
  34. new.site_name = tmp.site_name
  35. new.site_code = tmp.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.next_node = site.next_node
  46. new.fastd_mesh_vpn = site.fastd_mesh_vpn
  47. new.autoupdater = site.autoupdater
  48. new.simple_tc = site.simple_tc
  49. new.debugserver = site.debugserver
  50. new.batman_on_wan = site.batman_on_wan
  51. file = '/lib/gluon/site.conf'
  52. f = io.open(file, "w")
  53. serialize(f,new,0)
  54. f:write('\n')
  55. f:close()
  56. configured = true
  57. break
  58. end
  59. end
  60. if configured == false then
  61. uci:set("currentsite", "current", "name", site.site_code)
  62. uci:save('currentsite')
  63. uci:commit('currentsite')
  64. end
  65. end