510-autoupdater-wifi-fallback 1.2 KB

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