#!/bin/sh

# 01dns-up-totd sets up /etc/resolv.conf for the provider being connected to.
# In conjunction with pppd's usepeerdns option it also handles dynamic dns.
# It expects to be passed the provider name in PPP_IPPARAM.

# If pppconfig has been removed we are not supposed to do anything.

test -f /usr/sbin/pppconfig || exit 0

# If resolv.conf has been removed we can't do anything.

test -f /etc/resolv.conf || exit 0

# If /etc/resolv.conf is not replaced by totd, we don't do anything.
grep "created by totd" /etc/resolv.conf || exit 0

PROVIDER="$PPP_IPPARAM"
ETC="/etc"
RUNDIR="/var/run/totd"

TOTD_CONF="$RUNDIR/totd.conf"

# Security: we sit in the $ETC directory while we do our work.

cd "$ETC" || exit 1

killall totd
test -f $TOTD_CONF && rm -f $TOTD_CONF
/etc/init.d/totd start
