|
|
@ -4,6 +4,7 @@ APP_NAME="frigate"
|
|
|
|
|
|
|
|
|
|
|
|
ACTION="${1}"
|
|
|
|
ACTION="${1}"
|
|
|
|
shift 1
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
|
|
|
|
fetch_and_validate_uci () {
|
|
|
|
fetch_and_validate_uci () {
|
|
|
|
local config_name=$1
|
|
|
|
local config_name=$1
|
|
|
@ -280,68 +281,92 @@ write_camera_to_yml() {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update_camera_in_yml() {
|
|
|
|
get_camera_index_by_name() {
|
|
|
|
local name=$1
|
|
|
|
local name=$1
|
|
|
|
# Deletes the camera from the YML file and writes it again
|
|
|
|
local camera_index=0
|
|
|
|
yq eval "del(.cameras.$name)" -i /opt/docker2/compose/frigate/config.yml
|
|
|
|
while : ; do
|
|
|
|
write_camera_to_yml $name
|
|
|
|
local current_name=$(get_uci_camera_value $camera_index)
|
|
|
|
|
|
|
|
[[ "$current_name" == "$name" ]] && echo $camera_index && break
|
|
|
|
|
|
|
|
[[ -z "$current_name" ]] && break
|
|
|
|
|
|
|
|
camera_index=$((camera_index+1))
|
|
|
|
|
|
|
|
done
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_camera_in_yml() {
|
|
|
|
|
|
|
|
local name=$1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the index of the camera with name "$name"
|
|
|
|
|
|
|
|
local camera_index=$(get_camera_index_by_name $name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fetch and Update the specific settings for this camera from UCI -> YAML
|
|
|
|
|
|
|
|
local path=$(get_uci_camera_value $camera_index "path")
|
|
|
|
|
|
|
|
set_yml_value $name ".ffmpeg.inputs[0].path" $path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local roles=$(get_uci_camera_value $camera_index "roles")
|
|
|
|
|
|
|
|
set_yml_value $name ".ffmpeg.inputs[0].roles" $roles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local record=$(get_uci_camera_value $camera_index "record")
|
|
|
|
|
|
|
|
set_yml_value $name ".record.enabled" $record
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local snapshots=$(get_uci_camera_value $camera_index "snapshots")
|
|
|
|
|
|
|
|
set_yml_value $name ".snapshots.enabled" $snapshots
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local mask=$(get_uci_camera_value $camera_index "mask")
|
|
|
|
|
|
|
|
if [ -n "$mask" ]; then
|
|
|
|
|
|
|
|
set_yml_value $name ".motion.mask" $mask
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Mask is empty, ignoring."
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sync_camera_config() {
|
|
|
|
sync_camera_config() {
|
|
|
|
echo "Starting sync_camera_config..."
|
|
|
|
echo "Starting sync_camera_config..."
|
|
|
|
|
|
|
|
|
|
|
|
# Fetching all cameras from UCI
|
|
|
|
# Initializing the camera index
|
|
|
|
local uci_cameras=""
|
|
|
|
camera_index=0
|
|
|
|
local camera_index=0
|
|
|
|
|
|
|
|
while : ; do
|
|
|
|
|
|
|
|
local name=$(get_uci_camera_value $camera_index)
|
|
|
|
|
|
|
|
# Exit loop if no more cameras are found
|
|
|
|
|
|
|
|
[[ -z "$name" ]] && break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uci_cameras="$uci_cameras $name"
|
|
|
|
# Fetching all cameras from frigate YML
|
|
|
|
camera_index=$((camera_index+1))
|
|
|
|
yml_cameras=$(yq eval '.cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs)
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Cameras fetched from UCI: $uci_cameras"
|
|
|
|
echo "Cameras fetched from YML: $yml_cameras"
|
|
|
|
|
|
|
|
|
|
|
|
# Fetching all cameras from Frigate YML
|
|
|
|
# Loop through all camera configs in UCI using index
|
|
|
|
local yml_cameras=$(yq eval '.cameras | keys' /opt/docker2/compose/frigate/config.yml | sed 's/- //g' | xargs)
|
|
|
|
while true; do
|
|
|
|
|
|
|
|
# Try to fetch camera configuration
|
|
|
|
|
|
|
|
local camera_name=$(get_uci_camera_value $camera_index)
|
|
|
|
|
|
|
|
|
|
|
|
echo "Cameras fetched from YML: $yml_cameras"
|
|
|
|
# Exit loop if no more cameras are found
|
|
|
|
|
|
|
|
[ -z "$camera_name" ] && break
|
|
|
|
|
|
|
|
|
|
|
|
# Checking for cameras in UCI that are not in YML and adding them
|
|
|
|
if ! echo "$yml_cameras" | grep -q -w "$camera_name"; then
|
|
|
|
for camera_name in $uci_cameras; do
|
|
|
|
|
|
|
|
if ! echo "$yml_cameras" | grep -q "$camera_name"; then
|
|
|
|
|
|
|
|
echo "Camera $camera_name not found in YML, adding..."
|
|
|
|
echo "Camera $camera_name not found in YML, adding..."
|
|
|
|
# Retrieves camera settings from UCI configuration and adds them to the YML file.
|
|
|
|
|
|
|
|
write_camera_to_yml $camera_name
|
|
|
|
write_camera_to_yml $camera_name
|
|
|
|
else
|
|
|
|
else
|
|
|
|
echo "Camera $camera_name found in YML, updating..."
|
|
|
|
echo "Camera $camera_name found in YML, updating..."
|
|
|
|
# Retrieves camera settings from UCI configuration and updates them in the YML file.
|
|
|
|
|
|
|
|
update_camera_in_yml $camera_name
|
|
|
|
update_camera_in_yml $camera_name
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Add to uci_cameras
|
|
|
|
|
|
|
|
uci_cameras="${uci_cameras} ${camera_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Increment camera index
|
|
|
|
|
|
|
|
camera_index=$((camera_index+1))
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Checking for cameras in YML that are not in UCI and deleting them
|
|
|
|
# Crosscheck and remove any old cameras in YML not present in UCI config
|
|
|
|
if [[ $yml_cameras != '[]' ]]; then # Add this condition
|
|
|
|
for yml_camera in $yml_cameras; do
|
|
|
|
for camera_name in $yml_cameras; do
|
|
|
|
# Fix for word splitting
|
|
|
|
if ! echo "$uci_cameras" | grep -q "$camera_name"; then
|
|
|
|
set -f
|
|
|
|
echo "Camera $camera_name not found in UCI, removing from YML..."
|
|
|
|
if ! echo $uci_cameras | grep -q -w "$yml_camera"; then
|
|
|
|
yq eval "del(.cameras.$camera_name)" -i /opt/docker2/compose/frigate/config.yml
|
|
|
|
echo "Camera $yml_camera found in YML, but not in UCI, removing..."
|
|
|
|
|
|
|
|
yq eval "del(.cameras.$yml_camera)" -i /opt/docker2/compose/frigate/config.yml
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
set +f
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi # Close the condition
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "sync_camera_config completed!"
|
|
|
|
echo "sync_camera_config completed!"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "${ACTION}" in
|
|
|
|
case "${ACTION}" in
|
|
|
|
"install" | "upgrade")
|
|
|
|
"install" | "upgrade")
|
|
|
|
do_install_detail
|
|
|
|
do_install_detail
|
|
|
@ -362,6 +387,7 @@ case "${ACTION}" in
|
|
|
|
CONTAINER_IDS=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.ID}}')
|
|
|
|
CONTAINER_IDS=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.ID}}')
|
|
|
|
for ID in $CONTAINER_IDS; do
|
|
|
|
for ID in $CONTAINER_IDS; do
|
|
|
|
docker "${ACTION}" "${ID}"
|
|
|
|
docker "${ACTION}" "${ID}"
|
|
|
|
|
|
|
|
sync_camera_config
|
|
|
|
done
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
"status")
|
|
|
|
"status")
|
|
|
@ -381,7 +407,4 @@ case "${ACTION}" in
|
|
|
|
# Use the UCI port to filter the docker ps output and return only the external port
|
|
|
|
# Use the UCI port to filter the docker ps output and return only the external port
|
|
|
|
docker ps --all -f "name=${CONTAINER_NAME}" --format '{{.Ports}}' | grep -o "0.0.0.0:$uci_port->[0-9]*/tcp" | sed "s/0.0.0.0://;s/->[0-9]*\/tcp//"
|
|
|
|
docker ps --all -f "name=${CONTAINER_NAME}" --format '{{.Ports}}' | grep -o "0.0.0.0:$uci_port->[0-9]*/tcp" | sed "s/0.0.0.0://;s/->[0-9]*\/tcp//"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
"sync")
|
|
|
|
|
|
|
|
sync_camera_config
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
esac
|