wait-for-routes 975 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. #
  3. # Wait for routing adjacencies to come up and produce a default route
  4. #
  5. # Maximilian Wilhelm <max@sdn.clinic>
  6. # -- Mon, 05 Apr 2021 02:31:58 +0200
  7. # Wait for this amount of seconds before giving up
  8. timeout=30
  9. # Wait for IPv4 default route to emerge
  10. (
  11. for n in $(seq 1 $timeout); do
  12. # If there is an IPv4 default route, stop waiting
  13. if ip -4 route | grep -q "^default"; then
  14. break
  15. fi
  16. sleep 1
  17. done
  18. )&
  19. # Wait for IPv6 default route to emerge
  20. (
  21. for n in $(seq 1 $timeout); do
  22. # If there is an IPv6 default route, stop waiting
  23. if ip -6 route | grep -q "^default"; then
  24. break
  25. fi
  26. sleep 1
  27. done
  28. )&
  29. # Wait for IPv6 IPs do leave tentative state
  30. # This will most likely be only relevant for nodes with static IPs/route
  31. (
  32. for n in $(seq 1 $timeout); do
  33. # If there is an IPv6 in state tentative, wait on
  34. if ip -6 addr | grep -q "tentative"; then
  35. sleep 1
  36. else
  37. break
  38. fi
  39. done
  40. )&
  41. # WAit for both sub-shells to finish
  42. wait
  43. exit 0