Skip to content

Instantly share code, notes, and snippets.

@pdcastro
Created September 7, 2019 01:36
Show Gist options
  • Save pdcastro/993c53b0edd0bd68343333d12bac3719 to your computer and use it in GitHub Desktop.
Save pdcastro/993c53b0edd0bd68343333d12bac3719 to your computer and use it in GitHub Desktop.
fix_route function for the provisioning container
#!/bin/bash
...
fix_route () {
good_wifi=$(ip route | perl -ne '/default\s+via\s+(\S+).+?metric\s+600/; if ($1) {print $1; exit}')
good_eth0=$(ip route | perl -ne '/default\s+via\s+(\S+).+?metric\s+100/; if ($1) {print $1; exit}')
bad_eth0=$(ip route | perl -ne '/default\s+via\s+(\S+).+?metric\s+20100/; if ($1) {print $1; exit}')
# if there are no good routes with metrics 100 or 600, and there is a "bad"
# route with metric 20100, assume the bad route is actually good and use it
if [ -z "$good_wifi" -a -z "$good_eth0" -a -n "$bad_eth0" ]; then
echo ip route add 0.0.0.0/0 via "$bad_eth0" metric 100
fi
}
while true; do
fix_route
provisioning
echo "*** provisioning exited; waiting 5s before trying again"
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment