wifiwan-check.sh 821 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. . /lib/functions/network.sh
  3. ## if wan is wireless
  4. unset _COUNT
  5. while network_get_physdev _IFNAME wan && [[ ! $_IFNAME =~ 'wlan' ]]; do
  6. let _COUNT++
  7. if [[ $_COUNT -ge 30 ]]; then
  8. echo 'wan is not wifi'
  9. exit
  10. fi
  11. echo "waiting for wan conf.. $((30-$_COUNT))"
  12. sleep 1
  13. done
  14. checkWan() {
  15. if [[ "$(iw $_IFNAME link)" =~ 'Connected ' ]]; then
  16. if [[ "$(route | grep $_IFNAME)" =~ '0.0.0.0' ]]; then
  17. return 1
  18. fi
  19. fi
  20. return 0
  21. }
  22. ## if wan is connected and is default gw
  23. unset _COUNT
  24. while checkWan; do
  25. let _COUNT++
  26. if [[ $_COUNT -ge 60 ]]; then
  27. echo 'wan wifi is dead, disabling'
  28. uci set wireless.@wifi-iface[-1].disabled=1
  29. uci commit wireless
  30. wifi
  31. exit
  32. fi
  33. echo "waiting for wan wifi.. $((60-$_COUNT))"
  34. sleep 1
  35. done
  36. echo 'wan wifi is connected'
  37. exit