~mikini/hometools

ref: e2ad43fb4fd297b1c35abeac2f34170ee801b1cc hometools/dnsmasqctl -rwxr-xr-x 1.0 KiB
e2ad43fb — Mikkel Kirkgaard Nielsen Add list mode and colors to dnsmasqctl 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /bin/bash

if [ "$1" = "--list" -o "$1" = "-l" ]; then
    LIST=1
fi

for fp in /etc/dnsmasq.d-available/*; do
  f=$(basename $fp)
  if [ -h /etc/dnsmasq.d/$f ]; then
      echo -ne "\e[32m"
      if [ $LIST ]; then
          echo $f: enabled
      else
          echo -n "disable $f? "
          if read; then
              if [ "$REPLY" = "y" ]; then
                  sudo rm /etc/dnsmasq.d/$f
              fi
          fi
      fi
      echo -ne "\e[0m"
  elif [ ! -f /etc/dnsmasq.d/$f ]; then
      echo -ne "\e[31m"
      if [ $LIST ]; then
          echo $f: disabled
      else
          echo -n "enable $f? "
          if read; then
              if [ "$REPLY" = "y" ]; then
                  sudo ln -sv /etc/dnsmasq.d-available/$f /etc/dnsmasq.d/
              fi
          fi
      fi
      echo -ne "\e[0m"
  else
      echo non-link file already present in /etc/dnsmasq.d/$f.
  fi
done

if [ ! $LIST ]; then
    if read -p "restart dnsmasq? "; then
        if [ "$REPLY" = "y" ]; then
            sudo systemctl restart dnsmasq
        fi
    fi
fi