Removed YML helper functions, they are more trouble then they are worth

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

@ -156,32 +156,6 @@ set_uci_camera_value() {
uci commit frigate 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() { write_camera_to_yml() {
local name=$1 local name=$1
local camera_index="" local camera_index=""
@ -291,29 +265,29 @@ 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")
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" overwrite_warning_comment $name "ffmpeg.inputs[0].path"
local roles=$(get_uci_camera_value $camera_index "roles") local roles="[\"detect\"]" # adjust as necessary
set_yml_value $name ".ffmpeg.inputs[0].roles" $roles yq eval '.cameras.'$name'.ffmpeg.inputs[0].roles = '$roles'' -i /opt/docker2/compose/frigate/config.yml
overwrite_warning_comment $name "ffmpeg.inputs[0].roles" 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")
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" overwrite_warning_comment $name "record.enabled"
local snapshots=$(get_uci_camera_value $camera_index "snapshots") 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" overwrite_warning_comment $name "snapshots.enabled"
local mask=$(get_uci_camera_value $camera_index "mask") local mask=$(get_uci_camera_value $camera_index "mask")
if [ -n "$mask" ]; then 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" overwrite_warning_comment $name "motion.mask"
else else
yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml yq eval "del(.cameras.$name.motion)" -i /opt/docker2/compose/frigate/config.yml
fi 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() { 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) yml_cameras=$(yq eval '... comments="" | .cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs)
echo "Cameras fetched from YML: $yml_cameras" echo "Cameras fetched from YML: $yml_cameras"
# Loop through all camera configs in UCI using index # Loop through all camera configs in UCI using index
while true; do while true; do
# Try to fetch camera configuration # Try to fetch camera configuration

Loading…
Cancel
Save