#!/bin/sh

get_interface_priority()
{
  awk -v IFACE=$1 -v TARGET=metrics -F ' *= *' '
  {
    if ($0 ~ /^\[.*\]$/) {
      gsub(/^\[|\]$/, "", $0)
      SECTION=$0
    } else if (($1 == IFACE) && (SECTION==TARGET)) {
      print $2
    }
  }
  ' /etc/network-manager.ini
}

route -n | grep $1 | grep ^0.0.0.0 &>/dev/null
if [[ $? -ne 0 ]]; then
   metric=$(get_interface_priority "$1")
   route add default gw $5 metric "$metric" | logger
fi

if [[ -e /etc/ppp/resolv.conf ]];then
    cat /etc/ppp/resolv.conf | resolvconf -a "$1.udhcpc"
    rm -f /etc/ppp/resolv.conf
fi

