routing-rest.sh 636 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. # Sometimes the connection does down and we lose our route to
  3. # the VPN. Re-insert the route if it goes down.
  4. IP_FMT="[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"
  5. # This route should be the only hard-coded IP address
  6. ROUTE=$(ip route | grep "^$IP_FMT via $IP_FMT dev")
  7. # OpenVPN might not have started yet. Repeat until route appears
  8. while [ -z "$ROUTE" ]; do
  9. sleep 1
  10. ROUTE=$(ip route | grep "^$IP_FMT via $IP_FMT dev")
  11. done
  12. # Loop forever
  13. while true; do
  14. # Check that the route still exists, add it if it doesn't
  15. if ! ip route | grep -q "$ROUTE"; then
  16. echo "Fixing routing..."
  17. ip route add $ROUTE
  18. fi
  19. sleep 1
  20. done