#!/bin/sh -e

# $Rev$

PATH=/sbin:/bin:/usr/sbin:/usr/bin
RM=`which rm`
TOUCH=`which touch`
ETC="/etc"
TMP="/tmp"
RESOLVCONF="$ETC/resolv.conf"
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'}`

# write new resolv.conf
# we can safely write the new DNS config as ip-down will restore it for us
$RM $RESOLVCONF
$TOUCH $RESOLVCONF

cat >> $RESOLVCONF <<-EOA
nameserver $PRIMARYDNS
nameserver $SECONDARYDNS
EOA

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

