#!/bin/sh -e

# $Rev: 810 $

DEV="$1"
IPPARAM="$6"

export PATH=/sbin:/bin:/usr/sbin:/usr/bin
ETC="/etc"
TMP="/tmp"
ROUTEBACK="${TMP}/defaultroute.vmc"
VMCCONN="${TMP}/vmc-conn.lock"

# Make sure we are only being called by a vmc invoked pppd
[ "${IPPARAM}" = "vmc" ] || exit 0

# Ubuntu8 manages DNS for us if we are gleaning info from the mobile network
# but if we have static settings we have to do it ourselves

# follow any symlink to find the real file
REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)

if [ -f "$REALRESOLVCONF.vmc" ] ; then
	mv -f "$REALRESOLVCONF.vmc" "$REALRESOLVCONF"

	# restart nscd because resolv.conf has changed
	if [ -e /var/run/nscd.pid ]; then
		/etc/init.d/nscd restart || true
	fi
fi
rm -f ${VMCCONN}


# now replace original default route
if [ -f ${ROUTEBACK} ] ; then
	. ${ROUTEBACK} # source it

	if [ -n "${OLDGW}" ] ; then
		route add default gw ${OLDGW}
	fi

	rm -f ${ROUTEBACK}
fi


