#!/bin/sh -e

# $Rev: 810 $

export PATH=/sbin:/bin:/usr/sbin:/usr/bin
MV=`which mv`
RM=`which rm`
TOUCH=`which touch`
CHMOD=`which chmod`
ETC="/etc"
TMP="/tmp"
RESOLVCONF=$(readlink --canonicalize $ETC/resolv.conf)
BACKRESOLV="$RESOLVCONF.pppd-backup"
VMCCONN="$TMP/vmc-conn.lock"

! test -f "$VMCCONN" || exit 0

# remove connection lock
rm -f $VMCCONN

# is dhclient running?
DHCP=`ps aux | grep dhclient | grep -v grep`

if [ -n "$DHCP" ]; then
	# we are going to back up resolv.conf
	$MV $BACKRESOLV $RESOLVCONF
	# restart nscd because resolv.conf has changed
	if [ -e /var/run/nscd.pid ]; then
      		/etc/init.d/nscd restart || true
	fi
fi

# Remove back up file if it exists
[ -f $BACKRESOLV ] && rm -f $BACKRESOLV
