autoupdater.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --[[
  2. Copyright 2013 Nils Schneider <nils@nilsschneider.net>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. ]]--
  8. local uci = require("simple-uci").cursor()
  9. local autoupdater = uci:get_first("autoupdater", "autoupdater")
  10. local f = Form(translate("Automatic updates"))
  11. local s = f:section(Section)
  12. local o
  13. o = s:option(Flag, "enabled", translate("Enable"))
  14. o.default = uci:get_bool("autoupdater", autoupdater, "enabled")
  15. function o:write(data)
  16. uci:set("autoupdater", autoupdater, "enabled", data)
  17. end
  18. o = s:option(ListValue, "branch", translate("Branch"))
  19. uci:foreach("autoupdater", "branch",
  20. function (section)
  21. o:value(section[".name"])
  22. end
  23. )
  24. o.default = uci:get("autoupdater", autoupdater, "branch")
  25. function o:write(data)
  26. uci:set("autoupdater", autoupdater, "branch", data)
  27. end
  28. o = s:option(Value, "minute", translate("Minute"), translate(
  29. "This value forces the autoupdater to check for updates at the "
  30. .. "specified minute. Normally there is no need to set this value "
  31. .. "because it is selected automatically. You may want to set this to "
  32. .. "a specific value if you have multiple nodes which should not "
  33. .. "update at the same time."
  34. ))
  35. o.datatype = "irange(0, 59)"
  36. o.default = uci:get("gluon", "autoupdater", "minute")
  37. o.optional = true
  38. function o:write(data)
  39. if data == uci:get("gluon", "autoupdater", "minute") then
  40. return
  41. end
  42. uci:set("gluon", "autoupdater", "minute", data)
  43. if data then
  44. local f = io.open("/usr/lib/micron.d/autoupdater", "w")
  45. f:write(string.format("%i 4 * * * /usr/sbin/autoupdater\n", data))
  46. f:write(string.format("%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n", data))
  47. f:close()
  48. end
  49. end
  50. function f:write()
  51. uci:commit("autoupdater")
  52. uci:commit("gluon")
  53. end
  54. return f