From dc9fd380ac02774d0d48edfcaa678eead7a13770 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 00:08:06 -0400 Subject: [PATCH 01/12] Troubleshooting status reporting --- root/usr/libexec/apps/frigate/frigate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 3063f90..fede17c 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -179,7 +179,7 @@ case "${ACTION}" in APP_NAME="frigate" CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }') - if [ -z "$CONTAINER_STATUS" ]; then + if [ -z "$CONTAINER_NAME" ]; then echo "${APP_NAME} is not installed" else echo "${CONTAINER_STATUS}" -- 2.38.4 From 2895e78b7280707726e0ddcad2ce48a56966d016 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 00:08:06 -0400 Subject: [PATCH 02/12] Troubleshooting status reporting --- root/usr/libexec/apps/frigate/frigate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 3063f90..fede17c 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -179,7 +179,7 @@ case "${ACTION}" in APP_NAME="frigate" CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }') - if [ -z "$CONTAINER_STATUS" ]; then + if [ -z "$CONTAINER_NAME" ]; then echo "${APP_NAME} is not installed" else echo "${CONTAINER_STATUS}" -- 2.38.4 From b092cf53339ba8f6fc1066816114572a1094677d Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 16:02:50 -0400 Subject: [PATCH 03/12] Removed config yml check because we are generating it with the script --- root/usr/libexec/apps/frigate/frigate.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index fede17c..1100b9d 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -13,7 +13,6 @@ do_install_detail() { local config port IMAGE_NAME username password LAN_IP local usbcoral hwaccel storage mqtt host coral type device - config=$(uci get frigate.@frigate_config[0].config_path 2>/dev/null) port=$(uci get frigate.@frigate_config[0].port 2>/dev/null) IMAGE_NAME=$(uci get frigate.@frigate_config[0].image 2>/dev/null) usbcoral=$(uci get frigate.@frigate_config[0].usbcoral 2>/dev/null) @@ -37,11 +36,6 @@ do_install_detail() { LAN_IP=$(uci get network.lan.ipaddr) LAN_IP="${LAN_IP%/*}" - if [ -z "$config" ]; then - echo "config path is empty!" - exit 1 - fi - [ -z "$port" ] && port=1880 [ -z "$IMAGE_NAME" ] && IMAGE_NAME="ghcr.io/blakeblackshear/frigate:stable" -- 2.38.4 From c0c81ad1cdfb4830059ca6d2ea74bef763e7a7eb Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 16:38:27 -0400 Subject: [PATCH 04/12] Major config fetching refactor --- root/etc/config/frigate | 6 +-- root/usr/libexec/apps/frigate/frigate.sh | 62 ++++++++++++++---------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/root/etc/config/frigate b/root/etc/config/frigate index 9977b88..34a1254 100644 --- a/root/etc/config/frigate +++ b/root/etc/config/frigate @@ -6,11 +6,11 @@ config frigate_config 'docker' option storage './frigate/storage' config frigate_config 'mqtt' - option mqtt '0' + option enabled '0' option host 'mqtt.server.com' -config frigate_config 'detectors' - option coral '1' +config frigate_config 'tpu' + option enabled '1' option type 'edgetpu' option device 'usb' diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 1100b9d..14fde12 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -10,28 +10,48 @@ get_image() { } do_install_detail() { - local config port IMAGE_NAME username password LAN_IP + local config port IMAGE_NAME LAN_IP local usbcoral hwaccel storage mqtt host coral type device - port=$(uci get frigate.@frigate_config[0].port 2>/dev/null) - IMAGE_NAME=$(uci get frigate.@frigate_config[0].image 2>/dev/null) - usbcoral=$(uci get frigate.@frigate_config[0].usbcoral 2>/dev/null) - hwaccel=$(uci get frigate.@frigate_config[0].hwaccel 2>/dev/null) - storage=$(uci get frigate.@frigate_config[0].storage 2>/dev/null) + echo "Fetching port from configuration..." + port=$(uci get frigate.docker.port 2>/dev/null) + [ -z "$port" ] && { echo "Error: Port not found in configuration."; exit 1; } - mqtt=$(uci get frigate.@frigate_config[0].mqtt 2>/dev/null) - host=$(uci get frigate.@frigate_config[0].host 2>/dev/null) + echo "Fetching image name from configuration..." + IMAGE_NAME=$(uci get frigate.docker.image 2>/dev/null) + [ -z "$IMAGE_NAME" ] && { echo "Error: Image name not found in configuration."; exit 1; } - coral=$(uci get frigate.@frigate_config[0].coral 2>/dev/null) - type=$(uci get frigate.@frigate_config[0].type 2>/dev/null) - device=$(uci get frigate.@frigate_config[0].device 2>/dev/null) + echo "Fetching USB Coral path from configuration..." + usbcoral=$(uci get frigate.docker.usbcoral 2>/dev/null) + [ -z "$usbcoral" ] && { echo "Error: USB Coral path not found in configuration."; exit 1; } - username=$(uci get frigate.@frigate_config[0].username 2>/dev/null) - password=$(uci get frigate.@frigate_config[0].password 2>/dev/null) - APP_NAME="frigate" + echo "Fetching hardware acceleration path from configuration..." + hwaccel=$(uci get frigate.docker.hwaccel 2>/dev/null) + [ -z "$hwaccel" ] && { echo "Error: Hardware acceleration path not found in configuration."; exit 1; } - GEN_PASS=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c 14; echo) - GEN_PASS2=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c 14; echo) + echo "Fetching storage path from configuration..." + storage=$(uci get frigate.docker.storage 2>/dev/null) + [ -z "$storage" ] && { echo "Error: Storage path not found in configuration."; exit 1; } + + echo "Fetching MQTT status from configuration..." + mqtt=$(uci get frigate.mqtt.enabled 2>/dev/null) + [ -z "$mqtt" ] && { echo "Error: MQTT status not found in configuration."; exit 1; } + + echo "Fetching MQTT host from configuration..." + host=$(uci get frigate.mqtt.host 2>/dev/null) + [ -z "$host" ] && { echo "Error: MQTT host not found in configuration."; exit 1; } + + echo "Fetching Coral status from configuration..." + coral=$(uci get frigate.detectors.coral 2>/dev/null) + [ -z "$coral" ] && { echo "Error: Coral status not found in configuration."; exit 1; } + + echo "Fetching Coral type from configuration..." + type=$(uci get frigate.detectors.type 2>/dev/null) + [ -z "$type" ] && { echo "Error: Coral type not found in configuration."; exit 1; } + + echo "Fetching Coral device from configuration..." + device=$(uci get frigate.detectors.device 2>/dev/null) + [ -z "$device" ] && { echo "Error: Coral device not found in configuration."; exit 1; } LAN_IP=$(uci get network.lan.ipaddr) LAN_IP="${LAN_IP%/*}" @@ -44,16 +64,6 @@ do_install_detail() { mkdir -p /opt/docker2/compose/frigate touch /opt/docker2/compose/frigate/config.yml - # Write global settings to config.yml using yq - # Replace these uci get commands with actual commands to get these variables - local usbcoral=$(uci get frigate.@frigate_config[0].usbcoral) - local hwaccel=$(uci get frigate.@frigate_config[0].hwaccel) - local storage=$(uci get frigate.@frigate_config[0].storage) - local mqtt=$(uci get frigate.@frigate_config[0].mqtt) - local host=$(uci get frigate.@frigate_config[0].host) - local coral=$(uci get frigate.@frigate_config[0].coral) - local type=$(uci get frigate.@frigate_config[0].type) - yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml yq eval ".storage = \"$storage\"" -i /opt/docker2/compose/frigate/config.yml -- 2.38.4 From 7c6bbd34a34bc6b814338aeba67eca4f0cb94808 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 16:44:59 -0400 Subject: [PATCH 05/12] updated some config names for clarity --- luasrc/model/cbi/frigate.lua | 2 +- root/usr/libexec/apps/frigate/frigate.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 259e136..631abc5 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -46,7 +46,7 @@ o = s:option(Value, "host", "MQTT Host") o.default = "mqtt.server.com" -- Detectors Configuration -s = m:section(NamedSection, "detectors", "frigate_config", "TPU Configuration") +s = m:section(NamedSection, "tpu", "frigate_config", "TPU Configuration") s.addremove = false s.anonymous = true diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 14fde12..dee2c4f 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -42,15 +42,15 @@ do_install_detail() { [ -z "$host" ] && { echo "Error: MQTT host not found in configuration."; exit 1; } echo "Fetching Coral status from configuration..." - coral=$(uci get frigate.detectors.coral 2>/dev/null) + coral=$(uci get frigate.tpu.enabled 2>/dev/null) [ -z "$coral" ] && { echo "Error: Coral status not found in configuration."; exit 1; } echo "Fetching Coral type from configuration..." - type=$(uci get frigate.detectors.type 2>/dev/null) + type=$(uci get frigate.tpu.type 2>/dev/null) [ -z "$type" ] && { echo "Error: Coral type not found in configuration."; exit 1; } echo "Fetching Coral device from configuration..." - device=$(uci get frigate.detectors.device 2>/dev/null) + device=$(uci get frigate.tpu.device 2>/dev/null) [ -z "$device" ] && { echo "Error: Coral device not found in configuration."; exit 1; } LAN_IP=$(uci get network.lan.ipaddr) -- 2.38.4 From 1837dd868e2d693c61d68b6b5082a4152215be5e Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 16:51:03 -0400 Subject: [PATCH 06/12] updated default port due to Whoogle conflict --- luasrc/model/cbi/frigate.lua | 2 +- root/etc/config/frigate | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 631abc5..6a86144 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -20,7 +20,7 @@ s.addremove = false s.anonymous = true o = s:option(Value, "port", "Port") -o.default = "5000" +o.default = "5100" o = s:option(Value, "image", "Image") o.default = "ghcr.io/blakeblackshear/frigate:stable" diff --git a/root/etc/config/frigate b/root/etc/config/frigate index 34a1254..163f1ee 100644 --- a/root/etc/config/frigate +++ b/root/etc/config/frigate @@ -1,5 +1,5 @@ config frigate_config 'docker' - option port '5000' + option port '5100' option image 'ghcr.io/blakeblackshear/frigate:stable' option usbcoral '/dev/bus/usb' option hwaccel '/dev/crypto' -- 2.38.4 From a6a960f81b6749e39074800f78841e579e79e993 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 16:57:18 -0400 Subject: [PATCH 07/12] Updated status polling --- luasrc/view/frigate/status.htm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/luasrc/view/frigate/status.htm b/luasrc/view/frigate/status.htm index ad9bbaa..df39087 100644 --- a/luasrc/view/frigate/status.htm +++ b/luasrc/view/frigate/status.htm @@ -1,7 +1,7 @@ <% local util = require "luci.util" local container_status = util.trim(util.exec("/usr/libexec/apps/frigate/frigate.sh status")) -local container_running = string.find(string.lower(container_status), "up") and string.find(string.lower(container_status), "(healthy)") +local container_running = string.match(string.lower(container_status), "^up%W") -%>
@@ -16,9 +16,9 @@ local container_running = string.find(string.lower(container_status), "up") and <% if container_running then - local port=util.trim(util.exec("/usr/libexec/apps/frigate/frigate.sh port")) + local port = util.trim(util.exec("/usr/libexec/apps/frigate/frigate.sh port")) if port == "" then - port="1880" + port="5100" end -%>
-- 2.38.4 From 9892b62ca217dc6a0753e6ebfaf4dae4f8bc28a3 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 20 Sep 2023 22:22:34 -0400 Subject: [PATCH 08/12] Major yml config building refactor --- root/usr/libexec/apps/frigate/frigate.sh | 103 ++++++++++++----------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index dee2c4f..a729750 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -59,48 +59,6 @@ do_install_detail() { [ -z "$port" ] && port=1880 [ -z "$IMAGE_NAME" ] && IMAGE_NAME="ghcr.io/blakeblackshear/frigate:stable" - # Initialize counter - local i=0 -mkdir -p /opt/docker2/compose/frigate -touch /opt/docker2/compose/frigate/config.yml - - yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".storage = \"$storage\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".mqtt.enabled = $mqtt" -i /opt/docker2/compose/frigate/config.yml - yq eval ".mqtt.host = \"$host\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".detectors.coral.type = \"$type\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".detectors.coral.device = \"$coral\"" -i /opt/docker2/compose/frigate/config.yml - - # Write each camera's configuration to config.yml - local camera_index=0 - while : ; do - # Try to fetch camera configuration - local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null) - # Exit loop if no more cameras are found - [[ -z "$name" ]] && break - - # Retrieve the rest of the camera settings here... - local path=$(uci get frigate.@camera_config[$camera_index].path) - local roles=$(uci get frigate.@camera_config[$camera_index].roles) - local record=$(uci get frigate.@camera_config[$camera_index].record) - local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots) - local mask=$(uci get frigate.@camera_config[$camera_index].mask) - - # Write to config.yml using yq - yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"$path\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.ffmpeg.inputs[0].roles[0] = \"detect\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.detect.width = 1280" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.detect.height = 720" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.record.enabled = $record" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.snapshots.enabled = $snapshots" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.motion.mask[0] = \"$mask\"" -i /opt/docker2/compose/frigate/config.yml - - camera_index=$((camera_index+1)) - done - - - rm -r /opt/docker2/compose/frigate 2>/dev/null mkdir -p /opt/docker2/compose/frigate @@ -137,6 +95,49 @@ services: FRIGATE_RTSP_PASSWORD: "password" EOF + # Initialize the base structure + echo "{}" > /opt/docker2/compose/frigate/config.yml + + # Set global configurations + yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".storage = \"$storage\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".mqtt.enabled = $mqtt" -i /opt/docker2/compose/frigate/config.yml + yq eval ".mqtt.host = \"$host\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".detectors.coral.type = \"$type\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".detectors.coral.device = \"$coral\"" -i /opt/docker2/compose/frigate/config.yml + + # Initialize cameras structure + yq eval ".cameras = {}" -i /opt/docker2/compose/frigate/config.yml + + # Write each camera's configuration to config.yml + local camera_index=0 + while : ; do + # Try to fetch camera configuration + local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null) + # Exit loop if no more cameras are found + [[ -z "$name" ]] && break + + # Retrieve the rest of the camera settings here... + local path=$(uci get frigate.@camera_config[$camera_index].path) + local roles=$(uci get frigate.@camera_config[$camera_index].roles) + local record=$(uci get frigate.@camera_config[$camera_index].record) + local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots) + local mask=$(uci get frigate.@camera_config[$camera_index].mask) + + # Initialize camera structure + yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml + + # Write to config.yml using yq + yq eval ".cameras.$name.ffmpeg = { inputs: [{ path: \"$path\", roles: [\"detect\"] }] }" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.detect = { width: 1280, height: 720 }" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.record = { enabled: $record }" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.snapshots = { enabled: $snapshots }" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.motion = { mask: [\"$mask\"] }" -i /opt/docker2/compose/frigate/config.yml + + camera_index=$((camera_index+1)) + done + docker-compose -f /opt/docker2/compose/frigate/docker-compose.yml up -d uci add shortcutmenu lists @@ -174,7 +175,7 @@ case "${ACTION}" in ;; "start" | "stop" | "restart") APP_NAME="frigate" - CONTAINER_IDS=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.ID}}') + CONTAINER_IDS=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.ID}}') for ID in $CONTAINER_IDS; do docker "${ACTION}" "${ID}" done @@ -184,18 +185,18 @@ case "${ACTION}" in CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }') if [ -z "$CONTAINER_NAME" ]; then - echo "${APP_NAME} is not installed" + echo "${APP_NAME} is not installed" else echo "${CONTAINER_STATUS}" fi ;; - "port") +"port") APP_NAME="frigate" - CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.Names}}') - docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Ports}}' | grep -o -m1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://' - ;; - *) - usage - exit 1 + CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') + # Fetch the port from UCI configuration + uci_port=$(uci get frigate.docker.port 2>/dev/null) + [ -z "$uci_port" ] && exit 1 # Exit silently if UCI port is not found + # Use the UCI port to filter the docker ps output and return only the external port + docker ps --all -f "name=${CONTAINER_NAME}" --format '{{.Ports}}' | grep -o "0.0.0.0:$uci_port->[0-9]*/tcp" | sed "s/0.0.0.0://;s/->[0-9]*\/tcp//" ;; esac \ No newline at end of file -- 2.38.4 From 11d26ffe105ca77fd35682988fa068e21a0a2737 Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 21 Sep 2023 00:20:07 -0400 Subject: [PATCH 09/12] More config building refactors --- root/usr/libexec/apps/frigate/frigate.sh | 37 +++++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index a729750..190eb23 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -42,7 +42,7 @@ do_install_detail() { [ -z "$host" ] && { echo "Error: MQTT host not found in configuration."; exit 1; } echo "Fetching Coral status from configuration..." - coral=$(uci get frigate.tpu.enabled 2>/dev/null) + coral=$(uci get frigate.tpu.device 2>/dev/null) [ -z "$coral" ] && { echo "Error: Coral status not found in configuration."; exit 1; } echo "Fetching Coral type from configuration..." @@ -99,9 +99,9 @@ EOF echo "{}" > /opt/docker2/compose/frigate/config.yml # Set global configurations - yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".storage = \"$storage\"" -i /opt/docker2/compose/frigate/config.yml + # yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml + # yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml + # yq eval ".media.storage = \"$storage\"" -i /opt/docker2/compose/frigate/config.yml yq eval ".mqtt.enabled = $mqtt" -i /opt/docker2/compose/frigate/config.yml yq eval ".mqtt.host = \"$host\"" -i /opt/docker2/compose/frigate/config.yml yq eval ".detectors.coral.type = \"$type\"" -i /opt/docker2/compose/frigate/config.yml @@ -114,7 +114,7 @@ EOF local camera_index=0 while : ; do # Try to fetch camera configuration - local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null) + local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null | tr ' ' '_') # Exit loop if no more cameras are found [[ -z "$name" ]] && break @@ -128,12 +128,27 @@ EOF # Initialize camera structure yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml - # Write to config.yml using yq - yq eval ".cameras.$name.ffmpeg = { inputs: [{ path: \"$path\", roles: [\"detect\"] }] }" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.detect = { width: 1280, height: 720 }" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.record = { enabled: $record }" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.snapshots = { enabled: $snapshots }" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.motion = { mask: [\"$mask\"] }" -i /opt/docker2/compose/frigate/config.yml + # Initialize ffmpeg and inputs for each camera + yq eval ".cameras.$name.ffmpeg = {}" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.ffmpeg.inputs = []" -i /opt/docker2/compose/frigate/config.yml + + # Add path and roles to the inputs + yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"\\\"$path\\\"\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml + + # Add other camera settings + yq eval ".cameras.$name.detect = {}" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.detect.width = 1280" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.detect.height = 720" -i /opt/docker2/compose/frigate/config.yml + + yq eval ".cameras.$name.record = {}" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.record.enabled = $record" -i /opt/docker2/compose/frigate/config.yml + + yq eval ".cameras.$name.snapshots = {}" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.snapshots.enabled = $snapshots" -i /opt/docker2/compose/frigate/config.yml + + yq eval ".cameras.$name.motion = {}" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.motion.mask = [\"$mask\"]" -i /opt/docker2/compose/frigate/config.yml camera_index=$((camera_index+1)) done -- 2.38.4 From 03bd47480eca74a1d601f1d3c1519ace087b49ed Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 21 Sep 2023 14:20:32 -0400 Subject: [PATCH 10/12] Fixed url quoting --- root/usr/libexec/apps/frigate/frigate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 190eb23..e066e08 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -133,7 +133,7 @@ EOF yq eval ".cameras.$name.ffmpeg.inputs = []" -i /opt/docker2/compose/frigate/config.yml # Add path and roles to the inputs - yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"\\\"$path\\\"\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.ffmpeg.inputs[0].path = $path" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml # Add other camera settings -- 2.38.4 From 2ea76daa359408ccec3b55702f81332d69ef6baf Mon Sep 17 00:00:00 2001 From: Jason Hawks Date: Thu, 21 Sep 2023 20:29:34 -0400 Subject: [PATCH 11/12] Makefile Fix --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index ff14318..2066a9e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,11 @@ include $(TOPDIR)/rules.mk +PKG_MAINTAINER:=Jason Hawks + +PKG_NAME:=luci-app-frigate +PKG_VERSION:=1.0.0 +PKG_RELEASE:=1 LUCI_TITLE:=LuCI support for frigate LUCI_PKGARCH:=all -- 2.38.4 From 7fa6305168c0a7da0c32f77de8be3c9726fd9c0b Mon Sep 17 00:00:00 2001 From: Jason Hawks Date: Fri, 22 Sep 2023 14:10:26 -0400 Subject: [PATCH 12/12] Remove unnecessary stuff, clean up code, fix yaml parsing bugs Also always use --force-recreate on docker-compose --- root/usr/libexec/apps/frigate/frigate.sh | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index e066e08..97ece0c 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -119,11 +119,11 @@ EOF [[ -z "$name" ]] && break # Retrieve the rest of the camera settings here... - local path=$(uci get frigate.@camera_config[$camera_index].path) - local roles=$(uci get frigate.@camera_config[$camera_index].roles) - local record=$(uci get frigate.@camera_config[$camera_index].record) - local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots) - local mask=$(uci get frigate.@camera_config[$camera_index].mask) + local path=$(uci get frigate.@camera_config[$camera_index].path 2>/dev/null) + local roles=$(uci get frigate.@camera_config[$camera_index].roles 2>/dev/null) + local record=$(uci get frigate.@camera_config[$camera_index].record 2>/dev/null) + local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots 2>/dev/null) + local mask=$(uci get frigate.@camera_config[$camera_index].mask 2>/dev/null) # Initialize camera structure yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml @@ -133,7 +133,7 @@ EOF yq eval ".cameras.$name.ffmpeg.inputs = []" -i /opt/docker2/compose/frigate/config.yml # Add path and roles to the inputs - yq eval ".cameras.$name.ffmpeg.inputs[0].path = $path" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"$path\"" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml # Add other camera settings @@ -147,13 +147,19 @@ EOF yq eval ".cameras.$name.snapshots = {}" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.snapshots.enabled = $snapshots" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.motion = {}" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.motion.mask = [\"$mask\"]" -i /opt/docker2/compose/frigate/config.yml + # Check if the mask is not empty + if [ -n "$mask" ]; then + # Run the yq commands to update the YAML file + yq eval ".cameras.$name.motion = {}" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.motion.mask = [\"$mask\"]" -i /opt/docker2/compose/frigate/config.yml + else + echo "Mask is empty, ignoring." + fi camera_index=$((camera_index+1)) done - docker-compose -f /opt/docker2/compose/frigate/docker-compose.yml up -d + docker-compose -f /opt/docker2/compose/frigate/docker-compose.yml up -d --force-recreate uci add shortcutmenu lists uci set shortcutmenu.@lists[-1].webname="$APP_NAME" @@ -189,14 +195,12 @@ case "${ACTION}" in rm -r /opt/docker2/compose/frigate 2>/dev/null ;; "start" | "stop" | "restart") - APP_NAME="frigate" CONTAINER_IDS=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.ID}}') for ID in $CONTAINER_IDS; do docker "${ACTION}" "${ID}" done ;; "status") - APP_NAME="frigate" CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }') if [ -z "$CONTAINER_NAME" ]; then @@ -205,8 +209,7 @@ case "${ACTION}" in echo "${CONTAINER_STATUS}" fi ;; -"port") - APP_NAME="frigate" + "port") CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') # Fetch the port from UCI configuration uci_port=$(uci get frigate.docker.port 2>/dev/null) -- 2.38.4