From 4ce2f3bf00851a83213f48b3c1b505e65271905b Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 26 Sep 2023 17:29:02 -0400 Subject: [PATCH 01/24] removed unused function --- root/usr/libexec/apps/frigate/frigate.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 97ece0c..2730a29 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -5,10 +5,6 @@ APP_NAME="frigate" ACTION="${1}" shift 1 -get_image() { - do_install_detail -} - do_install_detail() { local config port IMAGE_NAME LAN_IP local usbcoral hwaccel storage mqtt host coral type device @@ -178,6 +174,7 @@ usage() { echo " port frigate port" } + case "${ACTION}" in "install" | "upgrade") do_install_detail -- 2.38.4 From e07da23f195e6e1bf86ee62a09acd353c3d73c44 Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 26 Sep 2023 20:46:38 -0400 Subject: [PATCH 02/24] Testing new config fetching function --- root/usr/libexec/apps/frigate/frigate.sh | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 2730a29..7065608 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -174,6 +174,51 @@ usage() { echo " port frigate port" } +sync_camera_config() { + echo "Starting sync_camera_config..." + + # First, handle additions: + local camera_index=0 + while : ; do + local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null | tr ' ' '_') + if [[ -z "$name" ]]; then + echo "No more cameras found in UCI at index $camera_index. Moving to deletions..." + break + fi + echo "Processing UCI camera named: $name" + + # Check if the camera is in the YML + if ! yq eval "has(.cameras.$name)" /opt/docker2/compose/frigate/config.yml; then + echo "Camera $name not found in YML, adding..." + + # Initialize camera structure in YML + yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml + echo "Initialized $name in YML" + # ... Add other camera configurations here as needed ... + + else + echo "Camera $name already exists in YML. Skipping addition." + fi + camera_index=$((camera_index+1)) + done + + # Then, handle deletions: + local cameras_in_yml=$(yq eval '.cameras | keys[]' /opt/docker2/compose/frigate/config.yml) + echo "Checking for cameras in YML that are not in UCI..." + for camera_name in $cameras_in_yml; do + echo "Validating camera: $camera_name in UCI" + if ! uci get frigate.@camera_config[*].name | grep -q "^$camera_name$"; then + echo "Camera $camera_name not found in UCI, removing from YML..." + yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml + echo "Removed $camera_name from YML" + else + echo "Camera $camera_name found in UCI. No deletion needed." + fi + done + + echo "sync_camera_config completed!" +} + case "${ACTION}" in "install" | "upgrade") -- 2.38.4 From cfeecbdf1f00b61b039382b494162c569eaf1e74 Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 26 Sep 2023 21:11:42 -0400 Subject: [PATCH 03/24] Fixed yq syntax --- root/usr/libexec/apps/frigate/frigate.sh | 35 +++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 7065608..56314d3 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -202,19 +202,28 @@ sync_camera_config() { camera_index=$((camera_index+1)) done - # Then, handle deletions: - local cameras_in_yml=$(yq eval '.cameras | keys[]' /opt/docker2/compose/frigate/config.yml) - echo "Checking for cameras in YML that are not in UCI..." - for camera_name in $cameras_in_yml; do - echo "Validating camera: $camera_name in UCI" - if ! uci get frigate.@camera_config[*].name | grep -q "^$camera_name$"; then - echo "Camera $camera_name not found in UCI, removing from YML..." - yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml - echo "Removed $camera_name from YML" - else - echo "Camera $camera_name found in UCI. No deletion needed." - fi - done + # Then, handle deletions: + local num_cameras=$(yq eval '.cameras | length' /opt/docker2/compose/frigate/config.yml 2>/dev/null) + local i=0 + local cameras_in_yml="" + + while [ "$i" -lt "$num_cameras" ]; do + local camera_name=$(yq eval ".cameras | keys[$i]" /opt/docker2/compose/frigate/config.yml 2>/dev/null) + cameras_in_yml="$cameras_in_yml $camera_name" + i=$((i+1)) + done + + echo "Checking for cameras in YML that are not in UCI..." + for camera_name in $cameras_in_yml; do + echo "Validating camera: $camera_name in UCI" + if ! uci get frigate.@camera_config[*].name | grep -q "^$camera_name$"; then + echo "Camera $camera_name not found in UCI, removing from YML..." + yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml + echo "Removed $camera_name from YML" + else + echo "Camera $camera_name found in UCI. No deletion needed." + fi + done echo "sync_camera_config completed!" } -- 2.38.4 From 7a39a260868acf3881822150765553e3a064564e Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 26 Sep 2023 22:31:02 -0400 Subject: [PATCH 04/24] Added default values for camera checkboxes --- luasrc/model/cbi/frigate.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 6a86144..2a495e7 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -69,7 +69,9 @@ o = s:option(Value, "name", "Camera Name") o = s:option(Value, "path", "RTSP Path") o = s:option(Value, "roles", "Roles") o = s:option(Flag, "record", "Enable Recording") +o.default = "0" o = s:option(Flag, "snapshots", "Enable Snapshots") +o.default = "0" o = s:option(Value, "mask", "Mask") return m \ No newline at end of file -- 2.38.4 From c4b16c4b18b0bb1c5f3ff8c708615cc29cd3096c Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 26 Sep 2023 23:00:38 -0400 Subject: [PATCH 05/24] More data formatting changes for adding new cameras --- luasrc/model/cbi/frigate.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 2a495e7..62cc3e3 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -70,8 +70,10 @@ o = s:option(Value, "path", "RTSP Path") o = s:option(Value, "roles", "Roles") o = s:option(Flag, "record", "Enable Recording") o.default = "0" +o.rmempty = false o = s:option(Flag, "snapshots", "Enable Snapshots") o.default = "0" +o.rmempty = false o = s:option(Value, "mask", "Mask") return m \ No newline at end of file -- 2.38.4 From 5f76355289d5c3e0106574f12ea47a51fafffd0c Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 00:04:47 -0400 Subject: [PATCH 06/24] changed from named section to typed section --- root/etc/config/frigate | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/root/etc/config/frigate b/root/etc/config/frigate index 163f1ee..9f3a452 100644 --- a/root/etc/config/frigate +++ b/root/etc/config/frigate @@ -14,7 +14,7 @@ config frigate_config 'tpu' option type 'edgetpu' option device 'usb' -config camera_config 'cam1' +config camera_config option name 'living_room' option path 'rtsp://admin:password@192.168.70.173:554/cam/realmonitor?channel=1&subtype=0&authbasic=64' option roles 'detect' @@ -22,7 +22,7 @@ config camera_config 'cam1' option snapshots '1' option mask '0,461,3,0,1919,0,1919,843,1699,492,1344,458,1346,336,973,317,869,375,866,432' -config camera_config 'cam2' +config camera_config option name 'upstairs_bedroom' option path 'rtsp://admin:password@192.168.70.173:554/cam/realmonitor?channel=1&subtype=0&authbasic=64' option roles 'detect' @@ -30,7 +30,7 @@ config camera_config 'cam2' option snapshots '1' option mask '0,461,3,0,1919,0,1919,843,1699,492,1344,458,1346,336,973,317,869,375,866,432' -config camera_config 'cam3' +config camera_config option name 'kitchen' option path 'rtsp://admin:password@192.168.70.173:554/cam/realmonitor?channel=1&subtype=0&authbasic=64' option roles 'detect' -- 2.38.4 From 1bf23bf3560a9272863a141afc73dc7a64073285 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 00:40:56 -0400 Subject: [PATCH 07/24] Major refactor of frigate.sh Adds the ability to sync UCI camera values to the frigate config.yml --- root/usr/libexec/apps/frigate/frigate.sh | 246 +++++++++++++++++------ 1 file changed, 181 insertions(+), 65 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 56314d3..99ca06f 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -5,51 +5,55 @@ APP_NAME="frigate" ACTION="${1}" shift 1 +fetch_and_validate_uci () { + local config_name=$1 + local config_attr=$2 + + local result=$(uci get frigate.$config_name.$config_attr 2>/dev/null) + if [ -z "$result" ]; then + echo "Error: $config_name not found in configuration." + exit 1 + fi + + echo "Fetched $config_name from configuration: $result" + echo $result +} + do_install_detail() { local config port IMAGE_NAME LAN_IP local usbcoral hwaccel storage mqtt host coral type device 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; } - + port=$(fetch_and_validate_uci docker port) + 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; } + IMAGE_NAME=$(fetch_and_validate_uci docker image) 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; } + usbcoral=$(fetch_and_validate_uci docker usbcoral) 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; } + hwaccel=$(fetch_and_validate_uci docker hwaccel) 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; } + storage=$(fetch_and_validate_uci docker storage) 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; } + mqtt=$(fetch_and_validate_uci mqtt enabled) 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; } + host=$(fetch_and_validate_uci mqtt host) echo "Fetching Coral status from configuration..." - coral=$(uci get frigate.tpu.device 2>/dev/null) - [ -z "$coral" ] && { echo "Error: Coral status not found in configuration."; exit 1; } + coral=$(fetch_and_validate_uci tpu device) echo "Fetching Coral type from configuration..." - type=$(uci get frigate.tpu.type 2>/dev/null) - [ -z "$type" ] && { echo "Error: Coral type not found in configuration."; exit 1; } + type=$(fetch_and_validate_uci tpu type) echo "Fetching Coral device from configuration..." - device=$(uci get frigate.tpu.device 2>/dev/null) - [ -z "$device" ] && { echo "Error: Coral device not found in configuration."; exit 1; } + device=$(fetch_and_validate_uci tpu device) - LAN_IP=$(uci get network.lan.ipaddr) + LAN_IP=$(fetch_and_validate_uci network.lan) LAN_IP="${LAN_IP%/*}" [ -z "$port" ] && port=1880 @@ -103,6 +107,7 @@ EOF 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 @@ -174,61 +179,169 @@ usage() { echo " port frigate port" } -sync_camera_config() { - echo "Starting sync_camera_config..." - - # First, handle additions: - local camera_index=0 - while : ; do - local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null | tr ' ' '_') - if [[ -z "$name" ]]; then - echo "No more cameras found in UCI at index $camera_index. Moving to deletions..." +# Gets a specific setting for a camera. If no setting is provided, it retrieves the camera name. +get_uci_camera_value() { + local index=$1 + local setting=${2:-name} + uci get frigate.@camera_config[$index].$setting 2>/dev/null | tr ' ' '_' +} + +# Sets a specific setting for a camera +set_uci_camera_value() { + local name=$1 + local setting=$2 + local value=$3 + uci set frigate.@camera_config[@$name].$setting=$value + uci commit frigate +} + +# YML Helper Functions + +# Retrieves a specific setting from the YML. If no setting_path is provided, it retrieves the camera name. +get_yml_value() { + local name=$1 + local setting_path=${2:-} + yq eval ".cameras.$name$setting_path" /opt/docker2/compose/frigate/config.yml +} + +# Sets a specific setting in the YML +set_yml_value() { + local name=$1 + local setting_path=$2 + local value=$3 + # If the value starts with "{", "[", or is a number, we don't quote it; otherwise, we do. + case "$value" in + "{"*|"["*|*[0-9]*) + # do nothing + ;; + *) + value="\"$value\"" + ;; + esac + yq eval ".cameras.$name$setting_path = $value" -i /opt/docker2/compose/frigate/config.yml +} + +write_camera_to_yml() { + local name=$1 + local camera_index="" + local lines=$(uci show frigate | grep '@camera_config') + IFS=$'\n' + for line in $lines + do + if [[ $line == *".name='$name'"* ]] + then + camera_index=$(echo $line | grep -E -o "@camera_config\[[0-9]+\]" | grep -E -o "[0-9]+" ) break fi - echo "Processing UCI camera named: $name" - - # Check if the camera is in the YML - if ! yq eval "has(.cameras.$name)" /opt/docker2/compose/frigate/config.yml; then - echo "Camera $name not found in YML, adding..." - - # Initialize camera structure in YML - yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml - echo "Initialized $name in YML" - # ... Add other camera configurations here as needed ... - - else - echo "Camera $name already exists in YML. Skipping addition." - fi - camera_index=$((camera_index+1)) done - # Then, handle deletions: - local num_cameras=$(yq eval '.cameras | length' /opt/docker2/compose/frigate/config.yml 2>/dev/null) - local i=0 - local cameras_in_yml="" + if [[ -z "$camera_index" ]] + then + echo "Camera $name not found in UCI" + return + fi + + # Retrieves the rest of the camera settings from UCI... + 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 in YML + yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml + + # Initialize ffmpeg and inputs for each camera in YML + 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 in 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 to YML + 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 + + # 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 +} + +update_camera_in_yml() { + local name=$1 + # Deletes the camera from the YML file and writes it again + yq eval "del(.cameras.$name)" -i /opt/docker2/compose/frigate/config.yml + write_camera_to_yml $name +} + + - while [ "$i" -lt "$num_cameras" ]; do - local camera_name=$(yq eval ".cameras | keys[$i]" /opt/docker2/compose/frigate/config.yml 2>/dev/null) - cameras_in_yml="$cameras_in_yml $camera_name" - i=$((i+1)) + +sync_camera_config() { + echo "Starting sync_camera_config..." + + # Fetching all cameras from UCI + local uci_cameras="" + local camera_index=0 + while : ; do + local name=$(get_uci_camera_value $camera_index) + # Exit loop if no more cameras are found + [[ -z "$name" ]] && break + + uci_cameras="$uci_cameras $name" + camera_index=$((camera_index+1)) done - echo "Checking for cameras in YML that are not in UCI..." - for camera_name in $cameras_in_yml; do - echo "Validating camera: $camera_name in UCI" - if ! uci get frigate.@camera_config[*].name | grep -q "^$camera_name$"; then - echo "Camera $camera_name not found in UCI, removing from YML..." - yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml - echo "Removed $camera_name from YML" - else - echo "Camera $camera_name found in UCI. No deletion needed." - fi + echo "Cameras fetched from UCI: $uci_cameras" + + # Fetching all cameras from Frigate YML + local yml_cameras=$(yq eval '.cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs) + + echo "Cameras fetched from YML: $yml_cameras" + + # Checking for cameras in UCI that are not in YML and adding them + for camera_name in $uci_cameras; do + if ! echo "$yml_cameras" | grep -q "$camera_name"; then + echo "Camera $camera_name not found in YML, adding..." + # Retrieves camera settings from UCI configuration and adds them to the YML file. + write_camera_to_yml $camera_name + else + echo "Camera $camera_name found in YML, updating..." + # Retrieves camera settings from UCI configuration and updates them in the YML file. + update_camera_in_yml $camera_name + fi done - echo "sync_camera_config completed!" + # Checking for cameras in YML that are not in UCI and deleting them + if [[ $yml_cameras != '[]' ]]; then # Add this condition + for camera_name in $yml_cameras; do + if ! echo "$uci_cameras" | grep -q "$camera_name"; then + echo "Camera $camera_name not found in UCI, removing from YML..." + yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml + fi + done + fi # Close the condition + + echo "sync_camera_config completed!" } + + + case "${ACTION}" in "install" | "upgrade") do_install_detail @@ -268,4 +381,7 @@ case "${ACTION}" in # 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//" ;; + "sync") + sync_camera_config + ;; esac \ No newline at end of file -- 2.38.4 From 8b997a53bf069435697aa507c5ed04cb3f8c64d3 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 02:36:45 -0400 Subject: [PATCH 08/24] WIP frigate config syncing improvements --- root/usr/libexec/apps/frigate/frigate.sh | 107 ++++++++++++++--------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 99ca06f..c0c6bfc 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -4,6 +4,7 @@ APP_NAME="frigate" ACTION="${1}" shift 1 +set -x fetch_and_validate_uci () { local config_name=$1 @@ -280,67 +281,91 @@ write_camera_to_yml() { fi } -update_camera_in_yml() { - local name=$1 - # Deletes the camera from the YML file and writes it again - yq eval "del(.cameras.$name)" -i /opt/docker2/compose/frigate/config.yml - write_camera_to_yml $name +get_camera_index_by_name() { + local name=$1 + local camera_index=0 + while : ; do + local current_name=$(get_uci_camera_value $camera_index) + [[ "$current_name" == "$name" ]] && echo $camera_index && break + [[ -z "$current_name" ]] && break + camera_index=$((camera_index+1)) + done } +update_camera_in_yml() { + local name=$1 + # Get the index of the camera with name "$name" + local camera_index=$(get_camera_index_by_name $name) + # Fetch and Update the specific settings for this camera from UCI -> YAML + local path=$(get_uci_camera_value $camera_index "path") + set_yml_value $name ".ffmpeg.inputs[0].path" $path + + local roles=$(get_uci_camera_value $camera_index "roles") + set_yml_value $name ".ffmpeg.inputs[0].roles" $roles -sync_camera_config() { - echo "Starting sync_camera_config..." + local record=$(get_uci_camera_value $camera_index "record") + set_yml_value $name ".record.enabled" $record - # Fetching all cameras from UCI - local uci_cameras="" - local camera_index=0 - while : ; do - local name=$(get_uci_camera_value $camera_index) - # Exit loop if no more cameras are found - [[ -z "$name" ]] && break + local snapshots=$(get_uci_camera_value $camera_index "snapshots") + set_yml_value $name ".snapshots.enabled" $snapshots - uci_cameras="$uci_cameras $name" - camera_index=$((camera_index+1)) - done + local mask=$(get_uci_camera_value $camera_index "mask") + if [ -n "$mask" ]; then + set_yml_value $name ".motion.mask" $mask + else + echo "Mask is empty, ignoring." + fi +} - echo "Cameras fetched from UCI: $uci_cameras" +sync_camera_config() { + echo "Starting sync_camera_config..." - # Fetching all cameras from Frigate YML - local yml_cameras=$(yq eval '.cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs) + # Initializing the camera index + camera_index=0 + # Fetching all cameras from frigate YML + yml_cameras=$(yq eval '.cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs) + echo "Cameras fetched from YML: $yml_cameras" - # Checking for cameras in UCI that are not in YML and adding them - for camera_name in $uci_cameras; do - if ! echo "$yml_cameras" | grep -q "$camera_name"; then + # Loop through all camera configs in UCI using index + while true; do + # Try to fetch camera configuration + local camera_name=$(get_uci_camera_value $camera_index) + + # Exit loop if no more cameras are found + [ -z "$camera_name" ] && break + + if ! echo "$yml_cameras" | grep -q -w "$camera_name"; then echo "Camera $camera_name not found in YML, adding..." - # Retrieves camera settings from UCI configuration and adds them to the YML file. write_camera_to_yml $camera_name else echo "Camera $camera_name found in YML, updating..." - # Retrieves camera settings from UCI configuration and updates them in the YML file. update_camera_in_yml $camera_name fi - done - - # Checking for cameras in YML that are not in UCI and deleting them - if [[ $yml_cameras != '[]' ]]; then # Add this condition - for camera_name in $yml_cameras; do - if ! echo "$uci_cameras" | grep -q "$camera_name"; then - echo "Camera $camera_name not found in UCI, removing from YML..." - yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml - fi - done - fi # Close the condition - - echo "sync_camera_config completed!" -} + # Add to uci_cameras + uci_cameras="${uci_cameras} ${camera_name}" + # Increment camera index + camera_index=$((camera_index+1)) + done + # Crosscheck and remove any old cameras in YML not present in UCI config + for yml_camera in $yml_cameras; do + # Fix for word splitting + set -f + if ! echo $uci_cameras | grep -q -w "$yml_camera"; then + echo "Camera $yml_camera found in YML, but not in UCI, removing..." + yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml + fi + set +f + done + echo "sync_camera_config completed!" +} case "${ACTION}" in "install" | "upgrade") @@ -362,6 +387,7 @@ case "${ACTION}" in CONTAINER_IDS=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.ID}}') for ID in $CONTAINER_IDS; do docker "${ACTION}" "${ID}" + sync_camera_config done ;; "status") @@ -381,7 +407,4 @@ case "${ACTION}" in # 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//" ;; - "sync") - sync_camera_config - ;; esac \ No newline at end of file -- 2.38.4 From 19e0eb4d19797d6f9be97ffb51ca9d361ee4e031 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 12:03:32 -0400 Subject: [PATCH 09/24] Minor bug fixes --- root/usr/libexec/apps/frigate/frigate.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index c0c6bfc..87b9c58 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -4,7 +4,7 @@ APP_NAME="frigate" ACTION="${1}" shift 1 -set -x +#set -x fetch_and_validate_uci () { local config_name=$1 @@ -12,11 +12,11 @@ fetch_and_validate_uci () { local result=$(uci get frigate.$config_name.$config_attr 2>/dev/null) if [ -z "$result" ]; then - echo "Error: $config_name not found in configuration." + echo "Error: $config_name not found in configuration." >&2 exit 1 fi - echo "Fetched $config_name from configuration: $result" + echo "Fetched $config_name from configuration: $result" >&2 echo $result } @@ -313,7 +313,7 @@ update_camera_in_yml() { local mask=$(get_uci_camera_value $camera_index "mask") if [ -n "$mask" ]; then - set_yml_value $name ".motion.mask" $mask + set_yml_value $name ".motion.mask" "[\"$mask\"]" else echo "Mask is empty, ignoring." fi -- 2.38.4 From f43d76bff192e63ea78ae8e897c9a599f41e7337 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 12:06:58 -0400 Subject: [PATCH 10/24] Fixed IP fetching --- 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 87b9c58..7f6c40c 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -54,7 +54,7 @@ do_install_detail() { echo "Fetching Coral device from configuration..." device=$(fetch_and_validate_uci tpu device) - LAN_IP=$(fetch_and_validate_uci network.lan) + LAN_IP=$(uci get network.lan.ipaddr) LAN_IP="${LAN_IP%/*}" [ -z "$port" ] && port=1880 -- 2.38.4 From 230891628ec234cba510f4685706dc7c4bc60ebc Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 12:22:56 -0400 Subject: [PATCH 11/24] Updated mask handling --- 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 7f6c40c..fb6b94d 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -315,7 +315,7 @@ update_camera_in_yml() { if [ -n "$mask" ]; then set_yml_value $name ".motion.mask" "[\"$mask\"]" else - echo "Mask is empty, ignoring." + yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml fi } -- 2.38.4 From 2d5fa7ae40c79ae54c8f6c439335791164a79efa Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 16:53:19 -0400 Subject: [PATCH 12/24] Readability improvements and general cleanup --- root/usr/libexec/apps/frigate/frigate.sh | 50 ++---------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index fb6b94d..0d3886f 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -108,10 +108,6 @@ EOF 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 @@ -119,45 +115,7 @@ EOF 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 - - # Retrieve the rest of the camera settings here... - 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 - - # 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 - - # 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 - + write_camera_to_yml $name camera_index=$((camera_index+1)) done @@ -320,7 +278,7 @@ update_camera_in_yml() { } sync_camera_config() { - echo "Starting sync_camera_config..." + echo "Syncing camera config..." # Initializing the camera index camera_index=0 @@ -339,10 +297,10 @@ sync_camera_config() { [ -z "$camera_name" ] && break if ! echo "$yml_cameras" | grep -q -w "$camera_name"; then - echo "Camera $camera_name not found in YML, adding..." + echo "UCI Camera $camera_name not found in YML, adding..." write_camera_to_yml $camera_name else - echo "Camera $camera_name found in YML, updating..." + echo "UCI Camera $camera_name found in YML, updating..." update_camera_in_yml $camera_name fi -- 2.38.4 From 1374f4ead91d044510819ed13b71200ca32a7619 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 16:53:56 -0400 Subject: [PATCH 13/24] Added commenting to YML file to alert users of UCI overwriting --- root/usr/libexec/apps/frigate/frigate.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 0d3886f..7d941f0 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -250,6 +250,21 @@ get_camera_index_by_name() { done } +# Toggles the line comment for a specific camera attribute in the YML +toggle_override() { + local name=$1 + local attribute=$2 + local current_comment=$(yq eval ".cameras.$name.$attribute | line_comment" /opt/docker2/compose/frigate/config.yml) + + if [ "$current_comment" = "OVERWRITTEN_BY_UCI" ]; then + # If the current comment is "OVERWRITTEN_BY_UCI", remove it by setting it to nothing + yq eval ".cameras.$name.$attribute line_comment=\"\"" -i /opt/docker2/compose/frigate/config.yml + else + # Otherwise, set the comment to "OVERWRITTEN_BY_UCI" + yq eval ".cameras.$name.$attribute line_comment=\"OVERWRITTEN_BY_UCI\"" -i /opt/docker2/compose/frigate/config.yml + fi +} + update_camera_in_yml() { local name=$1 -- 2.38.4 From 18a7067dca052bd849a1a91c635ddbed04d52a7a Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 16:54:15 -0400 Subject: [PATCH 14/24] Syntax fix --- 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 7d941f0..57e0b72 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -273,7 +273,7 @@ update_camera_in_yml() { # Fetch and Update the specific settings for this camera from UCI -> YAML local path=$(get_uci_camera_value $camera_index "path") - set_yml_value $name ".ffmpeg.inputs[0].path" $path + set_yml_value $name ".ffmpeg.inputs[0].path" "\"$path\"" local roles=$(get_uci_camera_value $camera_index "roles") set_yml_value $name ".ffmpeg.inputs[0].roles" $roles -- 2.38.4 From 7bc9c3d2b6b11e9ae25b97c1cb8f607ad4596dce Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 16:54:59 -0400 Subject: [PATCH 15/24] Added UCI flag to control if camera configs get overwritten by UCI --- luasrc/model/cbi/frigate.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 62cc3e3..59d1f66 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -68,12 +68,23 @@ s.novaluetext = "There are no cameras configured yet." o = s:option(Value, "name", "Camera Name") o = s:option(Value, "path", "RTSP Path") o = s:option(Value, "roles", "Roles") + o = s:option(Flag, "record", "Enable Recording") o.default = "0" o.rmempty = false + o = s:option(Flag, "snapshots", "Enable Snapshots") o.default = "0" o.rmempty = false + o = s:option(Value, "mask", "Mask") +-- Add the new flag for Overwrite Frigate Config +o = s:option(Flag, "overwrite_cfg", "Overwrite Frigate Config") +o.default = "1" +o.rmempty = false + +return m + + return m \ No newline at end of file -- 2.38.4 From d7f316f26ba4112633eda3d8c8d7f5037366d3ca Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 18:21:54 -0400 Subject: [PATCH 16/24] Added comments in YML for clarity, handle YML camera creation --- root/etc/config/frigate | 19 +----- root/usr/libexec/apps/frigate/frigate.sh | 80 +++++++++++++++++------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/root/etc/config/frigate b/root/etc/config/frigate index 9f3a452..48cf692 100644 --- a/root/etc/config/frigate +++ b/root/etc/config/frigate @@ -20,21 +20,6 @@ config camera_config option roles 'detect' option record '1' option snapshots '1' - option mask '0,461,3,0,1919,0,1919,843,1699,492,1344,458,1346,336,973,317,869,375,866,432' - -config camera_config - option name 'upstairs_bedroom' - option path 'rtsp://admin:password@192.168.70.173:554/cam/realmonitor?channel=1&subtype=0&authbasic=64' - option roles 'detect' - option record '1' - option snapshots '1' - option mask '0,461,3,0,1919,0,1919,843,1699,492,1344,458,1346,336,973,317,869,375,866,432' - -config camera_config - option name 'kitchen' - option path 'rtsp://admin:password@192.168.70.173:554/cam/realmonitor?channel=1&subtype=0&authbasic=64' - option roles 'detect' - option record '1' - option snapshots '1' - option mask '0,461,3,0,1919,0,1919,843,1699,492,1344,458,1346,336,973,317,869,375,866,432' + option mask '' + option overwrite_cfg '1' diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 57e0b72..5734c27 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -103,6 +103,7 @@ EOF # 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 '. head_comment="WARNING: Any values marked as OVERWRITTEN_BY_ROUTER are managed by Private Router. Manual changes will overwritten unless you uncheck "Overwrite Frigate Config" in the frigate app camera settings."' -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 @@ -216,8 +217,9 @@ write_camera_to_yml() { # Add path and roles to the inputs in YML yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"$path\"" -i /opt/docker2/compose/frigate/config.yml + overwrite_warning_comment $name "ffmpeg.inputs[0].path" yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml - + overwrite_warning_comment $name "ffmpeg.inputs[0].roles" # Add other camera settings to YML 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 @@ -225,18 +227,21 @@ write_camera_to_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 - + overwrite_warning_comment $name "record.enabled" 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 - + overwrite_warning_comment $name "snapshots.enabled" # 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 + overwrite_warning_comment $name "motion.mask" else echo "Mask is empty, ignoring." fi + yq eval ".cameras.$name.origin = \"privaterouter\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name.origin line_comment=\"DO NOT EDIT THIS LINE\"" -i /opt/docker2/compose/frigate/config.yml } get_camera_index_by_name() { @@ -251,19 +256,27 @@ get_camera_index_by_name() { } # Toggles the line comment for a specific camera attribute in the YML -toggle_override() { +overwrite_warning_comment() { local name=$1 local attribute=$2 - local current_comment=$(yq eval ".cameras.$name.$attribute | line_comment" /opt/docker2/compose/frigate/config.yml) - - if [ "$current_comment" = "OVERWRITTEN_BY_UCI" ]; then - # If the current comment is "OVERWRITTEN_BY_UCI", remove it by setting it to nothing - yq eval ".cameras.$name.$attribute line_comment=\"\"" -i /opt/docker2/compose/frigate/config.yml - else - # Otherwise, set the comment to "OVERWRITTEN_BY_UCI" - yq eval ".cameras.$name.$attribute line_comment=\"OVERWRITTEN_BY_UCI\"" -i /opt/docker2/compose/frigate/config.yml - fi + yq eval ".cameras.$name.$attribute line_comment=\"OVERWRITTEN_BY_ROUTER\"" -i /opt/docker2/compose/frigate/config.yml } +remove_warning_comments() { + local name=$1 + # Attribute list to remove warning comments + local attributes=( + "ffmpeg.inputs[0].path" + "ffmpeg.inputs[0].roles" + "record.enabled" + "snapshots.enabled" + "motion.mask" + ) + + for attribute in "${attributes[@]}"; do + yq '.cameras.'$name'.'$attribute' line_comment=""' -i /opt/docker2/compose/frigate/config.yml + done +} + update_camera_in_yml() { local name=$1 @@ -272,21 +285,28 @@ update_camera_in_yml() { local camera_index=$(get_camera_index_by_name $name) # Fetch and Update the specific settings for this camera from UCI -> YAML + + # For each attribute you update, apply warning comment local path=$(get_uci_camera_value $camera_index "path") set_yml_value $name ".ffmpeg.inputs[0].path" "\"$path\"" + overwrite_warning_comment $name "ffmpeg.inputs[0].path" local roles=$(get_uci_camera_value $camera_index "roles") set_yml_value $name ".ffmpeg.inputs[0].roles" $roles + overwrite_warning_comment $name "ffmpeg.inputs[0].roles" local record=$(get_uci_camera_value $camera_index "record") set_yml_value $name ".record.enabled" $record + overwrite_warning_comment $name "record.enabled" local snapshots=$(get_uci_camera_value $camera_index "snapshots") set_yml_value $name ".snapshots.enabled" $snapshots + overwrite_warning_comment $name "snapshots.enabled" local mask=$(get_uci_camera_value $camera_index "mask") if [ -n "$mask" ]; then set_yml_value $name ".motion.mask" "[\"$mask\"]" + overwrite_warning_comment $name "motion.mask" else yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml fi @@ -307,16 +327,24 @@ sync_camera_config() { while true; do # Try to fetch camera configuration local camera_name=$(get_uci_camera_value $camera_index) + local overwrite_cfg=$(get_uci_camera_value $camera_index "overwrite_cfg") # Exit loop if no more cameras are found [ -z "$camera_name" ] && break - if ! echo "$yml_cameras" | grep -q -w "$camera_name"; then - echo "UCI Camera $camera_name not found in YML, adding..." - write_camera_to_yml $camera_name + # Only proceed if overwrite_cfg is enabled (set to 1) + if [ "$overwrite_cfg" -eq 1 ] + then + if ! echo "$yml_cameras" | grep -q -w "$camera_name"; then + echo "UCI Camera $camera_name not found in YML, adding..." + write_camera_to_yml $camera_name + else + echo "UCI Camera $camera_name found in YML, updating..." + update_camera_in_yml $camera_name + fi else - echo "UCI Camera $camera_name found in YML, updating..." - update_camera_in_yml $camera_name + echo "Skipping camera $camera_name, overwrite is set to false." + remove_warning_comment $camera_name fi # Add to uci_cameras @@ -326,18 +354,26 @@ sync_camera_config() { camera_index=$((camera_index+1)) done - # Crosscheck and remove any old cameras in YML not present in UCI config + # Crosschecking and removing orphaned entry in YML not present in UCI config for yml_camera in $yml_cameras; do + # Get the origin of this camera + local origin=$(get_yml_value $yml_camera ".origin") + # Fix for word splitting set -f if ! echo $uci_cameras | grep -q -w "$yml_camera"; then - echo "Camera $yml_camera found in YML, but not in UCI, removing..." - yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml + # If the origin is either non-existent or not equal to "privaterouter", keep it + if [ -z "$origin" ] || [ "$origin" != "privaterouter" ]; then + echo "Manual camera $yml_camera found in YML. Keeping it since it's manually added." + else + echo "Auto generated camera $yml_camera found in YML, but not in UCI , removing..." + yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml + fi fi set +f done - echo "sync_camera_config completed!" + echo "Camera config syncing completed!" } case "${ACTION}" in -- 2.38.4 From c74c1b73028ef4ac7af70fdc5707e4b237a35b31 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 18:46:56 -0400 Subject: [PATCH 17/24] CBI code bug fix --- luasrc/model/cbi/frigate.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 59d1f66..9368527 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -34,6 +34,7 @@ o.default = "/dev/crypto" o = s:option(Value, "storage", "Storage Path") o.default = "./frigate/storage" + -- MQTT Configuration s = m:section(NamedSection, "mqtt", "frigate_config", "MQTT Configuration") s.addremove = false @@ -84,7 +85,4 @@ o = s:option(Flag, "overwrite_cfg", "Overwrite Frigate Config") o.default = "1" o.rmempty = false -return m - - return m \ No newline at end of file -- 2.38.4 From 224ca2fd3ebe83538429f3843c5ea4c054af8d30 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 18:47:25 -0400 Subject: [PATCH 18/24] Comment remove function refactor due to lack of bash --- root/usr/libexec/apps/frigate/frigate.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 5734c27..8fe1634 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -263,18 +263,16 @@ overwrite_warning_comment() { } remove_warning_comments() { local name=$1 - # Attribute list to remove warning comments - local attributes=( - "ffmpeg.inputs[0].path" - "ffmpeg.inputs[0].roles" - "record.enabled" - "snapshots.enabled" - "motion.mask" - ) - - for attribute in "${attributes[@]}"; do - yq '.cameras.'$name'.'$attribute' line_comment=""' -i /opt/docker2/compose/frigate/config.yml - done + + yq '.cameras.'$name'.ffmpeg.inputs[0].path line_comment=""' -i /opt/docker2/compose/frigate/config.yml + + yq '.cameras.'$name'.ffmpeg.inputs[0].roles line_comment=""' -i /opt/docker2/compose/frigate/config.yml + + yq '.cameras.'$name'.record.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml + + yq '.cameras.'$name'.snapshots.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml + + yq '.cameras.'$name'.motion.mask line_comment=""' -i /opt/docker2/compose/frigate/config.yml } @@ -344,7 +342,7 @@ sync_camera_config() { fi else echo "Skipping camera $camera_name, overwrite is set to false." - remove_warning_comment $camera_name + remove_warning_comments $camera_name fi # Add to uci_cameras -- 2.38.4 From 959b23764fd871080f1edb9b7985d15f4e822e26 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 19:19:53 -0400 Subject: [PATCH 19/24] Cleaned up manual camera entry detection --- root/usr/libexec/apps/frigate/frigate.sh | 30 ++++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 8fe1634..a609a15 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -4,7 +4,7 @@ APP_NAME="frigate" ACTION="${1}" shift 1 -#set -x +set -x fetch_and_validate_uci () { local config_name=$1 @@ -103,7 +103,8 @@ EOF # 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 '. head_comment="WARNING: Any values marked as OVERWRITTEN_BY_ROUTER are managed by Private Router. Manual changes will overwritten unless you uncheck "Overwrite Frigate Config" in the frigate app camera settings."' -i /opt/docker2/compose/frigate/config.yml + yq eval '. head_comment="WARNING: Any values marked as OVERWRITTEN_BY_ROUTER are managed by Private Router. Manual changes will overwritten unless you uncheck \"Overwrite Frigate Config\" in the frigate app camera settings."' -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 @@ -240,8 +241,7 @@ write_camera_to_yml() { else echo "Mask is empty, ignoring." fi - yq eval ".cameras.$name.origin = \"privaterouter\"" -i /opt/docker2/compose/frigate/config.yml - yq eval ".cameras.$name.origin line_comment=\"DO NOT EDIT THIS LINE\"" -i /opt/docker2/compose/frigate/config.yml + yq eval ".cameras.$name line_comment=\"DO NOT REMOVE - Managed by PrivateRouter Script\"" -i /opt/docker2/compose/frigate/config.yml } get_camera_index_by_name() { @@ -354,19 +354,23 @@ sync_camera_config() { # Crosschecking and removing orphaned entry in YML not present in UCI config for yml_camera in $yml_cameras; do - # Get the origin of this camera - local origin=$(get_yml_value $yml_camera ".origin") + # Get the comment of this camera + local comment=$(yq eval ".cameras.$yml_camera line_comment" /opt/docker2/compose/frigate/config.yml) # Fix for word splitting set -f if ! echo $uci_cameras | grep -q -w "$yml_camera"; then - # If the origin is either non-existent or not equal to "privaterouter", keep it - if [ -z "$origin" ] || [ "$origin" != "privaterouter" ]; then - echo "Manual camera $yml_camera found in YML. Keeping it since it's manually added." - else - echo "Auto generated camera $yml_camera found in YML, but not in UCI , removing..." - yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml - fi + # Trim leading and trailing whitespaces and converting to all lowercase. + comment=${comment,,} + comment=${comment//[[:blank:]]/} + + # If the comment is either non-existent or doesn't contain "donotremove-managedbyprivaterouterscript", keep it + if [ -z "$comment" ] || [[ "$comment" != *"donotremove-managedbyprivaterouterscript"* ]]; then + echo "Manual camera $yml_camera found in YML. Keeping it since it's manually added." + else + echo "Auto generated camera $yml_camera found in YML, but not in UCI , removing..." + yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml + fi fi set +f done -- 2.38.4 From f899aa390356d37c6bfa609bb38673fbe684e454 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 27 Sep 2023 21:32:59 -0400 Subject: [PATCH 20/24] Comment handling cleanup --- root/usr/libexec/apps/frigate/frigate.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index a609a15..a339a3e 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -241,7 +241,7 @@ write_camera_to_yml() { else echo "Mask is empty, ignoring." fi - yq eval ".cameras.$name line_comment=\"DO NOT REMOVE - Managed by PrivateRouter Script\"" -i /opt/docker2/compose/frigate/config.yml + yq eval '(.cameras.Office | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml } get_camera_index_by_name() { @@ -259,20 +259,26 @@ get_camera_index_by_name() { overwrite_warning_comment() { local name=$1 local attribute=$2 - yq eval ".cameras.$name.$attribute line_comment=\"OVERWRITTEN_BY_ROUTER\"" -i /opt/docker2/compose/frigate/config.yml + + # Handle the special case of the list item + if [[ $attribute == "ffmpeg.inputs[0].roles" ]]; then + yq eval '(.cameras.'$name'.ffmpeg.inputs[0] | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml + else + yq eval '(.cameras.'$name'.'$attribute' | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml + fi } remove_warning_comments() { local name=$1 - yq '.cameras.'$name'.ffmpeg.inputs[0].path line_comment=""' -i /opt/docker2/compose/frigate/config.yml + yq eval '.cameras.'$name'.ffmpeg.inputs[0].path line_comment=""' -i /opt/docker2/compose/frigate/config.yml - yq '.cameras.'$name'.ffmpeg.inputs[0].roles line_comment=""' -i /opt/docker2/compose/frigate/config.yml + yq eval '.cameras.'$name'.ffmpeg.inputs[0].roles line_comment=""' -i /opt/docker2/compose/frigate/config.yml - yq '.cameras.'$name'.record.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml + yq eval '.cameras.'$name'.record.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml - yq '.cameras.'$name'.snapshots.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml + yq eval '.cameras.'$name'.snapshots.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml - yq '.cameras.'$name'.motion.mask line_comment=""' -i /opt/docker2/compose/frigate/config.yml + yq eval '.cameras.'$name'.motion.mask line_comment=""' -i /opt/docker2/compose/frigate/config.yml } @@ -308,6 +314,7 @@ update_camera_in_yml() { else yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml fi + yq eval '(.cameras.Office | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml } sync_camera_config() { @@ -355,7 +362,7 @@ sync_camera_config() { # Crosschecking and removing orphaned entry in YML not present in UCI config for yml_camera in $yml_cameras; do # Get the comment of this camera - local comment=$(yq eval ".cameras.$yml_camera line_comment" /opt/docker2/compose/frigate/config.yml) + local comment=$(yq ".cameras.$yml_camera | key | line_comment" /opt/docker2/compose/frigate/config.yml) # Fix for word splitting set -f -- 2.38.4 From 8eb3ddbea8e5b3953e9f39347b2c81aa6a89cf7a Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 28 Sep 2023 18:42:47 -0400 Subject: [PATCH 21/24] WIP Still trying to clean up yml comment sync --- root/usr/libexec/apps/frigate/frigate.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index a339a3e..68e7fb3 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -4,7 +4,7 @@ APP_NAME="frigate" ACTION="${1}" shift 1 -set -x +#set -x fetch_and_validate_uci () { local config_name=$1 @@ -281,7 +281,6 @@ remove_warning_comments() { yq eval '.cameras.'$name'.motion.mask line_comment=""' -i /opt/docker2/compose/frigate/config.yml } - update_camera_in_yml() { local name=$1 @@ -324,10 +323,10 @@ sync_camera_config() { camera_index=0 # Fetching all cameras from frigate YML - yml_cameras=$(yq eval '.cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs) + yml_cameras=$(yq eval '... comments="" | .cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs) echo "Cameras fetched from YML: $yml_cameras" - + # Loop through all camera configs in UCI using index while true; do # Try to fetch camera configuration -- 2.38.4 From 71ba2606a71153e52d6de078561fbc20a15eb976 Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 28 Sep 2023 20:24:20 -0400 Subject: [PATCH 22/24] Removed YML helper functions, they are more trouble then they are worth --- root/usr/libexec/apps/frigate/frigate.sh | 42 +++++------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 68e7fb3..7a2bda3 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -156,32 +156,6 @@ set_uci_camera_value() { uci commit frigate } -# YML Helper Functions - -# Retrieves a specific setting from the YML. If no setting_path is provided, it retrieves the camera name. -get_yml_value() { - local name=$1 - local setting_path=${2:-} - yq eval ".cameras.$name$setting_path" /opt/docker2/compose/frigate/config.yml -} - -# Sets a specific setting in the YML -set_yml_value() { - local name=$1 - local setting_path=$2 - local value=$3 - # If the value starts with "{", "[", or is a number, we don't quote it; otherwise, we do. - case "$value" in - "{"*|"["*|*[0-9]*) - # do nothing - ;; - *) - value="\"$value\"" - ;; - esac - yq eval ".cameras.$name$setting_path = $value" -i /opt/docker2/compose/frigate/config.yml -} - write_camera_to_yml() { local name=$1 local camera_index="" @@ -291,29 +265,29 @@ update_camera_in_yml() { # For each attribute you update, apply warning comment local path=$(get_uci_camera_value $camera_index "path") - set_yml_value $name ".ffmpeg.inputs[0].path" "\"$path\"" + yq eval '.cameras.'$name'.ffmpeg.inputs[0].path = "'$path'"' -i /opt/docker2/compose/frigate/config.yml overwrite_warning_comment $name "ffmpeg.inputs[0].path" - local roles=$(get_uci_camera_value $camera_index "roles") - set_yml_value $name ".ffmpeg.inputs[0].roles" $roles + local roles="[\"detect\"]" # adjust as necessary + yq eval '.cameras.'$name'.ffmpeg.inputs[0].roles = '$roles'' -i /opt/docker2/compose/frigate/config.yml overwrite_warning_comment $name "ffmpeg.inputs[0].roles" local record=$(get_uci_camera_value $camera_index "record") - set_yml_value $name ".record.enabled" $record + yq eval '.cameras.'$name'.record.enabled = '$record'' -i /opt/docker2/compose/frigate/config.yml overwrite_warning_comment $name "record.enabled" local snapshots=$(get_uci_camera_value $camera_index "snapshots") - set_yml_value $name ".snapshots.enabled" $snapshots + yq eval '.cameras.'$name'.snapshots.enabled = '$snapshots'' -i /opt/docker2/compose/frigate/config.yml overwrite_warning_comment $name "snapshots.enabled" local mask=$(get_uci_camera_value $camera_index "mask") if [ -n "$mask" ]; then - set_yml_value $name ".motion.mask" "[\"$mask\"]" + yq eval '.cameras.'$name'.motion.mask = ["'$mask'"]' -i /opt/docker2/compose/frigate/config.yml overwrite_warning_comment $name "motion.mask" else yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml fi - yq eval '(.cameras.Office | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml + yq eval '(.cameras.'$name' | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml } sync_camera_config() { @@ -326,7 +300,7 @@ sync_camera_config() { yml_cameras=$(yq eval '... comments="" | .cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs) echo "Cameras fetched from YML: $yml_cameras" - + # Loop through all camera configs in UCI using index while true; do # Try to fetch camera configuration -- 2.38.4 From a3b24423873f53afea63fa291d9aa48f0888b904 Mon Sep 17 00:00:00 2001 From: riley Date: Fri, 29 Sep 2023 18:02:56 -0400 Subject: [PATCH 23/24] Removed mask UCI config, comment handling cleanup --- luasrc/model/cbi/frigate.lua | 2 - root/etc/config/frigate | 1 - root/usr/libexec/apps/frigate/frigate.sh | 67 +++++++----------------- 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/luasrc/model/cbi/frigate.lua b/luasrc/model/cbi/frigate.lua index 9368527..7039e65 100644 --- a/luasrc/model/cbi/frigate.lua +++ b/luasrc/model/cbi/frigate.lua @@ -78,8 +78,6 @@ o = s:option(Flag, "snapshots", "Enable Snapshots") o.default = "0" o.rmempty = false -o = s:option(Value, "mask", "Mask") - -- Add the new flag for Overwrite Frigate Config o = s:option(Flag, "overwrite_cfg", "Overwrite Frigate Config") o.default = "1" diff --git a/root/etc/config/frigate b/root/etc/config/frigate index 48cf692..5d56463 100644 --- a/root/etc/config/frigate +++ b/root/etc/config/frigate @@ -20,6 +20,5 @@ config camera_config option roles 'detect' option record '1' option snapshots '1' - option mask '' option overwrite_cfg '1' diff --git a/root/usr/libexec/apps/frigate/frigate.sh b/root/usr/libexec/apps/frigate/frigate.sh index 7a2bda3..8a580bb 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -181,7 +181,6 @@ write_camera_to_yml() { 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 in YML yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml @@ -192,9 +191,7 @@ write_camera_to_yml() { # Add path and roles to the inputs in YML yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"$path\"" -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "ffmpeg.inputs[0].path" yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "ffmpeg.inputs[0].roles" # Add other camera settings to YML 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 @@ -202,20 +199,10 @@ write_camera_to_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 - overwrite_warning_comment $name "record.enabled" 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 - overwrite_warning_comment $name "snapshots.enabled" - # 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 - overwrite_warning_comment $name "motion.mask" - else - echo "Mask is empty, ignoring." - fi - yq eval '(.cameras.Office | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml + + add_warning_comments $name } get_camera_index_by_name() { @@ -230,29 +217,28 @@ get_camera_index_by_name() { } # Toggles the line comment for a specific camera attribute in the YML -overwrite_warning_comment() { +add_warning_comments() { local name=$1 - local attribute=$2 + yq eval '(.cameras.'$name' | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml - # Handle the special case of the list item - if [[ $attribute == "ffmpeg.inputs[0].roles" ]]; then - yq eval '(.cameras.'$name'.ffmpeg.inputs[0] | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml - else - yq eval '(.cameras.'$name'.'$attribute' | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml - fi + yq eval '(.cameras.'$name'.ffmpeg.inputs[0].path | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml + + yq eval '(.cameras.'$name'.ffmpeg.inputs[0].roles | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml + + yq eval '.cameras.'$name'.record.enabled line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml + + yq eval '.cameras.'$name'.snapshots.enabled line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml } remove_warning_comments() { local name=$1 yq eval '.cameras.'$name'.ffmpeg.inputs[0].path line_comment=""' -i /opt/docker2/compose/frigate/config.yml - yq eval '.cameras.'$name'.ffmpeg.inputs[0].roles line_comment=""' -i /opt/docker2/compose/frigate/config.yml + yq eval '(.cameras.'$name'.ffmpeg.inputs[0].roles | key) line_comment=""' -i /opt/docker2/compose/frigate/config.yml yq eval '.cameras.'$name'.record.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml yq eval '.cameras.'$name'.snapshots.enabled line_comment=""' -i /opt/docker2/compose/frigate/config.yml - - yq eval '.cameras.'$name'.motion.mask line_comment=""' -i /opt/docker2/compose/frigate/config.yml } update_camera_in_yml() { @@ -266,28 +252,20 @@ update_camera_in_yml() { # For each attribute you update, apply warning comment local path=$(get_uci_camera_value $camera_index "path") yq eval '.cameras.'$name'.ffmpeg.inputs[0].path = "'$path'"' -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "ffmpeg.inputs[0].path" + local roles="[\"detect\"]" # adjust as necessary yq eval '.cameras.'$name'.ffmpeg.inputs[0].roles = '$roles'' -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "ffmpeg.inputs[0].roles" + local record=$(get_uci_camera_value $camera_index "record") yq eval '.cameras.'$name'.record.enabled = '$record'' -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "record.enabled" + local snapshots=$(get_uci_camera_value $camera_index "snapshots") yq eval '.cameras.'$name'.snapshots.enabled = '$snapshots'' -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "snapshots.enabled" - - local mask=$(get_uci_camera_value $camera_index "mask") - if [ -n "$mask" ]; then - yq eval '.cameras.'$name'.motion.mask = ["'$mask'"]' -i /opt/docker2/compose/frigate/config.yml - overwrite_warning_comment $name "motion.mask" - else - yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml - fi - yq eval '(.cameras.'$name' | key) line_comment="DO NOT REMOVE - Managed by PrivateRouter Script"' -i /opt/docker2/compose/frigate/config.yml + + add_warning_comments $name } sync_camera_config() { @@ -336,14 +314,10 @@ sync_camera_config() { for yml_camera in $yml_cameras; do # Get the comment of this camera local comment=$(yq ".cameras.$yml_camera | key | line_comment" /opt/docker2/compose/frigate/config.yml) + comment=$(echo $comment | awk '{print tolower($0)}') # convert to lowercase using awk + comment=$(echo $comment | tr -d ' ') # remove whitespaces - # Fix for word splitting - set -f - if ! echo $uci_cameras | grep -q -w "$yml_camera"; then - # Trim leading and trailing whitespaces and converting to all lowercase. - comment=${comment,,} - comment=${comment//[[:blank:]]/} - + if ! echo "$uci_cameras" | grep -q -w "$yml_camera"; then # If the comment is either non-existent or doesn't contain "donotremove-managedbyprivaterouterscript", keep it if [ -z "$comment" ] || [[ "$comment" != *"donotremove-managedbyprivaterouterscript"* ]]; then echo "Manual camera $yml_camera found in YML. Keeping it since it's manually added." @@ -352,7 +326,6 @@ sync_camera_config() { yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml fi fi - set +f done echo "Camera config syncing completed!" -- 2.38.4 From 1cb33bc3ca6a48af4b6c669ebbc7d8edab877ca5 Mon Sep 17 00:00:00 2001 From: riley Date: Fri, 29 Sep 2023 18:15:01 -0400 Subject: [PATCH 24/24] Warning phrasing --- 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 8a580bb..64e18bd 100755 --- a/root/usr/libexec/apps/frigate/frigate.sh +++ b/root/usr/libexec/apps/frigate/frigate.sh @@ -103,7 +103,7 @@ EOF # 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 '. head_comment="WARNING: Any values marked as OVERWRITTEN_BY_ROUTER are managed by Private Router. Manual changes will overwritten unless you uncheck \"Overwrite Frigate Config\" in the frigate app camera settings."' -i /opt/docker2/compose/frigate/config.yml + yq eval '. head_comment="WARNING: Values labeled OVERWRITTEN_BY_ROUTER are auto-managed by Private Router. Uncheck \"Overwrite Frigate Config\" in camera settings to edit manually."' -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 -- 2.38.4