#!/usr/bin/env bash # Deploy vanlink configs/scripts (Pi 4 "wan" port) to their system locations. # Usage: cd ~/vanlink && sudo ./deploy.sh # Idempotent. Netplan (wlan0 + Starlink NIC = NM-managed WANs; eth0 is a LAN # port on br0) is NOT touched here — reference copy in ap/50-van-wan.yaml, # applied once manually (apply flaps uplinks). set -euo pipefail cd "$(dirname "$(readlink -f "$0")")" [ "$(id -u)" = 0 ] || { echo "Run with sudo (writes to /etc, /usr)."; exit 1; } echo "== access point ==" install -D -m0644 ap/hostapd.conf /etc/hostapd/hostapd.conf install -D -m0644 ap/hostapd-restart.conf /etc/systemd/system/hostapd.service.d/restart.conf install -D -m0644 ap/default-hostapd /etc/default/hostapd install -D -m0644 ap/hostapd-2g.conf /etc/hostapd/hostapd-2g.conf install -D -m0644 ap/hostapd-2g.service /etc/systemd/system/hostapd-2g.service install -D -m0644 ap/11-van-ap-2g.network /etc/systemd/network/11-van-ap-2g.network install -D -m0644 ap/van-ap-watchdog-2g.service /etc/systemd/system/van-ap-watchdog-2g.service install -D -m0644 ap/rtw88.conf /etc/modprobe.d/rtw88.conf install -D -m0755 ap/van-ap-watchdog /usr/local/sbin/van-ap-watchdog install -D -m0644 ap/van-ap-watchdog.service /etc/systemd/system/van-ap-watchdog.service install -D -m0644 ap/van-ap-dnsmasq.conf /etc/van-ap/dnsmasq.conf install -D -m0644 ap/van-ap-dnsmasq.service /etc/systemd/system/van-ap-dnsmasq.service install -D -m0644 ap/10-van-ap.network /etc/systemd/network/10-van-ap.network install -D -m0644 ap/20-van-br0.netdev /etc/systemd/network/20-van-br0.netdev install -D -m0644 ap/21-van-br0.network /etc/systemd/network/21-van-br0.network install -D -m0644 ap/22-van-lan.network /etc/systemd/network/22-van-lan.network install -D -m0644 ap/23-van-lan-eth0.network /etc/systemd/network/23-van-lan-eth0.network install -D -m0644 ap/van-ap-unmanaged.conf /etc/NetworkManager/conf.d/van-ap-unmanaged.conf install -D -m0644 ap/nftables.conf /etc/nftables.conf install -D -m0644 ap/regdomain.service /etc/systemd/system/regdomain.service install -D -m0644 ap/rtw89.conf /etc/modprobe.d/rtw89.conf install -D -m0644 ap/99-van-router.conf /etc/sysctl.d/99-van-router.conf echo "== failover ==" install -D -m0755 failover/van-failover /usr/local/sbin/van-failover install -D -m0644 failover/config.json /etc/van-failover/config.json install -D -m0644 failover/van-failover.service /etc/systemd/system/van-failover.service install -D -m0755 failover/50-disable-eee /etc/NetworkManager/dispatcher.d/50-disable-eee install -D -m0644 failover/99-van-arp.conf /etc/sysctl.d/99-van-arp.conf echo "== cockpit plugin ==" install -d /usr/share/cockpit/vanrouter install -m0644 cockpit/vanrouter/* /usr/share/cockpit/vanrouter/ # Bridge fd headroom (Python bridge frees spawn pipes only at GC; 1024 is too tight) install -D -m0644 cockpit/cockpit-session-nofile.conf /etc/systemd/system/cockpit-session@.service.d/nofile.conf # The Starlink card queries the dish's gRPC API; grpcurl isn't packaged in apt. command -v grpcurl >/dev/null 2>&1 \ || echo " -> grpcurl missing (Starlink card will say so): install linux_arm64 binary from github.com/fullstorydev/grpcurl/releases" echo "== thermal monitor ==" install -D -m0755 power/van-thermal /usr/local/sbin/van-thermal install -D -m0644 power/thermal-config.json /etc/van-thermal/config.json install -D -m0644 power/van-thermal.service /etc/systemd/system/van-thermal.service # Pushover secrets live only on the system (0600), never in the repo. Path kept # under /etc/van-battery/ for parity with wayback's van-thermal default. if [ ! -f /etc/van-battery/pushover.json ]; then install -D -m0600 power/pushover.json.example /etc/van-battery/pushover.json echo " -> seeded /etc/van-battery/pushover.json (EDIT IT: add Pushover token + user)" fi echo "== home assistant ==" # Native HA (Podman Quadlet, replaced the ha_van VM). daemon-reload below # regenerates homeassistant.service; started (not restarted) at the end so a # deploy never bounces HA — after editing the .container, restart it manually. install -D -m0644 ha/homeassistant.container /etc/containers/systemd/homeassistant.container install -d -m0755 /srv/homeassistant echo "== hardware watchdog ==" install -D -m0644 power/10-vanlink-watchdog.conf /etc/systemd/system.conf.d/10-vanlink-watchdog.conf echo "== apply ==" sysctl --system >/dev/null systemctl daemon-reload # Re-exec PID1 so the system.conf.d watchdog drop-in takes effect (daemon-reload # alone does NOT re-arm RuntimeWatchdogSec). Safe online. systemctl daemon-reexec # networkd here owns only the AP radios + bridge + wired LAN port (no real uplink); # its wait-online would just stall network-online.target. NM-wait-online covers WANs. systemctl mask systemd-networkd-wait-online.service >/dev/null 2>&1 || true systemctl unmask hostapd >/dev/null 2>&1 || true systemctl enable regdomain.service hostapd hostapd-2g van-ap-dnsmasq nftables systemd-networkd van-failover van-thermal van-ap-watchdog van-ap-watchdog-2g >/dev/null 2>&1 || true # bluetooth: host BlueZ serves the onboard hci0 to the HA container over D-Bus systemctl enable --now bluetooth >/dev/null 2>&1 || true systemctl start homeassistant || echo " -> homeassistant failed to start (podman/quadlet — check journalctl -u homeassistant)" systemctl restart van-thermal # Pick up unmanaged-devices changes so NM releases/keeps the right interfaces. nmcli general reload 2>/dev/null || systemctl reload NetworkManager 2>/dev/null || true # restart in dependency order: bridge + members first, then hostapd enslaves the # radios, then dnsmasq binds br0, then NAT/failover systemctl restart systemd-networkd systemctl restart van-ap-dnsmasq nftables van-failover # The AP radios live on the USB hub and may be absent; the start then fails but # Restart=always keeps retrying and claims them the moment they enumerate. systemctl restart hostapd hostapd-2g \ || echo " -> hostapd(-2g) waiting for AP radios (USB hub not plugged in)" # AP watchdogs last, after hostapd is back up (they only ever restart a wedged hostapd) systemctl restart van-ap-watchdog van-ap-watchdog-2g networkctl reload 2>/dev/null || true echo echo "Deployed. NOTE: until the USB hub (AP radios + LAN/Starlink adapters) is" echo "plugged in, hostapd/hostapd-2g just retry every 5s — that is by design." echo "Verify (with hub present):" echo " iw dev wlxc83a35a4ee55 info | grep -E 'ssid|channel|width'" echo " iw dev wlxd8ec5e2faa8c info | grep -E 'ssid|channel|width'" echo " cat /run/van-failover/state.json" echo " cat /run/van-thermal/state.json"