Major yml config building refactor

pull/2/head
riley 1 year ago
parent a6a960f81b
commit 9892b62ca2

@ -59,48 +59,6 @@ do_install_detail() {
[ -z "$port" ] && port=1880
[ -z "$IMAGE_NAME" ] && IMAGE_NAME="ghcr.io/blakeblackshear/frigate:stable"
# Initialize counter
local i=0
mkdir -p /opt/docker2/compose/frigate
touch /opt/docker2/compose/frigate/config.yml
yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".storage = \"$storage\"" -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
yq eval ".detectors.coral.device = \"$coral\"" -i /opt/docker2/compose/frigate/config.yml
# Write each camera's configuration to config.yml
local camera_index=0
while : ; do
# Try to fetch camera configuration
local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null)
# Exit loop if no more cameras are found
[[ -z "$name" ]] && break
# Retrieve the rest of the camera settings here...
local path=$(uci get frigate.@camera_config[$camera_index].path)
local roles=$(uci get frigate.@camera_config[$camera_index].roles)
local record=$(uci get frigate.@camera_config[$camera_index].record)
local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots)
local mask=$(uci get frigate.@camera_config[$camera_index].mask)
# Write to config.yml using yq
yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"$path\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.ffmpeg.inputs[0].roles[0] = \"detect\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.detect.width = 1280" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.detect.height = 720" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.record.enabled = $record" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.snapshots.enabled = $snapshots" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.motion.mask[0] = \"$mask\"" -i /opt/docker2/compose/frigate/config.yml
camera_index=$((camera_index+1))
done
rm -r /opt/docker2/compose/frigate 2>/dev/null
mkdir -p /opt/docker2/compose/frigate
@ -137,6 +95,49 @@ services:
FRIGATE_RTSP_PASSWORD: "password"
EOF
# Initialize the base structure
echo "{}" > /opt/docker2/compose/frigate/config.yml
# Set global configurations
yq eval ".usbcoral = \"$usbcoral\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".hwaccel = \"$hwaccel\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".storage = \"$storage\"" -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
yq eval ".detectors.coral.device = \"$coral\"" -i /opt/docker2/compose/frigate/config.yml
# Initialize cameras structure
yq eval ".cameras = {}" -i /opt/docker2/compose/frigate/config.yml
# Write each camera's configuration to config.yml
local camera_index=0
while : ; do
# Try to fetch camera configuration
local name=$(uci get frigate.@camera_config[$camera_index].name 2>/dev/null)
# Exit loop if no more cameras are found
[[ -z "$name" ]] && break
# Retrieve the rest of the camera settings here...
local path=$(uci get frigate.@camera_config[$camera_index].path)
local roles=$(uci get frigate.@camera_config[$camera_index].roles)
local record=$(uci get frigate.@camera_config[$camera_index].record)
local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots)
local mask=$(uci get frigate.@camera_config[$camera_index].mask)
# Initialize camera structure
yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml
# Write to config.yml using yq
yq eval ".cameras.$name.ffmpeg = { inputs: [{ path: \"$path\", roles: [\"detect\"] }] }" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.detect = { width: 1280, height: 720 }" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.record = { enabled: $record }" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.snapshots = { enabled: $snapshots }" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.motion = { mask: [\"$mask\"] }" -i /opt/docker2/compose/frigate/config.yml
camera_index=$((camera_index+1))
done
docker-compose -f /opt/docker2/compose/frigate/docker-compose.yml up -d
uci add shortcutmenu lists
@ -174,7 +175,7 @@ case "${ACTION}" in
;;
"start" | "stop" | "restart")
APP_NAME="frigate"
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.ID}}')
CONTAINER_IDS=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.ID}}')
for ID in $CONTAINER_IDS; do
docker "${ACTION}" "${ID}"
done
@ -189,13 +190,13 @@ case "${ACTION}" in
echo "${CONTAINER_STATUS}"
fi
;;
"port")
"port")
APP_NAME="frigate"
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.Names}}')
docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Ports}}' | grep -o -m1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://'
;;
*)
usage
exit 1
CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}')
# Fetch the port from UCI configuration
uci_port=$(uci get frigate.docker.port 2>/dev/null)
[ -z "$uci_port" ] && exit 1 # Exit silently if UCI port is not found
# 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//"
;;
esac
Loading…
Cancel
Save