500-autoupdater 1.3 KB

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