500-autoupdater 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. c:commit('autoupdater')
  35. local autoupdater_util = require 'autoupdater.util'
  36. autoupdater_util.randomseed()
  37. -- Perform updates at a random time between 04:00 and 05:00, and once an hour
  38. -- a fallback update (used after the regular updates haven't
  39. local minute = math.random(0, 59)
  40. local f = io.open('/lib/gluon/cron/autoupdater', 'w')
  41. f:write(string.format('%i 4 * * * /usr/sbin/autoupdater\n', minute))
  42. f:write(string.format('%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n', minute))
  43. f:close()