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!"