From f0657be289575a17b94c8cdcb9f6e11b923c75f1 Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Thu, 16 Oct 2025 20:50:42 +0200 Subject: [PATCH 1/7] Add availability checker for remote services based on ping and timeout --- dzgui.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dzgui.sh b/dzgui.sh index 33fb0d1..8585251 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -493,6 +493,22 @@ stale_symlinks(){ unlink "$l" done } + +check_availability() { + if [[ -z $1 ]]; then + return 1 + fi + local url=$1 + local timeout_sec="3" + if [[ $2 ]]; then + timeout_sec=$2 + fi + if ! ping -w "$timeout_sec" "$url"; then + logger WARN "Failed to reach $url, service may be down." + return 1 + fi +} + local_latlon(){ if [[ -z $(command -v dig) ]]; then local local_ip=$(curl -Ls "https://ipecho.net/plain") From 83552f833cf89c0356dc8c7215ca46a3dfa4c7c3 Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Thu, 16 Oct 2025 20:51:46 +0200 Subject: [PATCH 2/7] Add availability checks for local_latlon function --- dzgui.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dzgui.sh b/dzgui.sh index 8585251..f6666bb 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -511,19 +511,30 @@ check_availability() { local_latlon(){ if [[ -z $(command -v dig) ]]; then - local local_ip=$(curl -Ls "https://ipecho.net/plain") + local url_ipecho="https://ipecho.net/plain" + if ! check_availability "ipecho.net"; then + logger WARN "Failed to get external ip address, ipecho.net service may be down." + return 1 + fi + local local_ip=$(curl -Ls "$url_ipecho") else + # todo : implement checking remote local local_ip=$(dig -4 +short myip.opendns.com @resolver1.opendns.com) fi - local url="http://ip-api.com/json/$local_ip" - local res=$(curl -Ls "$url" | jq -r '"\(.lat)\n\(.lon)"') + local url_ip_api="http://ip-api.com/json/$local_ip" + if ! check_availability "ip-api.com"; then + logger WARN "Failed to get local coordinates, ip-api.com service may be down." + return 1 + fi + local res=$(curl -Ls "$url_ip_api" | jq -r '"\(.lat)\n\(.lon)"') if [[ -z "$res" ]]; then logger WARN "Failed to get local coordinates" return 1 fi echo "$res" > "$coords_file" } -lock(){ + +lock [[ ! -f $lock_file ]] && touch $lock_file local pid=$(cat $lock_file) ps -p $pid -o pid= >/dev/null 2>&1 From d6223e54b0d457b37177a97dc1720d6e76d9728b Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Thu, 16 Oct 2025 20:53:14 +0200 Subject: [PATCH 3/7] Fix unintended deletion --- dzgui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dzgui.sh b/dzgui.sh index f6666bb..bd613cf 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -534,7 +534,7 @@ local_latlon(){ echo "$res" > "$coords_file" } -lock +lock(){ [[ ! -f $lock_file ]] && touch $lock_file local pid=$(cat $lock_file) ps -p $pid -o pid= >/dev/null 2>&1 From 6aa1ec4201762924f91b30a23131ea9fe470039b Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Fri, 17 Oct 2025 04:20:13 +0900 Subject: [PATCH 4/7] fix: early abort if local coords are missing --- helpers/funcs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helpers/funcs b/helpers/funcs index e8f35ef..4b65df6 100755 --- a/helpers/funcs +++ b/helpers/funcs @@ -369,6 +369,10 @@ local_latlon(){ get_dist(){ shift local given_ip="$1" + if [[ ! -f $_cache_coords ]]; then + printf "Unknown" + return + fi readarray -t coords < "$_cache_coords" readarray -t n < <(<<< "$given_ip" awk 'BEGIN{RS="."}{$1=$1}1') From 239a82876ea5f56d581a9317b5467d0f38b5dbb7 Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Wed, 22 Oct 2025 17:20:56 +0200 Subject: [PATCH 5/7] fix: silence ping while checking remote urls --- dzgui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dzgui.sh b/dzgui.sh index bd613cf..133ae41 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -503,7 +503,7 @@ check_availability() { if [[ $2 ]]; then timeout_sec=$2 fi - if ! ping -w "$timeout_sec" "$url"; then + if ! ping -w "$timeout_sec" "$url" > /dev/null; then logger WARN "Failed to reach $url, service may be down." return 1 fi From cbc131028f2a1058810402ed0cc502be2279be25 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 23 Oct 2025 08:22:20 +0900 Subject: [PATCH 6/7] chore: capitalize TODO for syntax highlighting --- dzgui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dzgui.sh b/dzgui.sh index 133ae41..7b080ad 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -518,7 +518,7 @@ local_latlon(){ fi local local_ip=$(curl -Ls "$url_ipecho") else - # todo : implement checking remote + # TODO : implement checking remote local local_ip=$(dig -4 +short myip.opendns.com @resolver1.opendns.com) fi local url_ip_api="http://ip-api.com/json/$local_ip" From cc73f23c1c90c59cafdb1aa43d80d751a64409c6 Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Fri, 24 Oct 2025 12:35:56 +0000 Subject: [PATCH 7/7] fix: suppress ping stderr output --- dzgui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dzgui.sh b/dzgui.sh index 7b080ad..0e609a0 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -503,7 +503,7 @@ check_availability() { if [[ $2 ]]; then timeout_sec=$2 fi - if ! ping -w "$timeout_sec" "$url" > /dev/null; then + if ! ping -w "$timeout_sec" "$url" > /dev/null 2>&1; then logger WARN "Failed to reach $url, service may be down." return 1 fi