← back to Govarbitrage
apps/mobile/device-proof-evidence/capture-lib.sh
87 lines
#!/bin/bash
# GovArbitrage physical-device proof capture helpers (TK-10279)
# GATES: read-only device inspection + local recording ONLY. No ASC. No identity actions.
UDID="${GOVARB_DEVICE_UDID:-}"
BUNDLE="com.abrams.govarbitrage"
EVID="/Volumes/Henry/mac2-offload/govarbitrage/apps/mobile/device-proof-evidence"
dp_require_udid() {
if [ -z "$UDID" ]; then
echo "Set GOVARB_DEVICE_UDID to the connected physical iPhone identifier." >&2
return 64
fi
}
# 1) Device identity + OS -> device-info.txt
dp_info() {
dp_require_udid || return
xcrun devicectl device info details --device "$UDID" 2>&1 | tee "$EVID/device-info.txt" | \
grep -iE "productType|osVersion|deviceName|marketingName|udid|developerMode" | head -20
}
# 2) Is build 5 installed? (cannot side-load; TestFlight install is Steve's action)
dp_app_installed() {
dp_require_udid || return
local OUT
if ! OUT="$(xcrun devicectl device info apps --device "$UDID" 2>&1)"; then
printf '%s\n' "$OUT" | tee "$EVID/installed-apps.txt"
echo "DEVICE_QUERY_FAILED"
return 2
fi
printf '%s\n' "$OUT" | tee "$EVID/installed-apps.txt"
if printf '%s\n' "$OUT" | grep -qi "$BUNDLE\|govarbitrage"; then
echo "INSTALLED"
return 0
fi
echo "NOT_INSTALLED"
return 1
}
# 3) Find the iPhone's AVFoundation video index by name (only present when online+trusted)
dp_avf_index() {
ffmpeg -f avfoundation -list_devices true -i "" 2>&1 | \
awk '/AVFoundation video devices/{v=1;next} /AVFoundation audio devices/{v=0} v' | \
grep -i "iphone" | grep -oE '\[[0-9]+\]' | tr -d '[]' | head -1
}
# 4) Start recording (call: dp_record_start <avf_index> ; writes PID to $EVID/rec.pid)
dp_record_start() {
local IDX="$1"
local OUT="$EVID/govarbitrage-device-proof-$(date +%Y%m%dT%H%M%S).mov"
echo "$OUT" > "$EVID/rec.path"
# video-only (no mic) to avoid capturing room audio; 30fps; h264
ffmpeg -y -f avfoundation -framerate 30 -i "$IDX" -c:v h264_videotoolbox -b:v 8M "$OUT" \
> "$EVID/ffmpeg.log" 2>&1 &
echo $! > "$EVID/rec.pid"
echo "recording -> $OUT (pid $(cat "$EVID/rec.pid"))"
}
# 5) Stop recording cleanly (SIGINT so moov atom is written)
dp_record_stop() {
local PID="$(cat "$EVID/rec.pid" 2>/dev/null)"
[ -n "$PID" ] && kill -INT "$PID" 2>/dev/null && sleep 3
echo "stopped; file:"; ls -la "$(cat "$EVID/rec.path" 2>/dev/null)" 2>/dev/null
}
# 5b) WIRELESS FALLBACK — record the Mac screen (screen 0) while iPhone is AirPlay-mirrored to this Mac.
# PROVEN working 2026-09-02 (Screen Recording TCC already granted). Use when no USB cable.
# Steve: System Settings>General>AirDrop&Handoff>AirPlay Receiver = On; iPhone Control Center>Screen Mirroring>this Mac.
dp_record_screen0() {
local OUT="$EVID/govarbitrage-device-proof-airplay-$(date +%Y%m%dT%H%M%S).mov"
echo "$OUT" > "$EVID/rec.path"
ffmpeg -y -f avfoundation -framerate 30 -i "0" -c:v h264_videotoolbox -b:v 8M "$OUT" \
> "$EVID/ffmpeg.log" 2>&1 &
echo $! > "$EVID/rec.pid"
echo "recording Mac screen 0 (AirPlay mirror) -> $OUT (pid $(cat "$EVID/rec.pid"))"
}
# 6) Launch app cold
dp_launch() {
dp_require_udid || return
xcrun devicectl device process launch --device "$UDID" "$BUNDLE" 2>&1 | tee "$EVID/launch.txt"
}
"$@"