Cleaned up manual camera entry detection

pull/3/head
riley 12 months ago
parent 224ca2fd3e
commit 959b23764f

@ -4,7 +4,7 @@ APP_NAME="frigate"
ACTION="${1}"
shift 1
#set -x
set -x
fetch_and_validate_uci () {
local config_name=$1
@ -103,7 +103,8 @@ EOF
# yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml
# yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml
# yq eval ".media.storage = \"$storage\"" -i /opt/docker2/compose/frigate/config.yml
yq eval '. head_comment="WARNING: Any values marked as OVERWRITTEN_BY_ROUTER are managed by Private Router. Manual changes will overwritten unless you uncheck "Overwrite Frigate Config" in the frigate app camera settings."' -i /opt/docker2/compose/frigate/config.yml
yq eval '. head_comment="WARNING: Any values marked as OVERWRITTEN_BY_ROUTER are managed by Private Router. Manual changes will overwritten unless you uncheck \"Overwrite Frigate Config\" in the frigate app camera settings."' -i /opt/docker2/compose/frigate/config.yml
yq eval ".mqtt.enabled = $mqtt" -i /opt/docker2/compose/frigate/config.yml
yq eval ".mqtt.host = \"$host\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".detectors.coral.type = \"$type\"" -i /opt/docker2/compose/frigate/config.yml
@ -240,8 +241,7 @@ write_camera_to_yml() {
else
echo "Mask is empty, ignoring."
fi
yq eval ".cameras.$name.origin = \"privaterouter\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.origin line_comment=\"DO NOT EDIT THIS LINE\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name line_comment=\"DO NOT REMOVE - Managed by PrivateRouter Script\"" -i /opt/docker2/compose/frigate/config.yml
}
get_camera_index_by_name() {
@ -354,14 +354,18 @@ sync_camera_config() {
# Crosschecking and removing orphaned entry in YML not present in UCI config
for yml_camera in $yml_cameras; do
# Get the origin of this camera
local origin=$(get_yml_value $yml_camera ".origin")
# Get the comment of this camera
local comment=$(yq eval ".cameras.$yml_camera line_comment" /opt/docker2/compose/frigate/config.yml)
# Fix for word splitting
set -f
if ! echo $uci_cameras | grep -q -w "$yml_camera"; then
# If the origin is either non-existent or not equal to "privaterouter", keep it
if [ -z "$origin" ] || [ "$origin" != "privaterouter" ]; 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 [ -z "$comment" ] || [[ "$comment" != *"donotremove-managedbyprivaterouterscript"* ]]; then
echo "Manual camera $yml_camera found in YML. Keeping it since it's manually added."
else
echo "Auto generated camera $yml_camera found in YML, but not in UCI , removing..."

Loading…
Cancel
Save