mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
auto mediamtx installation
This commit is contained in:
+62
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user