From e07da23f195e6e1bf86ee62a09acd353c3d73c44 Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 26 Sep 2023 20:46:38 -0400 Subject: [PATCH] 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")