2026-01-08 00:59:14 -03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# scripts/daemon/lesavka-uvc.sh - launch UVC control helper as a standalone service
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
2026-04-08 20:00:14 -03:00
|
|
|
# Optional env file for runtime overrides (debug, width/fps, etc.)
|
|
|
|
|
if [[ -r /etc/lesavka/uvc.env ]]; then
|
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
|
source /etc/lesavka/uvc.env
|
|
|
|
|
fi
|
|
|
|
|
|
2026-04-28 05:06:19 -03:00
|
|
|
resolve_default_uvc_dev() {
|
|
|
|
|
local ctrl=""
|
|
|
|
|
ctrl=$(ls /sys/class/udc 2>/dev/null | head -n1 || true)
|
|
|
|
|
if [[ -n $ctrl ]]; then
|
|
|
|
|
printf '/dev/v4l/by-path/platform-%s-video-index0\n' "$ctrl"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
local candidate=""
|
|
|
|
|
candidate=$(ls /dev/v4l/by-path/platform-*-video-index0 2>/dev/null | head -n1 || true)
|
|
|
|
|
[[ -n $candidate ]] || return 1
|
|
|
|
|
printf '%s\n' "$candidate"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wait_for_uvc_dev() {
|
|
|
|
|
local dev="$1"
|
|
|
|
|
for _ in {1..50}; do
|
|
|
|
|
[[ -e $dev ]] && return 0
|
|
|
|
|
sleep 0.1
|
|
|
|
|
done
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [[ -n ${LESAVKA_UVC_DEV:-} ]]; then
|
|
|
|
|
DEV=${LESAVKA_UVC_DEV}
|
|
|
|
|
else
|
|
|
|
|
DEV=$(resolve_default_uvc_dev || true)
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z ${DEV:-} ]]; then
|
|
|
|
|
echo "[lesavka-uvc] no gadget video_output node discovered; waiting for /dev/v4l/by-path/platform-*-video-index0 or set LESAVKA_UVC_DEV" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if ! wait_for_uvc_dev "$DEV"; then
|
|
|
|
|
echo "[lesavka-uvc] gadget video_output node is still absent: $DEV" >&2
|
|
|
|
|
exit 1
|
2026-01-08 00:59:14 -03:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
exec /usr/local/bin/lesavka-uvc --device "$DEV"
|