#!/bin/bash

IFFILE=/tmp/$IFACE.started
METRIC=50


export DEBIAN_FRONTEND=noninteractive

if [ "$IFACE" = 'eth1' ] || [ "$IFACE" = 'wlan0' ]; then
  CARRIER=$(cat /sys/class/net/"$IFACE"/carrier)
  if [ "$CARRIER" = '1' ]; then
    touch $IFFILE
    systemctl stop quectel-ppp.service
    GATEWAY=$(cat /etc/resolv.conf|grep -im 1 '^nameserver' |cut -d ' ' -f2)
    ip route add default via "${GATEWAY}" dev "${IFACE}" proto static metric "${METRIC}"
    #systemctl restart ssh_vpn.service
  fi
fi

exit 0

