#!/bin/sh

# usepeerdns by Eduard Bloch, 12 Sep 2001.

# pppconfig is installed, it will do the job

test -f /etc/ppp/ip-up.d/0dns-up -a -f /usr/sbin/pppconfig && exit 0

BAKFILE=/etc/resolv.conf.bak.`date +%s`

# save to the backup file
cat /etc/resolv.conf > $BAKFILE

# If the usepeerdns option is used, merge the existing and the suggested
# resolv.conf

if [ "$USEPEERDNS" ] ; then
    cat /etc/resolv.conf /etc/ppp/resolv.conf | sort | uniq > /etc/resolv.conf.merge
    # workaround for symlinks
    cat /etc/resolv.conf.merge > /etc/resolv.conf
fi

# don't create dupes

if cmp $BAKFILE /etc/resolv.conf.backup; then
  rm $BAKFILE
else
# save the old backup file as another file
  cat /etc/resolv.conf.backup > "$BAKFILE.before"
# save new backup file as default backup file
  cat $BAKFILE > /etc/resolv.conf.backup
# remove the copy
  rm  $BAKFILE
fi

# Tell nscd about what we've done.
test -x /usr/sbin/nscd || exit 0
/usr/sbin/nscd -i hosts || exit 0
