Activates link local for both ports, removes fallback IP.

This commit is contained in:
pober
2026-03-03 15:02:55 +01:00
committed by pstruebi
parent 70bde5295f
commit c82f375539

View File

@@ -4,13 +4,13 @@ set -e
# This script installs, enables, and restarts the auracast-server and auracast-frontend services
# Requires sudo privileges
# Ensure static fallback IP is configured on eth0 (for direct laptop connection)
FALLBACK_IP="192.168.42.10/24"
if ! nmcli -g ipv4.addresses con show "Wired connection 1" 2>/dev/null | grep -q "$FALLBACK_IP"; then
echo "Adding static fallback IP $FALLBACK_IP to eth0..."
sudo nmcli con modify "Wired connection 1" +ipv4.addresses "$FALLBACK_IP"
sudo nmcli con up "Wired connection 1"
fi
# Ensure static link local is activated (for direct laptop connection)
# Enable link-local for all wired ethernet connections
for conn in $(nmcli -t -f NAME,TYPE connection show | grep "ethernet" | cut -d: -f1); do
echo "Enabling IPv4 link-local for connection: $conn"
sudo nmcli connection modify "$conn" ipv4.link-local enabled 2>/dev/null || echo "Failed to modify $conn"
sudo nmcli connection up "$conn" 2>/dev/null || echo "Failed to bring up $conn"
done
# Configure Avahi to prefer DHCP address over static fallback for mDNS
# Get the DHCP-assigned IP (first non-localhost, non-192.168.42.10 IP)
@@ -18,14 +18,14 @@ DHCP_IP=$(ip -4 addr show eth0 2>/dev/null | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
HOSTNAME=$(hostname)
if [ -n "$DHCP_IP" ]; then
echo "DHCP address detected: $DHCP_IP, configuring Avahi to prefer it for mDNS"
echo "DHCP address detected: $DHCP_IP, configuring Avahi to prefer it for mDNS."
# Add entry to /etc/avahi/hosts to explicitly map hostname to DHCP IP
sudo mkdir -p /etc/avahi
echo "$DHCP_IP $HOSTNAME $HOSTNAME.local" | sudo tee /etc/avahi/hosts > /dev/null
# Restart avahi to apply the hosts file
sudo systemctl restart avahi-daemon
else
echo "No DHCP address detected, mDNS will use static fallback IP $FALLBACK_IP"
echo "No DHCP address detected, mDNS will use link local"
# Remove hosts file to let Avahi advertise all IPs
sudo rm -f /etc/avahi/hosts
sudo systemctl restart avahi-daemon