From c4f9a475f3cc6d78deac5aa2fb61b191978cf638 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 11 Jul 2022 01:34:51 -0300 Subject: [PATCH 1/2] Debug log - add spinner for long processes Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 2f4b0011..02b6ed64 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1230,7 +1230,7 @@ check_dhcp_servers() { OLD_IFS="$IFS" IFS=$'\n' local entries=() - mapfile -t entries < <(pihole-FTL dhcp-discover) + mapfile -t entries < <(pihole-FTL dhcp-discover & spinner) for line in "${entries[@]}"; do log_write " ${line}" @@ -1309,7 +1309,7 @@ database_integrity_check(){ local database="${1}" log_write "${INFO} Checking integrity of ${database} ... (this can take several minutes)" - result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1)" + result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1 & spinner)" if [[ ${result} = "ok" ]]; then log_write "${TICK} Integrity of ${database} intact" @@ -1345,6 +1345,34 @@ check_database_integrity() { database_integrity_check "${PIHOLE_FTL_DB_FILE}" } +# Show a text spinner during a long process run +# +spinner(){ + local PID=$! # PID of the most recent background process + local spin="/-\|" + local start=0 + local elapsed=0 + local i=1 + + start=$(date +%s) # Start the counter + + tput civis > /dev/tty # Hide the cursor + trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit + + while [ -d /proc/$PID ]; do + elapsed=$(( $(date +%s) - start )) + # print the spinner only on screen (tty) - use hours only if needed + if [ "$elapsed" -lt 3600 ]; then + printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)" + else + printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)" + fi + sleep 0.25 + done + + printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten) + tput cnorm > /dev/tty # Restore cursor visibility +} obfuscated_pihole_log() { local pihole_log=("$@") From cbcd12631d5674c2f508089a3e2056de592c460c Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 11 Jul 2022 01:53:30 -0300 Subject: [PATCH 2/2] Adding the spinner for foreign_key_check too Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 02b6ed64..2e902903 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1316,7 +1316,7 @@ database_integrity_check(){ log_write "${INFO} Checking foreign key constraints of ${database} ... (this can take several minutes)" unset result - result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1)" + result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1 & spinner)" if [[ -z ${result} ]]; then log_write "${TICK} No foreign key errors in ${database}" else