dockerd-config.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require "luci.util"
  2. fs = require "nixio.fs"
  3. uci = (require "luci.model.uci").cursor()
  4. raw_file_dir = arg[1]
  5. raw_json_str = fs.readfile(raw_file_dir) or "[]"
  6. raw_json = luci.jsonc.parse(raw_json_str) or {}
  7. new_json = {}
  8. new_json["data-root"] = uci:get("dockerman", "local", "daemon_data_root")
  9. new_json["hosts"] = uci:get("dockerman", "local", "daemon_hosts") or {}
  10. new_json["registry-mirrors"] = uci:get("dockerman", "local", "daemon_registry_mirrors") or {}
  11. new_json["log-level"] = uci:get("dockerman", "local", "daemon_log_level")
  12. function comp(raw, new)
  13. for k, v in pairs(new) do
  14. if type(v) == "table" and raw[k] then
  15. if #v == #raw[k] then
  16. comp(raw[k], v)
  17. else
  18. changed = true
  19. raw[k] = v
  20. end
  21. elseif raw[k] ~= v then
  22. changed = true
  23. raw[k] = v
  24. end
  25. end
  26. for k, v in ipairs(new) do
  27. if type(v) == "table" and raw[k] then
  28. if #v == #raw[k] then
  29. comp(raw[k], v)
  30. else
  31. changed = true
  32. raw[k] = v
  33. end
  34. elseif raw[k] ~= v then
  35. changed = true
  36. raw[k] = v
  37. end
  38. end
  39. end
  40. comp(raw_json, new_json)
  41. if changed then
  42. if next(raw_json["registry-mirrors"]) == nil then raw_json["registry-mirrors"] = nil end
  43. if next(raw_json["hosts"]) == nil then raw_json["hosts"] = nil end
  44. fs.writefile(raw_file_dir, luci.jsonc.stringify(raw_json, true):gsub("\\", ""))
  45. os.exit(0)
  46. else
  47. os.exit(1)
  48. end