#!/bin/bash

[[ -n "$DEBUG" ]] && set -x

interface="$(ip link show | awk '/ ppp/ {print substr($2, 1, length($2)-1)}')"
addr="$(ip addr show dev "$interface" | awk '/inet / {print $2}')"
resolved="$(dig +short "${domain}" A)"

if [[ -z "$addr" ]] || [[ -z "$resolved" ]]
then
    echo "Address on '$interface' is '$addr' - resolved '$resolved'"
    exit 3
elif [[ "$addr" == "$resolved" ]]
then
    echo "Resolved IP for ${domain} matches current ip on $interface"
    exit 0
else
    echo "Resolved $resolved for ${domain}, but got $addr on $interface!"
    exit 2
fi
