fix(package): sentinèlla: use ip(8) for local-IP detection (inetutils hostname lacks -I); harden numeric parsing

This commit is contained in:
2026-04-27 17:21:00 +00:00
parent 0c81c0454d
commit f158a80492
2 changed files with 15 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
{ symlinkJoin, writeTextFile, socat, dash, hectic, curl, gawk, jq, inetutils, getent, bind }:
{ symlinkJoin, writeTextFile, socat, dash, hectic, curl, gawk, jq, iproute2, getent, bind }:
let
shell = "${dash}/bin/dash";
bashOptions = [
@@ -36,7 +36,7 @@ let
watcher = hectic.writeShellApplication {
inherit shell bashOptions;
name = "watcher";
runtimeInputs = [ curl jq gawk inetutils getent bind.dnsutils ];
runtimeInputs = [ curl jq gawk iproute2 getent bind.dnsutils ];
text = ''
${builtins.readFile ./log.sh}
${builtins.readFile ./colors.sh}

View File

@@ -61,7 +61,10 @@ local_ips() {
printf '%s' "$SELF"
return
fi
hostname -I 2>/dev/null || true
# ip -o -4 addr show: "<idx>: <iface> inet <ip>/<prefix> ..."
ip -o addr show 2>/dev/null \
| awk '$3 ~ /^inet6?$/ { sub(/\/.*/, "", $4); print $4 }' \
| tr '\n' ' '
}
# is_local_ip(ip) — returns 0 if ip belongs to this node
@@ -151,8 +154,15 @@ while :; do
ok="down"; total=0; good=0
if [ "$code" = "200" ]; then
summary=$(printf '%s' "$body" | parse_summary || true)
[ -n "$summary" ] && { total=${summary%% *}; good=${summary#* }; }
summary=$(printf '%s' "$body" | parse_summary 2>/dev/null || true)
if [ -n "$summary" ]; then
_total=${summary%% *}
_good=${summary#* }
case "$_total" in ''|*[!0-9]*) _total=0 ;; esac
case "$_good" in ''|*[!0-9]*) _good=0 ;; esac
total=$_total
good=$_good
fi
[ "$total" -eq "$good" ] && ok="up"
fi