#!/bin/sh
#
# resolvconf
#
# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
#
# History
# Jun2003-Jan2004: Written by Thomas Hood <jdthood@yahoo.co.uk>

set -e

PATH=/bin:/sbin
MYNAME="${0##*/}"
# Note that /etc/resolvconf/run may be a symlink
RUNDIR=/etc/resolvconf/run
IFACEDIR="${RUNDIR}/interface"
DISABLE_UPDATES_FLAGFILE="${RUNDIR}/disable-updates"

report_err()
{
	echo "${MYNAME}: Error: $*" >&2
}

update()
{
	[ -e "$DISABLE_UPDATES_FLAGFILE" ] && return
	cd "$IFACEDIR"
	# "update" scripts must assume that interface files are in PWD
	run-parts "${1:+--arg=$1}" "${2:+--arg=$2}" /etc/resolvconf/update.d
}

if [ ! -d "$IFACEDIR" ] ; then
	report_err "$IFACEDIR is not a directory, as it should be.  Exiting."
	exit 1
fi

[ "$1" ] || { report_err "No arguments supplied.  Exiting." ; exit 1 ; }
IFACE="${2##*/}"
[ "$IFACE" ] || { report_err "No interface name specified.  Exiting." ; exit 1 ; }

case "$1" in
	-a) sed 's/#.*//' - > "${IFACEDIR}/$IFACE" ;;
	-d) rm -f "${IFACEDIR}/$IFACE" ;;
esac

update "$1" "$2"

