510-autoupdater-wifi-fallback 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/lua
  2. local uci = require 'luci.model.uci'.cursor()
  3. local util = require 'gluon.util'
  4. local fs = require('nixio.fs')
  5. local enabled = uci:get('autoupdater','settings','enabled')
  6. if uci:get('autoupdater-wifi-fallback', 'settings') then
  7. enabled = uci:get_bool('autoupdater-wifi-fallback', 'settings', 'enabled') and 1 or 0
  8. uci:delete('autoupdater-wifi-fallback', 'settings')
  9. end
  10. uci:section('autoupdater-wifi-fallback','autoupdater-wifi-fallback','settings',
  11. {
  12. enabled = enabled,
  13. }
  14. )
  15. uci:delete('wireless', 'fallback')
  16. uci:delete('network','fallback')
  17. uci:delete('network','fallback6')
  18. uci:section('network', 'interface', 'fallback',
  19. {
  20. proto = 'dhcp',
  21. peerdns = 1,
  22. sourcefilter = 0,
  23. }
  24. )
  25. uci:section('network', 'interface', 'fallback6',
  26. {
  27. ifname = '@fallback',
  28. proto = 'dhcpv6',
  29. peerdns = 1,
  30. sourcefilter = 0,
  31. }
  32. )
  33. uci:save('autoupdater-wifi-fallback')
  34. uci:save('network')
  35. uci:save('wireless')
  36. local minute = tonumber(fs.readfile('/usr/lib/micron.d/autoupdater'):match('^([0-9][0-9]?)%s'))
  37. minute = (minute + 10) % 60
  38. local f = io.open('/usr/lib/micron.d/autoupdater-wifi-fallback', 'w')
  39. f:write(string.format('%i * * * * /usr/sbin/autoupdater-wifi-fallback\n', minute))
  40. f:close()