#!/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=$(ip route list | sed -n -e "s/^default.*[[:space:]]\([[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\).*/\1/p")
    ip route add default via "${GATEWAY}" dev "${IFACE}" proto static metric "${METRIC}"
    #systemctl restart ssh_vpn.service
  fi
fi

exit 0

