#!/bin/sh

set -e

. /usr/share/debconf/confmodule

adequate_eni()
{
	# Assume that if _any_ dns-nameservers line appears in
	# /etc/network/interfaces then that is adequate and we
	# don't need to ask the user if he wants to link the
	# original file to the dynamic file at medium priority
	grep -q dns-nameservers /etc/network/interfaces > /dev/null
}

case $1 in
configure|reconfigure)
	db_input low resolvconf/linkify-resolvconf || :
	db_go || :
	db_get resolvconf/linkify-resolvconf
	if \
		[ "$RET" = "true" ] \
		&& [ ! -e /etc/resolvconf/resolv.conf.d/tail ] \
		&& [ ! -L /etc/resolvconf/resolv.conf.d/tail ]
	then
		if adequate_eni ; then
			db_input low resolvconf/link-tail-to-original || :
		else
			db_input medium resolvconf/link-tail-to-original || :
		fi
		db_go || :
	else
		db_set resolvconf/link-tail-to-original false
	fi

	db_input medium resolvconf/downup-interfaces || :
	db_go || :
	;;
esac

db_stop

