From 773d24a00cca05b09b82eb1eb862731c7e9b1748 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Sat, 25 Oct 2025 11:33:42 +0900 Subject: [PATCH] chore: backport patch from testing --- dzgui.sh | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/dzgui.sh b/dzgui.sh index 58975c8..e3db876 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -496,20 +496,47 @@ 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" > /dev/null 2>&1; 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") + 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(){ [[ ! -f $lock_file ]] && touch $lock_file local pid=$(cat $lock_file)