#!/bin/bash

# IP config script for PPP interfaces.
#
# The regular if-up scripts used by ifup (under /etc/network/if-up.d/)
# cannot be used as they may be executed before the IP protocol has
# come up in the PPP link.

# The resolv.conf file where pppd leaves the name servers
PPPRESOLVCONF=/etc/ppp/resolv.conf

[ -n "$PPP_IFACE" ] || exit 1

# Setup the default route through the interface
# (use 'replace' as a default route may already be present)
ip route replace default dev "$PPP_IFACE" scope global

# Setup /etc/resolv.conf for from provided config
if [ -n "$DNS1" -o -n "$DNS2" ] && [ -f "$PPPRESOLVCONF" ]; then
    cat "$PPPRESOLVCONF" > /etc/resolv.conf
else
    cat /dev/null > /etc/resolv.conf
fi

# Make sure nscd catches the changed /etc/resolv.conf
nscd -i hosts

# Check that ntpd got all its servers OK and check for IP address change
/etc/spinetix/ntp-check --force

exit 0
