Files
yaris-obd/deploy/install_netwatch.sh
T
Mathieu MoranandCopilot 908e86d169 feat(network): wlan0 fallback if T3U dongle is absent
- PRIMARY_INTERFACE=wlan1, FALLBACK_INTERFACE=wlan0
- resolve_interface() checks /sys/class/net at startup and picks whichever exists
- INTERFACE is module-level, so all functions use the correct iface automatically
- restore_fallback() now also tries home-wifi-fb / Hotspot on wlan0 if wlan1 is primary but failed
- install_netwatch.sh creates home-wifi-fb profile on wlan0 (lower autoconnect-priority=5)
- wlan0 stays managed=yes (fallback) instead of being hard-disabled
- Status JSON now includes 'interface' field for diagnostics

Co-authored-by: Copilot <[email protected]>
2026-08-10 02:35:06 -04:00

73 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# One-time install of the yaris-obd phone/home/local-hotspot auto-switch
# watcher on the Pi. Run this ON THE PI as the `yaris` user (needs sudo):
# cd /home/yaris/app/yaris-obd && bash deploy/install_netwatch.sh
#
# Prerequisite: the "home-wifi" and "Hotspot" NetworkManager profiles must
# already exist (see PLAN.md Phase 6). The optional "phone-hotspot" profile is
# created through the Settings page.
#
# Since Phase 23+: all WiFi traffic (hotspot AP, phone client, home client)
# runs on wlan1 (TP-Link T3U dongle). wlan0 (onboard) is disabled.
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
WLAN=wlan1 # T3U dongle — change to wlan0 if reverting to onboard
WLAN_FB=wlan0 # onboard fallback
sudo systemctl stop yaris-uplink-wait.service 2>/dev/null || true
sudo systemctl stop yaris-netwatch.timer yaris-netwatch.service 2>/dev/null || true
sudo rm -f /usr/local/bin/yaris-netwatch.sh
sudo install -m 755 "$REPO_DIR/deploy/yaris_uplink.py" /usr/local/bin/yaris-uplink
sudo install -m 440 "$REPO_DIR/deploy/yaris-uplink.sudoers" /etc/sudoers.d/yaris-uplink
sudo visudo -cf /etc/sudoers.d/yaris-uplink
sudo install -m 644 "$REPO_DIR/deploy/yaris-hotspot-dns.conf" \
/etc/NetworkManager/dnsmasq-shared.d/yaris-hotspot-dns.conf
sudo install -m 755 "$REPO_DIR/deploy/90-yaris-uplink" \
/etc/NetworkManager/dispatcher.d/90-yaris-uplink
# Bind all connections to the T3U dongle (wlan1)
sudo nmcli connection modify home-wifi connection.interface-name "$WLAN"
sudo nmcli connection modify Hotspot \
connection.interface-name "$WLAN" \
ipv4.method shared \
ipv4.addresses 10.42.0.1/24
if nmcli connection show phone-hotspot >/dev/null 2>&1; then
sudo nmcli connection modify phone-hotspot \
connection.interface-name "$WLAN" \
ipv4.dhcp-send-hostname yes \
ipv4.dhcp-hostname yaris \
802-11-wireless.mtu 1400
fi
# Create wlan0 fallback profiles (lower autoconnect-priority so wlan1 wins)
# home-wifi-fb: same SSID as home-wifi but on wlan0
HOME_SSID=$(nmcli -g 802-11-wireless.ssid connection show home-wifi 2>/dev/null || true)
HOME_PSK=$(sudo nmcli -g 802-11-wireless-security.psk connection show --show-secrets home-wifi 2>/dev/null || true)
if [ -n "$HOME_SSID" ] && [ -n "$HOME_PSK" ]; then
nmcli connection delete home-wifi-fb 2>/dev/null || true
sudo nmcli connection add \
type wifi \
con-name home-wifi-fb \
ifname "$WLAN_FB" \
ssid "$HOME_SSID" \
-- \
wifi-security.key-mgmt wpa-psk \
wifi-security.psk "$HOME_PSK" \
connection.autoconnect yes \
connection.autoconnect-priority 5
echo "Created home-wifi-fb fallback on $WLAN_FB"
fi
# Re-enable wlan0 as a managed (but low-priority) fallback
sudo nmcli device set "$WLAN_FB" managed yes 2>/dev/null || true
sudo cp "$REPO_DIR/deploy/yaris-netwatch.service" /etc/systemd/system/yaris-netwatch.service
sudo cp "$REPO_DIR/deploy/yaris-netwatch.timer" /etc/systemd/system/yaris-netwatch.timer
sudo cp "$REPO_DIR/deploy/yaris-uplink-wait.service" /etc/systemd/system/yaris-uplink-wait.service
sudo systemctl daemon-reload
sudo systemctl enable --now yaris-netwatch.timer
echo "Done. Check status with: systemctl status yaris-netwatch.timer"
echo "Logs: journalctl -t yaris-netwatch -f"