autoupdater.lua 2.3 KB

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