diff --git a/Dockerfile b/Dockerfile index d1c4e28c..369e1491 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,17 +52,17 @@ RUN mkdir -p /usr/lib/pkgconfig && \ echo "prefix=/usr\nexec_prefix=\${prefix}\nlibdir=$LIB_DIR\nincludedir=\${prefix}/include\n\nName: mbedx509\nDescription: MbedTLS X509 Library\nVersion: 2.28.0\nLibs: -L\${libdir} -lmbedx509\nCflags: -I\${includedir}" > /usr/lib/pkgconfig/mbedx509.pc && \ chmod 644 /usr/lib/pkgconfig/mbedtls.pc /usr/lib/pkgconfig/mbedcrypto.pc /usr/lib/pkgconfig/mbedx509.pc -# Download and install go2rtc -RUN ARCH=$(uname -m) && \ - case $ARCH in \ - x86_64) GO2RTC_ARCH="amd64" ;; \ - aarch64) GO2RTC_ARCH="arm64" ;; \ - armv7l) GO2RTC_ARCH="arm" ;; \ - *) echo "Unsupported architecture: $ARCH"; exit 1 ;; \ - esac && \ +# Build go2rtc from opensensor fork (includes memory leak fixes) +# Install Go for building go2rtc +RUN curl -L https://go.dev/dl/go1.23.4.linux-$(dpkg --print-architecture).tar.gz | tar -C /usr/local -xzf - && \ + export PATH=$PATH:/usr/local/go/bin && \ mkdir -p /bin /etc/lightnvr/go2rtc && \ - RELEASE_URL=$(curl -s https://api.github.com/repos/AlexxIT/go2rtc/releases/latest | grep "browser_download_url.*linux_$GO2RTC_ARCH" | cut -d '"' -f 4) && \ - curl -L -o /bin/go2rtc $RELEASE_URL && \ + # Clone and build go2rtc from opensensor fork + cd /tmp && \ + git clone --depth 1 --branch fix/memory-leaks https://github.com/opensensor/go2rtc.git && \ + cd go2rtc && \ + CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags "-s -w" -trimpath -o /bin/go2rtc . && \ + cd / && rm -rf /tmp/go2rtc /usr/local/go && \ chmod +x /bin/go2rtc && \ # Create basic configuration file echo "# go2rtc configuration file" > /etc/lightnvr/go2rtc/go2rtc.yaml && \ diff --git a/scripts/install_go2rtc.sh b/scripts/install_go2rtc.sh index 6a8fb06a..4ea61303 100755 --- a/scripts/install_go2rtc.sh +++ b/scripts/install_go2rtc.sh @@ -1,5 +1,6 @@ #!/bin/bash # Script to download and install go2rtc for WebRTC streaming +# Uses opensensor/go2rtc fork with memory leak fixes set -e @@ -8,6 +9,8 @@ INSTALL_DIR="/usr/local/bin" CONFIG_DIR="/etc/lightnvr/go2rtc" VERSION="latest" ARCH=$(uname -m) +# Use opensensor fork by default (includes memory leak fixes) +REPO="opensensor/go2rtc" # Display usage information usage() { @@ -80,15 +83,20 @@ mkdir -p "$CONFIG_DIR" # Determine download URL if [ "$VERSION" = "latest" ]; then - # Get latest release URL - RELEASE_URL=$(curl -s https://api.github.com/repos/AlexxIT/go2rtc/releases/latest | grep "browser_download_url.*linux_$GO2RTC_ARCH" | cut -d '"' -f 4) + # Get latest release URL from opensensor fork + RELEASE_URL=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep "browser_download_url.*linux_$GO2RTC_ARCH" | cut -d '"' -f 4) if [ -z "$RELEASE_URL" ]; then - echo "Failed to determine latest release URL. Please specify a version." - exit 1 + echo "Failed to determine latest release URL from $REPO." + echo "Falling back to upstream AlexxIT/go2rtc..." + RELEASE_URL=$(curl -s https://api.github.com/repos/AlexxIT/go2rtc/releases/latest | grep "browser_download_url.*linux_$GO2RTC_ARCH" | cut -d '"' -f 4) + if [ -z "$RELEASE_URL" ]; then + echo "Failed to determine latest release URL. Please specify a version." + exit 1 + fi fi else - # Construct URL for specific version - RELEASE_URL="https://github.com/AlexxIT/go2rtc/releases/download/$VERSION/go2rtc_linux_$GO2RTC_ARCH" + # Construct URL for specific version from opensensor fork + RELEASE_URL="https://github.com/$REPO/releases/download/$VERSION/go2rtc_linux_$GO2RTC_ARCH" fi echo "Downloading from: $RELEASE_URL" @@ -103,7 +111,7 @@ chmod +x "$INSTALL_DIR/go2rtc" if [ ! -f "$CONFIG_DIR/go2rtc.yaml" ]; then cat > "$CONFIG_DIR/go2rtc.yaml" << EOF # go2rtc configuration file -# See https://github.com/AlexxIT/go2rtc for documentation +# See https://github.com/opensensor/go2rtc for documentation (fork with memory fixes) api: listen: :1984