Files
Claude f9e1eb82c4 feat: komplette Codebase vom Board ins Repo gespiegelt
app/ = /opt/callrec (Node-Backend, Vite-Frontend, Python-Inferenz,
Audio-Skripte, rkllm_server.cpp), system/ = systemd-Units,
WirePlumber/PipeWire-Drop-ins, sudoers. Modelle, Binaries, Aufnahmen
und node_modules bleiben draussen (.gitignore).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 11:18:29 +02:00

35 lines
2.4 KiB
Bash

#!/bin/bash
# Phone-like auto-connect for the realme Buds T110 (out-of-case = pairing mode).
# HEALTH = BT connected AND PipeWire actually has the bluez card (recording needs
# the card, not just the ACL link). Escalation ladder self-heals every state:
# healthy -> idle info-check (no RF, keeps SCO clean)
# BT-conn but no card-> desync: disconnect+reconnect, then kick wireplumber
# device present -> plain connect; else re-pair; 3x fail -> controller reset
# device not around -> quietly wait (in case / off)
MAC=98:34:8C:FD:24:17
CE=XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
fails=0
bt_connected(){ bluetoothctl info "$MAC" 2>/dev/null | grep -q 'Connected: yes'; }
has_card(){ sudo -u callrec env $CE pactl list cards short 2>/dev/null | grep -qi bluez_card; }
healthy(){ bt_connected && has_card; }
present(){ timeout 10 bluetoothctl --timeout 7 scan on >/dev/null 2>&1; bluetoothctl devices 2>/dev/null | grep -qi "$MAC"; }
repair(){ bluetoothctl remove "$MAC" >/dev/null 2>&1; timeout 15 bluetoothctl --timeout 12 scan on >/dev/null 2>&1; timeout 30 bluetoothctl --timeout 25 pair "$MAC" >/dev/null 2>&1; bluetoothctl trust "$MAC" >/dev/null 2>&1; timeout 20 bluetoothctl --timeout 15 connect "$MAC" >/dev/null 2>&1; }
reset_ctrl(){ echo 'btwatch: controller reset'; bluetoothctl remove "$MAC" >/dev/null 2>&1; hciconfig $(hciconfig 2>/dev/null | grep -oE '^hci[0-9]' | head -1) reset 2>/dev/null; systemctl restart bluetooth; sleep 5; }
kick_pw(){ echo 'btwatch: kick wireplumber'; sudo -u callrec env $CE systemctl --user restart wireplumber >/dev/null 2>&1; sleep 3; }
while true; do
if healthy; then fails=0; sleep 6; continue; fi
if bt_connected && ! has_card; then
echo 'btwatch: connected but no pipewire card'
bluetoothctl disconnect "$MAC" >/dev/null 2>&1; sleep 2
bluetoothctl connect "$MAC" >/dev/null 2>&1; sleep 3
has_card && { fails=0; continue; }
kick_pw; has_card && { fails=0; continue; }
fi
if timeout 12 bluetoothctl connect "$MAC" >/dev/null 2>&1; then sleep 3; healthy && { echo 'btwatch: connected'; fails=0; sleep 4; continue; }; fi
if ! present; then fails=0; sleep 8; continue; fi
fails=$((fails+1)); echo "btwatch: present but not healthy (fail $fails)"
if [ "$fails" -lt 3 ]; then repair; else reset_ctrl; repair; fails=0; sleep 8; fi
healthy && fails=0
sleep 4
done