From 16cd587e577b09e82d6c7aa35dd298ae752e7691 Mon Sep 17 00:00:00 2001 From: Claudio Pisa <claudio.pisa@garr.it> Date: Tue, 20 Aug 2019 06:59:19 +0000 Subject: [PATCH] simplify code --- hooks/install | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/hooks/install b/hooks/install index 0351885..227d4df 100644 --- a/hooks/install +++ b/hooks/install @@ -21,25 +21,21 @@ RELEASE_MAJOR="$( echo $DISTRIB_RELEASE | awk -F '.' '{print $1}' )" if [ "$RELEASE_MAJOR" -le "16" ]; then # Ubuntu release is less or equal than trusty - # copy metric 0 routes to routes with metric 1 - ip route show | grep "^default" | grep -v metric | while read line; do - ip route append $line metric 1 || true - done - # delete metric 0 routes - ip route show | grep "^default" | grep -v metric | while read line; do - ip route del $line metric 0 - done + defaultroutecommand="ip route show | grep ^default | grep -v metric" else - # copy metric 0 routes to routes with metric 1 - ip route show default metric 0 | while read line; do - ip route append $line metric 1 || true - done - # delete metric 0 routes - ip route show default metric 0 | while read line; do - ip route del $line metric 0 - done + defaultroutecommand="ip route show default metric 0" fi +# copy metric 0 routes to routes with metric 1 +eval $defaultroutecommand | while read line; do + ip route append $line metric 1 || true +done + +# delete metric 0 routes +eval $defaultroutecommand | while read line; do + ip route del $line metric 0 +done + # add our route if ip route replace default via $GATEWAY_IP metric 0; then juju-log "Default gateway set" -- GitLab