From 71ba2606a71153e52d6de078561fbc20a15eb976 Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 28 Sep 2023 20:24:20 -0400 Subject: [PATCH] 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