#!/bin/sh
#----------------------------------------------------------------------------
# /etc/ppp/ip-up200.dnsmasq - called whenever a (i)ppp connection
# over default circuit has been come up and dnsmasq is installed
#
# Creation:     ??.??.2003  lanspezi
# Last Update:  $Id: ip-up200.dnsmasq 8079 2005-03-23 21:22:53Z lanspezi $
#----------------------------------------------------------------------------
# back up etc/resolv.dnsmasq to etc/resolv.dnsmasq.bak
# if provider supports sending ip(s) of dns server(s)
#----------------------------------------------------------------------------

# is a default-route-interface going up?
if [ "$is_default_route" = "yes" ]
then
  # $interface.usepeerdns existing?
  if [ -f /var/run/$interface.usepeerdns ]
  then
    usepeerdns=`cat /var/run/$interface.usepeerdns` # set usepeerdns yes or no
  else
    usepeerdns='no'
  fi

  if [ "$usepeerdns" = "yes" ]
  then
    # pppd sets DNS1 and DNS2
    if [ "$DNS1" -o "$DNS2" ]
    then
      resolv_file=/etc/resolv.dnsmasq
      
      mv $resolv_file $resolv_file.bak
      echo "# x_USEPEERDNS is set">$resolv_file
      for dns in $DNS1 $DNS2
      do
        echo "nameserver $dns">>$resolv_file
      done
      chown dns:dns $resolv_file
      killall -HUP dnsmasq
    else
      echo "Your provider didn't send nameserver addresses, forwarders not changed"
    fi
  fi
fi

