Removed mask UCI config, comment handling cleanup

pull/3/head
riley 12 months ago
parent 71ba2606a7
commit a3b2442387

@ -78,8 +78,6 @@ o = s:option(Flag, "snapshots", "Enable Snapshots")
o.default = "0" o.default = "0"
o.rmempty = false o.rmempty = false
o = s:option(Value, "mask", "Mask")
-- Add the new flag for Overwrite Frigate Config -- Add the new flag for Overwrite Frigate Config
o = s:option(Flag, "overwrite_cfg", "Overwrite Frigate Config") o = s:option(Flag, "overwrite_cfg", "Overwrite Frigate Config")
o.default = "1" o.default = "1"

@ -20,6 +20,5 @@ config camera_config
option roles 'detect' option roles 'detect'
option record '1' option record '1'
option snapshots '1' option snapshots '1'
option mask ''
option overwrite_cfg '1' option overwrite_cfg '1'

@ -181,7 +181,6 @@ write_camera_to_yml() {
local roles=$(uci get frigate.@camera_config[$camera_index].roles 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 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 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 # Initialize camera structure in YML
yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.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 # 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].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 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 # Add other camera settings to YML
yq eval ".cameras.$name.detect = {}" -i /opt/docker2/compose/frigate/config.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.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 = {}" -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.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 = {}" -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.snapshots.enabled = $snapshots" -i /opt/docker2/compose/frigate/config.yml
overwrite_warning_comment $name "snapshots.enabled"
# Check if the mask is not empty add_warning_comments $name
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
} }
get_camera_index_by_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 # Toggles the line comment for a specific camera attribute in the YML
overwrite_warning_comment() { add_warning_comments() {
local name=$1 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 yq eval '(.cameras.'$name'.ffmpeg.inputs[0].path | key) line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml
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 yq eval '(.cameras.'$name'.ffmpeg.inputs[0].roles | 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 yq eval '.cameras.'$name'.record.enabled line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml
fi
yq eval '.cameras.'$name'.snapshots.enabled line_comment="OVERWRITTEN_BY_ROUTER"' -i /opt/docker2/compose/frigate/config.yml
} }
remove_warning_comments() { remove_warning_comments() {
local name=$1 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].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'.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'.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() { update_camera_in_yml() {
@ -266,28 +252,20 @@ update_camera_in_yml() {
# For each attribute you update, apply warning comment # For each attribute you update, apply warning comment
local path=$(get_uci_camera_value $camera_index "path") 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 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 local roles="[\"detect\"]" # adjust as necessary
yq eval '.cameras.'$name'.ffmpeg.inputs[0].roles = '$roles'' -i /opt/docker2/compose/frigate/config.yml 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") local record=$(get_uci_camera_value $camera_index "record")
yq eval '.cameras.'$name'.record.enabled = '$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"
local snapshots=$(get_uci_camera_value $camera_index "snapshots") local snapshots=$(get_uci_camera_value $camera_index "snapshots")
yq eval '.cameras.'$name'.snapshots.enabled = '$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"
add_warning_comments $name
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
} }
sync_camera_config() { sync_camera_config() {
@ -336,14 +314,10 @@ sync_camera_config() {
for yml_camera in $yml_cameras; do for yml_camera in $yml_cameras; do
# Get the comment of this camera # Get the comment of this camera
local comment=$(yq ".cameras.$yml_camera | key | line_comment" /opt/docker2/compose/frigate/config.yml) 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 if ! echo "$uci_cameras" | grep -q -w "$yml_camera"; then
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 the comment is either non-existent or doesn't contain "donotremove-managedbyprivaterouterscript", keep it # If the comment is either non-existent or doesn't contain "donotremove-managedbyprivaterouterscript", keep it
if [ -z "$comment" ] || [[ "$comment" != *"donotremove-managedbyprivaterouterscript"* ]]; then if [ -z "$comment" ] || [[ "$comment" != *"donotremove-managedbyprivaterouterscript"* ]]; then
echo "Manual camera $yml_camera found in YML. Keeping it since it's manually added." 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 yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml
fi fi
fi fi
set +f
done done
echo "Camera config syncing completed!" echo "Camera config syncing completed!"

Loading…
Cancel
Save