002-set-site-config 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. local file = "/etc/sysupgrade.conf"
  9. local configured = false
  10. function serialize (f,o,d)
  11. if type(o) == "number" then
  12. f:write(o)
  13. elseif type(o) == "string" then
  14. f:write(string.format("%q", o))
  15. elseif type(o) == "boolean" then
  16. f:write(o and 1 or 0)
  17. elseif type(o) == "table" then
  18. f:write("{\n")
  19. for k,v in pairs(o) do
  20. f:write(string.rep (" ", d+1))
  21. if type(k) == "string" then
  22. f:write(k, " = ")
  23. end
  24. serialize(f,v,d+1)
  25. f:write(",\n")
  26. end
  27. f:write(string.rep (" ", d), "}")
  28. else
  29. error("cannot serialize a " .. type(o))
  30. end
  31. end
  32. for line in io.lines(file) do
  33. if line == "/etc/config/currentsite" then
  34. configured = true
  35. end
  36. end
  37. if configured == false then
  38. f = io.open(file,"a")
  39. f:write("/etc/config/currentsite\n")
  40. f:close()
  41. end
  42. if site.site_code ~= currentsite then
  43. if type(config[currentsite]) == "table" then
  44. local new = {}
  45. new.hostname_prefix = site.hostname_prefix
  46. new.site_name = config[currentsite].site_name
  47. new.site_code = config[currentsite].site_code
  48. new.prefix4 = site.prefix4
  49. new.prefix6 = site.prefix6
  50. new.additional_prefix6 = site.additional_prefix6
  51. new.timezone = site.timezone
  52. new.ntp_servers = site.ntp_servers
  53. new.opkg_repo = site.opkg_repo
  54. new.regdom = site.regdom
  55. new.wifi24 = site.wifi24
  56. new.wifi5 = site.wifi5
  57. new.wifi24.ssid = config[currentsite].ssid
  58. new.wifi5.ssid = config[currentsite].ssid
  59. new.next_node = site.next_node
  60. new.fastd_mesh_vpn = site.fastd_mesh_vpn
  61. new.autoupdater = site.autoupdater
  62. new.simple_tc = site.simple_tc
  63. new.debugserver = site.debugserver
  64. new.batman_on_wan = site.batman_on_wan
  65. file = '/lib/gluon/site.conf'
  66. f = io.open(file, "w")
  67. serialize(f,new,0)
  68. f:write('\n')
  69. f:close()
  70. else
  71. c:set("currentsite", "current", "name", site.site_code)
  72. c:save('currentsite')
  73. c:commit('currentsite')
  74. end
  75. end