500-autoupdater 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site_config'
  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 in case no specific
  32. -- time is specified (gluon.autoupdater.minute), and once an hour a fallback
  33. -- update (used after the regular updates haven't worked for (priority+1) days
  34. -- after a firmware release, for example because the node is always offline at
  35. -- night)
  36. if not uci:get('gluon', 'autoupdater') then
  37. uci:section('gluon', 'autoupdater', 'autoupdater')
  38. uci:save('gluon')
  39. end
  40. local minute = uci:get('gluon', 'autoupdater', 'minute') or math.random(0, 59)
  41. local f = io.open('/usr/lib/micron.d/autoupdater', 'w')
  42. f:write(string.format('%i 4 * * * /usr/sbin/autoupdater\n', minute))
  43. f:write(string.format('%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n', minute))
  44. f:close()