Organize host and robot streaming releases

This commit is contained in:
Mike Mi
2026-08-09 15:56:20 +08:00
commit decff19daf
532 changed files with 127054 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "${SCRIPT_DIR}/load-env.sh"
camera_device="${OMNI_CAMERA_DEVICE}"
occupancy_policy="${OMNI_CAMERA_OCCUPANCY_POLICY:-check}"
die() {
echo "[camera-preflight] $*" >&2
exit 1
}
if [[ "${OMNI_CAMERA_SOURCE:-ros2}" == "ros2" ]]; then
die "ROS2 camera mode is active; do not inspect or release /dev/video*. Use ensure-ros-camera-services.sh instead."
fi
camera_pids() {
fuser "${camera_device}" 2>/dev/null \
| tr ' ' '\n' \
| grep -E '^[0-9]+$' \
| sort -nu \
|| true
}
pid_service() {
local pid="$1"
local service
service="$(sed -nE 's#.*[/:]([^/:]+\.service)$#\1#p' "/proc/${pid}/cgroup" 2>/dev/null | head -1)"
printf '%s' "${service:-unknown}"
}
report_owners() {
local pid
local comm
local service
local found=0
while read -r pid; do
[[ -n "${pid}" ]] || continue
found=1
comm="$(cat "/proc/${pid}/comm" 2>/dev/null || printf 'unknown')"
service="$(pid_service "${pid}")"
echo "[camera-preflight] owner pid=${pid} command=${comm} service=${service}" >&2
done < <(camera_pids)
if [[ "${found}" == "1" ]]; then
return 0
fi
return 1
}
if [[ ! -e "${camera_device}" ]]; then
die "camera device does not exist: ${camera_device}"
fi
if ! command -v fuser >/dev/null 2>&1; then
die "missing required command: fuser (install the psmisc package)"
fi
resolved_device="$(readlink -f "${camera_device}" 2>/dev/null || printf '%s' "${camera_device}")"
echo "[camera-preflight] checking ${camera_device} (${resolved_device}) policy=${occupancy_policy}" >&2
if ! report_owners; then
echo "[camera-preflight] ${camera_device} is free" >&2
exit 0
fi
case "${occupancy_policy}" in
check)
die "${camera_device} is busy; no process was stopped"
;;
release-known)
die "release-known is intentionally removed in OmniSocketGo_robot_ros; stop the owning service manually and use policy=check"
;;
*)
die "unsupported OMNI_CAMERA_OCCUPANCY_POLICY=${occupancy_policy}; expected check"
;;
esac