#!/usr/bin/env bash # provision-wifi.sh — join a Uno Q board to the workshop WiFi over adb and persist # it. NetworkManager saves the connection profile, so the board auto-reconnects on # every boot. The board reaches the cloud brain (api.anthropic.com) NAT'd out # through this WiFi, so every workshop board needs it. # # The venue network is baked in as the default (override with WIFI_SSID/WIFI_PASS). # # Usage: # ./provision-wifi.sh # first attached board # ./provision-wifi.sh # a specific board # # every attached board at once: # for s in $(adb devices | awk 'NR>1 && $2=="device"{print $1}'); do ./provision-wifi.sh "$s"; done set -uo pipefail # ── workshop WiFi (FabLab Torino) — override per venue with WIFI_SSID / WIFI_PASS ── WIFI_SSID="${WIFI_SSID:-Fablab_Torino}" WIFI_PASS="${WIFI_PASS:-Fablab.Torino!}" S="${1:-$(adb devices 2>/dev/null | awk '/\tdevice$/{print $1; exit}')}" [ -n "$S" ] || { echo "provision-wifi: no board attached over USB" >&2; exit 1; } echo "==> [$S] joining WiFi '$WIFI_SSID'" # Idempotent: if a saved profile already exists, just bring it up; otherwise scan # and create it (a persistent NetworkManager profile that auto-reconnects on boot). adb -s "$S" shell "nmcli radio wifi on >/dev/null 2>&1; sleep 1 if nmcli -t -f NAME connection show 2>/dev/null | grep -qx '$WIFI_SSID'; then nmcli connection up '$WIFI_SSID' else nmcli device wifi rescan >/dev/null 2>&1; sleep 4 nmcli device wifi connect '$WIFI_SSID' password '$WIFI_PASS' fi" 2>&1 | sed 's/^/ /' # verify link + that the cloud is reachable through it adb -s "$S" shell 'ip -brief addr show wlan0 2>/dev/null | sed "s/^/ wlan0: /"' if adb -s "$S" shell 'getent hosts api.anthropic.com >/dev/null 2>&1'; then echo " cloud DNS: resolves ✓ — board can reach the agent brain" else echo " cloud DNS: FAILS — check WiFi coverage / credentials" >&2 exit 1 fi