From 3631d1349ebe06ad804df8ca4ba008ca1b917433 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sat, 15 Jul 2017 20:11:06 +1000 Subject: [PATCH] Prevent Web Admin from printing restartdns colour codes (#1575) * Prevent Web Admin from printing unnecessary msgs * Make DNS restart behaviour consistent --- advanced/Scripts/webpage.sh | 17 +++++++++-------- pihole | 24 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5aae18f7..42272122 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -221,18 +221,19 @@ Reboot() { } RestartDNS() { - local str="Restarting dnsmasq" - echo -ne " ${INFO} ${str}..." - if [[ -x "$(command -v systemctl)" ]]; then - systemctl restart dnsmasq + local str="Restarting DNS service" + [[ -t 1 ]] && echo -ne " ${INFO} ${str}" + if command -v systemctl &> /dev/null; then + output=$( { systemctl restart dnsmasq; } 2>&1 ) else - service dnsmasq restart + output=$( { service dnsmasq restart; } 2>&1 ) fi - if [[ "$?" == 0 ]]; then - echo -e "${OVER} ${TICK} ${str}" + if [[ -z "${output}" ]]; then + [[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}" else - echo -e "${OVER} ${CROSS} ${str}" + [[ ! -t 1 ]] && OVER="" + echo -e "${OVER} ${CROSS} ${output}" fi } diff --git a/pihole b/pihole index 3c321b93..b4b5e886 100755 --- a/pihole +++ b/pihole @@ -173,24 +173,32 @@ versionFunc() { restartDNS() { dnsmasqPid=$(pidof dnsmasq) + local str="Restarting DNS service" + echo -ne " ${INFO} ${str}" if [[ "${dnsmasqPid}" ]]; then # Service already running - reload config - echo -ne " ${INFO} Restarting dnsmasq" if [[ -x "$(command -v systemctl)" ]]; then - systemctl restart dnsmasq + output=$( { systemctl restart dnsmasq; } 2>&1 ) else - service dnsmasq restart + output=$( { service dnsmasq restart; } 2>&1 ) + fi + if [[ -z "${output}" ]]; then + echo -e "${OVER} ${TICK} ${str}" + else + echo -e "${OVER} ${CROSS} ${output}" fi - [[ "$?" == 0 ]] && echo -e "${OVER} ${TICK} Restarted dnsmasq" || echo -e "${OVER} ${CROSS} Failed to restart dnsmasq" else # Service not running, start it up - echo -ne " ${INFO} Starting dnsmasq" if [[ -x "$(command -v systemctl)" ]]; then - systemctl start dnsmasq + output=$( { systemctl start dnsmasq; } 2>&1 ) else - service dnsmasq start + output=$( { service dnsmasq start; } 2>&1 ) + fi + if [[ -z "${output}" ]]; then + echo -e "${OVER} ${TICK} ${str}" + else + echo -e "${OVER} ${CROSS} ${output}" fi - [[ "$?" == 0 ]] && echo -e "${OVER} ${TICK} Restarted dnsmasq" || echo -e "${OVER} ${CROSS} Failed to restart dnsmasq" fi }