#!/bin/sh -e

# $Rev: 1186 $

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"

# Does VMCCONN exists?
test -f "$VMCCONN" || exit 0

# get DNS addresses

PRIMARYDNS=`grep DNS1 $VMCCONN | awk {'print $2'}`
SECONDARYDNS=`grep DNS2 $VMCCONN | awk {'print $2'}`

# Back up resolv.conf
# Other backup file can have been created by other script
if [ ! -f $BACKRESOLV ]
then
      $MV $RESOLVCONF $BACKRESOLV
fi

# create new resolv.conf
cat > $RESOLVCONF <<-EOA
nameserver $PRIMARYDNS
nameserver $SECONDARYDNS
EOA

# on Fedora 7 umask leaves /etc/resolv.conf as 0600
$CHMOD 644 $RESOLVCONF

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

