whip whep whap

This commit is contained in:
legop3
2025-11-14 05:14:30 -05:00
parent ab3b49b13e
commit a35bdad805
16 changed files with 238 additions and 380 deletions
+34 -88
View File
@@ -6,8 +6,6 @@ set -euo pipefail
BINARY_SRC="dist/roverd"
CONFIG_SRC="pi/roverd/roverd.sample.yaml"
INSTALL_MEDIAMTX=0
MEDIAMTX_VERSION="1.15.3"
usage() {
cat <<'USAGE'
@@ -17,15 +15,13 @@ Options:
-b, --binary <path> Path to the roverd binary (default: dist/roverd)
-c, --config <path> Source config to install if /etc/roverd.yaml is missing
(default: pi/roverd/roverd.sample.yaml)
--mediamtx Install/download mediaMTX (binary, config, systemd unit)
--mediamtx-version <v> Override mediaMTX release tag (default: 1.15.3)
-h, --help Show this help text
The script must run from the repository root and as root (sudo). It will:
* create system users/groups if needed
* install /usr/local/bin/roverd and /etc/roverd.yaml
* install /etc/systemd/system/roverd.service and enable the service
* optionally install mediaMTX config/unit when --mediamtx is set
* install /usr/local/bin/whip-publisher and its systemd unit
* enable roverd.service and whip-publisher.service
USAGE
}
@@ -39,14 +35,6 @@ while [[ $# -gt 0 ]]; do
CONFIG_SRC="${2:-}"
shift 2
;;
--mediamtx)
INSTALL_MEDIAMTX=1
shift
;;
--mediamtx-version)
MEDIAMTX_VERSION="${2:-}"
shift 2
;;
-h|--help)
usage
exit 0
@@ -74,6 +62,13 @@ if [[ ! -f "$CONFIG_SRC" ]]; then
exit 1
fi
if ! command -v libcamera-vid >/dev/null 2>&1; then
log "WARNING: libcamera-vid not found in PATH; install libcamera-utils for video publishing"
fi
if ! command -v ffmpeg >/dev/null 2>&1; then
log "WARNING: ffmpeg not found in PATH; install ffmpeg for WHIP publishing"
fi
ensure_user() {
local user="$1"
local groups="${2:-}"
@@ -92,52 +87,7 @@ log() {
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*"
}
detect_mediamtx_asset() {
local arch
arch="$(uname -m)"
case "$arch" in
armv7l|armv6l)
echo "mediamtx_v${MEDIAMTX_VERSION}_linux_armv7.tar.gz"
;;
aarch64|arm64)
echo "mediamtx_v${MEDIAMTX_VERSION}_linux_arm64.tar.gz"
;;
x86_64|amd64)
echo "mediamtx_v${MEDIAMTX_VERSION}_linux_amd64.tar.gz"
;;
*)
echo ""
;;
esac
}
install_mediamtx_binary() {
if ! command -v curl >/dev/null 2>&1; then
echo "curl is required to download mediaMTX" >&2
exit 1
fi
local asset
asset="$(detect_mediamtx_asset)"
if [[ -z "$asset" ]]; then
echo "Unsupported architecture $(uname -m) for mediaMTX download" >&2
exit 1
fi
local url="https://github.com/bluenviron/mediamtx/releases/download/v${MEDIAMTX_VERSION}/${asset}"
local tmpdir
tmpdir="$(mktemp -d)"
log "Downloading mediaMTX ${MEDIAMTX_VERSION} (${asset})"
if ! curl -fsSL "$url" -o "${tmpdir}/${asset}"; then
echo "Failed to download mediaMTX from ${url}" >&2
rm -rf "$tmpdir"
exit 1
fi
tar -xzf "${tmpdir}/${asset}" -C "$tmpdir" mediamtx
install -o mediamtx -g mediamtx -m 0755 "${tmpdir}/mediamtx" /usr/local/bin/mediamtx
log "Installed /usr/local/bin/mediamtx"
rm -rf "$tmpdir"
}
ensure_user roverd "dialout,gpio"
ensure_user roverd "dialout,gpio,video"
install -o roverd -g roverd -m 0755 "$BINARY_SRC" /usr/local/bin/roverd
log "Installed roverd binary"
@@ -154,36 +104,32 @@ fi
install -m 0644 pi/systemd/roverd.service /etc/systemd/system/roverd.service
log "Installed roverd systemd unit"
systemctl daemon-reload
systemctl enable roverd.service
if [[ $CONFIG_EXISTS -eq 1 ]]; then
systemctl restart roverd.service
log "Restarted roverd.service"
else
log "Skipped auto-start because config is the sample; edit $CONFIG_DEST then run: sudo systemctl restart roverd"
# Install WHIP publisher assets
install -D -o root -g root -m 0755 pi/bin/whip-publisher.sh /usr/local/bin/whip-publisher
install -m 0644 pi/systemd/whip-publisher.service /etc/systemd/system/whip-publisher.service
install -d -o roverd -g roverd /var/lib/roverd
if [[ ! -f /var/lib/roverd/whip.env ]]; then
cat > /var/lib/roverd/whip.env <<'ENV'
# Managed by roverd; placeholder values will be overwritten at runtime.
WHIP_URL=http://192.168.0.86:8889/whip/CHANGE_ME
VIDEO_WIDTH=1280
VIDEO_HEIGHT=720
VIDEO_FPS=30
VIDEO_BITRATE=3000000
ENV
chown roverd:roverd /var/lib/roverd/whip.env
chmod 0640 /var/lib/roverd/whip.env
fi
if [[ $INSTALL_MEDIAMTX -eq 1 ]]; then
if [[ ! -f "pi/mediamtx/mediamtx.yml" ]]; then
echo "pi/mediamtx/mediamtx.yml missing, cannot install mediaMTX config" >&2
exit 1
fi
if [[ ! -f "pi/systemd/mediamtx.service" ]]; then
echo "pi/systemd/mediamtx.service missing, cannot install mediaMTX unit" >&2
exit 1
fi
ensure_user mediamtx "video"
install_mediamtx_binary
install -d -o mediamtx -g mediamtx /etc/mediamtx
install -o mediamtx -g mediamtx -m 0644 pi/mediamtx/mediamtx.yml /etc/mediamtx/mediamtx.yml
install -m 0644 pi/systemd/mediamtx.service /etc/systemd/system/mediamtx.service
log "Installed mediamtx config and unit"
systemctl daemon-reload
systemctl enable mediamtx.service
systemctl restart mediamtx.service
log "Restarted mediamtx.service"
systemctl daemon-reload
systemctl enable roverd.service
systemctl enable whip-publisher.service
if [[ $CONFIG_EXISTS -eq 1 ]]; then
systemctl restart roverd.service
systemctl restart whip-publisher.service
log "Restarted roverd + WHIP publisher"
else
log "Skipped auto-start because config is the sample; edit $CONFIG_DEST then run: sudo systemctl restart roverd whip-publisher"
fi
log "Install complete"