~mikini/hometools

e2ad43fb4fd297b1c35abeac2f34170ee801b1cc — Mikkel Kirkgaard Nielsen 3 months ago 92802c9
Add list mode and colors to dnsmasqctl
1 files changed, 29 insertions(+), 9 deletions(-)

M dnsmasqctl
M dnsmasqctl => dnsmasqctl +29 -9
@@ 1,26 1,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
      if read -p "disable $f? "; then
          if [ "$REPLY" = "y" ]; then
              sudo rm /etc/dnsmasq.d/$f
      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
      if read -p "enable $f? "; then
          if [ "$REPLY" = "y" ]; then
              sudo ln -sv /etc/dnsmasq.d-available/$f /etc/dnsmasq.d/
      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 read -p "restart dnsmasq? "; then
    if [ "$REPLY" = "y" ]; then
        sudo systemctl restart dnsmasq
if [ ! $LIST ]; then
    if read -p "restart dnsmasq? "; then
        if [ "$REPLY" = "y" ]; then
            sudo systemctl restart dnsmasq
        fi
    fi
fi