500-autoupdater 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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, and once an hour
  32. -- a fallback update (used after the regular updates haven't
  33. local minute = math.random(0, 59)
  34. local f = io.open('/usr/lib/micron.d/autoupdater', 'w')
  35. f:write(string.format('%i 4 * * * /usr/sbin/autoupdater\n', minute))
  36. f:write(string.format('%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n', minute))
  37. f:close()