Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRD WebDesign <github@rdwebdesign.com.br>2022-07-11 07:34:51 +0300
committerRD WebDesign <github@rdwebdesign.com.br>2022-07-11 07:34:51 +0300
commitc4f9a475f3cc6d78deac5aa2fb61b191978cf638 (patch)
tree7780c7dd515e7ac6088b91ebf3d8bf3e52616e0b /advanced
parent71d310c50f45b568bb19edaac46c6a8722e24ce1 (diff)
Debug log - add spinner for long processes
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
Diffstat (limited to 'advanced')
-rwxr-xr-xadvanced/Scripts/piholeDebug.sh32
1 files 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=("$@")