auto mediamtx installation

This commit is contained in:
legop3
2025-11-10 15:35:31 -05:00
parent 28cbd910dd
commit c621f04d16
3 changed files with 68 additions and 7 deletions
+2 -1
View File
@@ -34,7 +34,7 @@ npm install
npm run start
```
Deploy a rover by copying the repo + `dist/roverd` to the Pi and running the helper:
Deploy a rover by copying the repo + `dist/roverd` to the Pi and running the helper (it will also fetch mediaMTX when `--mediamtx` is set):
```bash
cd ~/MultiRoombaRover
@@ -43,3 +43,4 @@ sudo ./pi/install_roverd.sh --mediamtx
Then point each rover's `/etc/roverd.yaml` at `ws://<server>:8080/rover`, enable the sensor stream from the UI, and drive with WASD.
Use the “Restart Camera” button if you enable media management so roverd can bounce the mediamtx service remotely.
Heads-up: the BRC pulser currently hits `/sys/class/gpio/export`, so the service needs root privileges on Raspberry Pi OS. Until its switched to `libgpiod`, set `brc.gpioPin: -1` if you prefer to run unprivileged (the Create will then nap unless something else keeps it awake).
+4 -2
View File
@@ -32,7 +32,7 @@ What the script does:
- creates the `roverd` (and optionally `mediamtx`) service users if missing and installs `/usr/local/bin/roverd`
- copies `pi/roverd/roverd.sample.yaml` to `/etc/roverd.yaml` if the file is absent (existing configs are left untouched)
- installs/enables the `roverd.service` systemd unit, restarting it automatically when a config already exists
- when `--mediamtx` is passed, installs the sample mediaMTX config + unit, enables the service, and restarts it
- when `--mediamtx` is passed, downloads the requested mediaMTX release for the Pis architecture, installs it to `/usr/local/bin/mediamtx`, drops the sample config + unit, enables the service, and restarts it
Flags:
@@ -40,7 +40,8 @@ Flags:
|------|---------|
| `-b PATH` | use a different roverd binary (defaults to `dist/roverd`) |
| `-c PATH` | seed `/etc/roverd.yaml` from another template |
| `--mediamtx` | install the provided mediaMTX config + unit alongside roverd |
| `--mediamtx` | download/install mediaMTX plus the provided config + unit |
| `--mediamtx-version X.Y.Z` | override the mediaMTX release tag (default `1.8.6`) |
If the script installs the sample config, it will remind you to edit `/etc/roverd.yaml` before manually restarting the service: set `name`, `serverUrl`, serial device, BRC pin, battery thresholds, and the WHEP URL that the central server should expose.
@@ -62,6 +63,7 @@ If the script installs the sample config, it will remind you to edit `/etc/rover
```
`roverd` requires access to `/dev/ttyAMA0` and `/sys/class/gpio`; keeping it under its own user ensures the rest of the system stays isolated.
**BRC note:** writing to `/sys/class/gpio/export` typically requires root on Raspberry Pi OS. Until the pulser moves to `libgpiod`, either run the service as root or set `brc.gpioPin: -1` (rover may eventually sleep).
If you set `media.manage: true` in `/etc/roverd.yaml`, make sure the `roverd` service account can invoke `systemctl <action> <media.service>` (either run the unit as root or grant sudo privileges for that command).
## Configuring mediaMTX
+62 -4
View File
@@ -6,7 +6,8 @@ set -euo pipefail
BINARY_SRC="dist/roverd"
CONFIG_SRC="pi/roverd/roverd.sample.yaml"
INSTALL_MEDIAMTX=0
INSTALL_MEDIAMTX=1
MEDIAMTX_VERSION="1.8.6"
usage() {
cat <<'USAGE'
@@ -16,7 +17,8 @@ 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 Also install mediaMTX unit/config (requires pi/mediamtx files)
--mediamtx Install/download mediaMTX (binary, config, systemd unit)
--mediamtx-version <v> Override mediaMTX release tag (default: 1.8.6)
-h, --help Show this help text
The script must run from the repository root and as root (sudo). It will:
@@ -41,6 +43,10 @@ while [[ $# -gt 0 ]]; do
INSTALL_MEDIAMTX=1
shift
;;
--mediamtx-version)
MEDIAMTX_VERSION="${2:-}"
shift 2
;;
-h|--help)
usage
exit 0
@@ -70,9 +76,15 @@ fi
ensure_user() {
local user="$1"
local groups="$2"
local groups="${2:-}"
if ! id -u "$user" >/dev/null 2>&1; then
useradd -r -s /usr/sbin/nologin -G "$groups" "$user"
if [[ -n "$groups" ]]; then
useradd -r -s /usr/sbin/nologin -G "$groups" "$user"
else
useradd -r -s /usr/sbin/nologin "$user"
fi
elif [[ -n "$groups" ]]; then
usermod -a -G "$groups" "$user"
fi
}
@@ -80,6 +92,51 @@ 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
}
local asset
asset="$(detect_mediamtx_asset)"
if [[ -z "$asset" ]]; then
echo "Unsupported architecture $(uname -m) for mediaMTX download" >&2
exit 1
}
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
}
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"
install -o roverd -g roverd -m 0755 "$BINARY_SRC" /usr/local/bin/roverd
log "Installed roverd binary"
@@ -117,6 +174,7 @@ if [[ $INSTALL_MEDIAMTX -eq 1 ]]; then
fi
ensure_user mediamtx ""
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