summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar/sb-iplocate
diff options
context:
space:
mode:
authorMaks Jopek <maks@jopek.eu>2026-07-12 15:30:03 +0200
committerMaks Jopek <maks@jopek.eu>2026-07-12 15:30:03 +0200
commit497f40ed5a286e52383cc77e81aa1f49b74df925 (patch)
treeb22ecddb58d2bac5be1285f10f4e0e7e44db6690 /.local/bin/statusbar/sb-iplocate
parentcfe0107b0b47cff187ffef91d1ae6e4d5566b370 (diff)
parent0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66 (diff)
downloadeibhear-master.tar.gz
eibhear-master.tar.zst
eibhear-master.zip
Merge remote-tracking branch 'voidrice/master'HEADmaster
Diffstat (limited to '.local/bin/statusbar/sb-iplocate')
-rwxr-xr-x.local/bin/statusbar/sb-iplocate21
1 files changed, 18 insertions, 3 deletions
diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate
index a9043e3..a1606e1 100755
--- a/.local/bin/statusbar/sb-iplocate
+++ b/.local/bin/statusbar/sb-iplocate
@@ -5,10 +5,25 @@
#
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
-set -e
+ifinstalled "geoip" || exit 1
-ifinstalled "geoip"
-addr="$(geoiplookup "$(curl -sfm 1 ifconfig.me 2>/dev/null)")"
+getip() {
+ { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
+ curl -sf api.ipify.org --output "$ipfile"
+}
+
+ipfile="$XDG_RUNTIME_DIR/iplocate"
+addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" ||
+ ( flock -n 9 &&
+ ( tries=0; while [ $tries -ne 100 ]; do
+ getip && break ||
+ { tries=$((tries+1)); sleep .1; }
+ done
+ ! [ -f "$ipfile" ] &&
+ until getip; do sleep 60; done &&
+ pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}"
+ ) &
+ echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-iplocate.lock"
name="${addr##*, }"
flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")"
flag="${flag%% *}"