#! /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