autoupdater.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 pkg_i18n = i18n 'ffho-web-autoupdater'
  13. local f = Form(pkg_i18n.translate('Automatic updates'))
  14. local s = f:section(Section)
  15. local o
  16. o = s:option(Flag, 'enabled', pkg_i18n.translate('Enable'))
  17. o.default = uci:get_bool('autoupdater', autoupdater, 'enabled')
  18. function o:write(data)
  19. uci:set('autoupdater', autoupdater, 'enabled', data)
  20. end
  21. o = s:option(ListValue, 'branch', pkg_i18n.translate('Branch'))
  22. uci:foreach('autoupdater', 'branch',
  23. function (section)
  24. o:value(section['.name'])
  25. end
  26. )
  27. o.default = uci:get('autoupdater', autoupdater, 'branch')
  28. function o:write(data)
  29. uci:set('autoupdater', autoupdater, 'branch', data)
  30. end
  31. o = s:option(Value, "minute", translate("Minute"), pkg_i18n.translate(
  32. "This value forces the autoupdater to check for updates at the "
  33. .. "specified minute. Normally there is no need to set this value "
  34. .. "because it is selected automatically. You may want to set this to "
  35. .. "a specific value if you have multiple nodes which should not "
  36. .. "update at the same time."
  37. ))
  38. o.datatype = "irange(0, 59)"
  39. o.default = uci:get("gluon", "autoupdater", "minute")
  40. o.optional = true
  41. function o:write(data)
  42. if data == uci:get("gluon", "autoupdater", "minute") then
  43. return
  44. end
  45. uci:set("gluon", "autoupdater", "minute", data)
  46. if data then
  47. local f = io.open("/usr/lib/micron.d/autoupdater", "w")
  48. f:write(string.format("%i 4 * * * /usr/sbin/autoupdater\n", data))
  49. f:write(string.format("%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n", data))
  50. f:close()
  51. end
  52. end
  53. local s = f:section(Section, translate('Wifi fallback updates'))
  54. o = s:option(Flag, 'enabled', translate('Enable'))
  55. o.default = uci:get_bool('autoupdater-wifi-fallback', wifi_fallback, 'enabled')
  56. function o:write(data)
  57. uci:set('autoupdater-wifi-fallback', wifi_fallback, 'enabled', data)
  58. uci:commit('autoupdater-wifi-fallback')
  59. end
  60. function f:write()
  61. uci:commit('autoupdater')
  62. uci:commit("gluon")
  63. end
  64. return f