Fix avahi service file

This commit is contained in:
imonlinux
2025-09-24 21:00:11 -07:00
committed by GitHub
parent 2564d1a745
commit 1cc4e43ee5
+8 -23
View File
@@ -2,7 +2,7 @@
set -euo pipefail set -euo pipefail
PORT=6053 PORT=6053
NAME="%h (Linux Voice Assistant)" NAME="%h"
SERVICE=/etc/avahi/services/esphome-lva.service SERVICE=/etc/avahi/services/esphome-lva.service
# Wait up to ~40s for any global IPv4 (cosmetic: to include ipv4_* TXT) # Wait up to ~40s for any global IPv4 (cosmetic: to include ipv4_* TXT)
@@ -15,7 +15,9 @@ done
# Collect all UP, non-loopback ifaces # Collect all UP, non-loopback ifaces
mapfile -t IFACES < <(ip -o link show up | awk -F': ' '{print $2}' | grep -v '^lo$' | sort -u) mapfile -t IFACES < <(ip -o link show up | awk -F': ' '{print $2}' | grep -v '^lo$' | sort -u)
TXT=" <txt-record>platform=linux</txt-record> TXT=" <txt-record>platform=HOST</txt-record>
"
TXT+=" <txt-record>board=host</txt-record>
" "
LIST="" LIST=""
for i in "${IFACES[@]}"; do for i in "${IFACES[@]}"; do
@@ -24,27 +26,10 @@ for i in "${IFACES[@]}"; do
mac_nc=${mac//:/} # no colons (ESPHome style) mac_nc=${mac//:/} # no colons (ESPHome style)
if [ -d "/sys/class/net/$i/wireless" ] || [[ "$i" == wl* ]]; then net=wifi; else net=ethernet; fi if [ -d "/sys/class/net/$i/wireless" ] || [[ "$i" == wl* ]]; then net=wifi; else net=ethernet; fi
TXT+=" <txt-record>net_${i}=${net}</txt-record> TXT+=" <txt-record>network=${net}</txt-record>
" "
TXT+=" <txt-record>mac_${i}=${mac_nc}</txt-record> TXT+=" <txt-record>mac=${mac_nc}</txt-record>
" "
# IPv4 (global)
while read -r a; do
[ -n "$a" ] || continue
a=${a%%/*}
TXT+=" <txt-record>ipv4_${i}=${a}</txt-record>
"
done < <(ip -o -4 addr show dev "$i" scope global | awk '{print $4}' || true)
# IPv6 (global, not link-local)
while read -r a6; do
[ -n "$a6" ] || continue
a6=${a6%%/*}
TXT+=" <txt-record>ipv6_${i}=${a6}</txt-record>
"
done < <(ip -o -6 addr show dev "$i" scope global | awk '{print $4}' || true)
LIST+="${i}," LIST+="${i},"
done done
LIST=${LIST%,} LIST=${LIST%,}
@@ -54,10 +39,10 @@ cat >"$SERVICE" <<XML
<!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group> <service-group>
<name replace-wildcards="yes">${NAME}</name> <name replace-wildcards="yes">${NAME}</name>
<service> <service protocol=ipv4>
<type>_esphomelib._tcp</type> <type>_esphomelib._tcp</type>
<port>${PORT}</port> <port>${PORT}</port>
<txt-record>ifaces=${LIST}</txt-record> <txt-record>version=2025.9.0</txt-record>
${TXT} </service> ${TXT} </service>
</service-group> </service-group>
XML XML