3
# Script to update the resolver list for dnsmasq
5
# N.B. Resolvconf may run us even if dnsmasq is not running.
6
# If dnsmasq is installed then we go ahead and update
7
# the resolver list in case dnsmasq is started later.
9
# Assumption: On entry, PWD contains the resolv.conf-type files
11
# Depends: resolvconf (>= 1.14)
13
# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
16
# June 2003 - June 2004: Written by Thomas Hood <jdthood@yahoo.co.uk>
20
RUN_DIR="/var/run/dnsmasq"
21
RSLVRLIST_FILE="${RUN_DIR}/resolv.conf"
22
TMP_FILE="${RSLVRLIST_FILE}_new.$$"
24
[ -x /usr/sbin/dnsmasq ] || exit 0
25
[ -x /lib/resolvconf/list-records ] || exit 1
29
report_err() { echo "$0: Error: $*" >&2 ; }
31
# Stores arguments (minus duplicates) in RSLT, separated by spaces
32
# Doesn't work properly if an argument itself contain whitespace
38
[ "$1" = "$E" ] && { shift ; continue 2 ; }
40
RSLT="${RSLT:+$RSLT }$1"
45
if [ ! -d "$RUN_DIR" ] && ! mkdir --parents --mode=0755 "$RUN_DIR" ; then
46
report_err "Failed trying to create directory $RUN_DIR"
50
RSLVCNFFILES="$(/lib/resolvconf/list-records | sed -e '/^lo.dnsmasq$/d')"
53
if [ "$RSLVCNFFILES" ] ; then
54
uniquify $(sed -n -e 's/^[[:space:]]*nameserver[[:space:]]\+//p' $RSLVCNFFILES)
58
clean_up() { rm -f "$TMP_FILE" ; }
61
for N in $NMSRVRS ; do echo "nameserver $N" >> "$TMP_FILE" ; done
62
mv -f "$TMP_FILE" "$RSLVRLIST_FILE"