1#!/bin/bash
2#
3# Borrowing heavily from the dnsmasq initscript's version of support for
4# resolvconf, intended for use in systemd-only configurations.
5#
6PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
7DAEMON=/usr/sbin/dnsmasq
8NAME=dnsmasq
9
10# Most configuration options in /etc/default/dnsmasq are deprecated
11# but still honoured.
12if [ -r /etc/default/$NAME ]; then
13   . /etc/default/$NAME
14fi
15
16start_resolvconf()
17{
18   # If interface "lo" is explicitly disabled in /etc/default/dnsmasq
19   # Then dnsmasq won't be providing local DNS, so don't add it to
20   # the resolvconf server set.
21   for interface in $DNSMASQ_EXCEPT
22   do
23      [ $interface = lo ] && return
24   done
25
26   if [ -x /sbin/resolvconf ] ; then
27      echo "nameserver 127.0.0.1" |
28      /sbin/resolvconf -a lo.$NAME
29   fi
30   return 0
31}
32
33stop_resolvconf()
34{
35   if [ -x /sbin/resolvconf ] ; then
36      /sbin/resolvconf -d lo.$NAME
37   fi
38   return 0
39}
40
41case "$1" in
42   start)
43      start_resolvconf
44      exit 0
45      ;;
46   stop)
47      stop_resolvconf
48      exit 0
49      ;;
50   restart)
51      stop_resolvconf
52      start_resolvconf
53      exit 0
54      ;;
55   *)
56      echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
57      exit 3
58      ;;
59esac
60
61exit 0
62
63