kunlang_video/deploy/install.sh
2026-05-09 10:51:10 +08:00

88 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo ./install.sh" >&2
exit 1
fi
PACKAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="${INSTALL_DIR:-/opt/vehicle-video-service}"
SERVICE_USER="${SERVICE_USER:-${SUDO_USER:-aiec}}"
SERVICE_GROUP="${SERVICE_GROUP:-$SERVICE_USER}"
DISABLE_LEGACY_SERVICES="${DISABLE_LEGACY_SERVICES:-1}"
need_file() {
if [[ ! -e "$1" ]]; then
echo "Missing required file: $1" >&2
exit 1
fi
}
render_service() {
local template="$1"
local target="$2"
sed \
-e "s#@INSTALL_DIR@#$INSTALL_DIR#g" \
-e "s#@SERVICE_USER@#$SERVICE_USER#g" \
-e "s#@SERVICE_GROUP@#$SERVICE_GROUP#g" \
"$template" > "$target"
}
warn_missing_gst_plugin() {
local plugin="$1"
if command -v gst-inspect-1.0 >/dev/null 2>&1; then
if ! gst-inspect-1.0 "$plugin" >/dev/null 2>&1; then
echo "Warning: missing GStreamer plugin: $plugin" >&2
fi
else
echo "Warning: gst-inspect-1.0 not found; please install GStreamer runtime." >&2
return
fi
}
need_file "$PACKAGE_DIR/bin/vehicle_video_service"
need_file "$PACKAGE_DIR/config/config.json"
need_file "$PACKAGE_DIR/srs/bin/srs"
need_file "$PACKAGE_DIR/srs/conf/live.conf"
need_file "$PACKAGE_DIR/srs/conf/record.conf"
install -d "$INSTALL_DIR/bin" "$INSTALL_DIR/srs/bin" "$INSTALL_DIR/srs/conf" "$INSTALL_DIR/srs/html" \
"$INSTALL_DIR/srs/log" "$INSTALL_DIR/srs/run" /media/record
install -m 0755 "$PACKAGE_DIR/bin/vehicle_video_service" "$INSTALL_DIR/bin/vehicle_video_service"
install -m 0644 "$PACKAGE_DIR/config/config.json" "$INSTALL_DIR/bin/config.json"
install -m 0755 "$PACKAGE_DIR/srs/bin/srs" "$INSTALL_DIR/srs/bin/srs"
install -m 0644 "$PACKAGE_DIR/srs/conf/live.conf" "$INSTALL_DIR/srs/conf/live.conf"
install -m 0644 "$PACKAGE_DIR/srs/conf/record.conf" "$INSTALL_DIR/srs/conf/record.conf"
cp -a "$PACKAGE_DIR/srs/html"/. "$INSTALL_DIR/srs/html/"
chown -R "$SERVICE_USER:$SERVICE_GROUP" "$INSTALL_DIR" /media/record
if [[ "$DISABLE_LEGACY_SERVICES" == "1" ]]; then
for service in srs-live.service srs-record.service video_manager.service; do
if systemctl list-unit-files "$service" >/dev/null 2>&1; then
systemctl disable --now "$service" >/dev/null 2>&1 || true
fi
done
fi
render_service "$PACKAGE_DIR/systemd/vehicle-video-srs-live.service.in" \
/etc/systemd/system/vehicle-video-srs-live.service
render_service "$PACKAGE_DIR/systemd/vehicle-video-srs-record.service.in" \
/etc/systemd/system/vehicle-video-srs-record.service
render_service "$PACKAGE_DIR/systemd/vehicle-video-service.service.in" \
/etc/systemd/system/vehicle-video-service.service
systemctl daemon-reload
systemctl enable --now vehicle-video-srs-live.service vehicle-video-srs-record.service vehicle-video-service.service
warn_missing_gst_plugin v4l2src
warn_missing_gst_plugin mpph264enc
warn_missing_gst_plugin h264parse
warn_missing_gst_plugin flvmux
warn_missing_gst_plugin rtmpsink
echo "Installed to $INSTALL_DIR"
echo "Services: vehicle-video-srs-live, vehicle-video-srs-record, vehicle-video-service"