500-autoupdater 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site'
  3. local uci = require('simple-uci').cursor()
  4. for name, config in pairs(site.autoupdater.branches()) do
  5. uci:delete('autoupdater', name)
  6. uci:section('autoupdater', 'branch', name, {
  7. name = config.name,
  8. mirror = config.mirrors,
  9. good_signatures = config.good_signatures,
  10. pubkey = config.pubkeys,
  11. })
  12. end
  13. if not uci:get('autoupdater', 'settings') then
  14. local enabled = false
  15. local branch = site.autoupdater.branch()
  16. local f = io.open('/lib/gluon/autoupdater/default_branch')
  17. if f then
  18. enabled = true
  19. branch = f:read('*line')
  20. f:close()
  21. end
  22. uci:section('autoupdater', 'autoupdater', 'settings', {
  23. enabled = enabled,
  24. branch = branch,
  25. })
  26. end
  27. uci:set('autoupdater', 'settings', 'version_file', '/lib/gluon/release')
  28. uci:save('autoupdater')
  29. local autoupdater_util = require 'autoupdater.util'
  30. autoupdater_util.randomseed()
  31. -- Perform updates at a random time between 04:00 and 05:00, and once an hour
  32. -- a fallback update (used after the regular updates haven't worked for
  33. -- (priority+1) days after a firmware release, for example because the node
  34. -- is always offline at night)
  35. local minute = math.random(0, 59)
  36. local f = io.open('/usr/lib/micron.d/autoupdater', 'w')
  37. f:write(string.format('%i 4 * * * /usr/sbin/autoupdater\n', minute))
  38. f:write(string.format('%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n', minute))
  39. f:close()