From e2ad43fb4fd297b1c35abeac2f34170ee801b1cc Mon Sep 17 00:00:00 2001 From: Mikkel Kirkgaard Nielsen Date: Tue, 15 Mar 2022 23:29:28 +0100 Subject: [PATCH] Add list mode and colors to dnsmasqctl --- dnsmasqctl | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/dnsmasqctl b/dnsmasqctl index f7c1eb3..e8ffc6a 100755 --- a/dnsmasqctl +++ b/dnsmasqctl @@ -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 -- 2.34.4