Merge pull request 'Remove unnecessary stuff, clean up code, fix yaml parsing bugs' (#2) from jason/luci-app-frigate:main into main

Reviewed-on: riley/luci-app-frigate#2
pull/2/head
jason 1 year ago
commit 1fc58b96c3

@ -119,11 +119,11 @@ EOF
[[ -z "$name" ]] && break [[ -z "$name" ]] && break
# Retrieve the rest of the camera settings here... # Retrieve the rest of the camera settings here...
local path=$(uci get frigate.@camera_config[$camera_index].path) local path=$(uci get frigate.@camera_config[$camera_index].path 2>/dev/null)
local roles=$(uci get frigate.@camera_config[$camera_index].roles) local roles=$(uci get frigate.@camera_config[$camera_index].roles 2>/dev/null)
local record=$(uci get frigate.@camera_config[$camera_index].record) local record=$(uci get frigate.@camera_config[$camera_index].record 2>/dev/null)
local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots) local snapshots=$(uci get frigate.@camera_config[$camera_index].snapshots 2>/dev/null)
local mask=$(uci get frigate.@camera_config[$camera_index].mask) local mask=$(uci get frigate.@camera_config[$camera_index].mask 2>/dev/null)
# Initialize camera structure # Initialize camera structure
yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name = {}" -i /opt/docker2/compose/frigate/config.yml
@ -133,7 +133,7 @@ EOF
yq eval ".cameras.$name.ffmpeg.inputs = []" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.ffmpeg.inputs = []" -i /opt/docker2/compose/frigate/config.yml
# Add path and roles to the inputs # Add path and roles to the inputs
yq eval ".cameras.$name.ffmpeg.inputs[0].path = $path" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.ffmpeg.inputs[0].path = \"$path\"" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.ffmpeg.inputs[0].roles = [\"detect\"]" -i /opt/docker2/compose/frigate/config.yml
# Add other camera settings # Add other camera settings
@ -147,13 +147,19 @@ EOF
yq eval ".cameras.$name.snapshots = {}" -i /opt/docker2/compose/frigate/config.yml yq eval ".cameras.$name.snapshots = {}" -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.snapshots.enabled = $snapshots" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.motion = {}" -i /opt/docker2/compose/frigate/config.yml # Check if the mask is not empty
yq eval ".cameras.$name.motion.mask = [\"$mask\"]" -i /opt/docker2/compose/frigate/config.yml if [ -n "$mask" ]; then
# Run the yq commands to update the YAML file
yq eval ".cameras.$name.motion = {}" -i /opt/docker2/compose/frigate/config.yml
yq eval ".cameras.$name.motion.mask = [\"$mask\"]" -i /opt/docker2/compose/frigate/config.yml
else
echo "Mask is empty, ignoring."
fi
camera_index=$((camera_index+1)) camera_index=$((camera_index+1))
done done
docker-compose -f /opt/docker2/compose/frigate/docker-compose.yml up -d docker-compose -f /opt/docker2/compose/frigate/docker-compose.yml up -d --force-recreate
uci add shortcutmenu lists uci add shortcutmenu lists
uci set shortcutmenu.@lists[-1].webname="$APP_NAME" uci set shortcutmenu.@lists[-1].webname="$APP_NAME"
@ -189,14 +195,12 @@ case "${ACTION}" in
rm -r /opt/docker2/compose/frigate 2>/dev/null rm -r /opt/docker2/compose/frigate 2>/dev/null
;; ;;
"start" | "stop" | "restart") "start" | "stop" | "restart")
APP_NAME="frigate"
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}"
done done
;; ;;
"status") "status")
APP_NAME="frigate"
CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}')
CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }') CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }')
if [ -z "$CONTAINER_NAME" ]; then if [ -z "$CONTAINER_NAME" ]; then
@ -205,8 +209,7 @@ case "${ACTION}" in
echo "${CONTAINER_STATUS}" echo "${CONTAINER_STATUS}"
fi fi
;; ;;
"port") "port")
APP_NAME="frigate"
CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}')
# Fetch the port from UCI configuration # Fetch the port from UCI configuration
uci_port=$(uci get frigate.docker.port 2>/dev/null) uci_port=$(uci get frigate.docker.port 2>/dev/null)

Loading…
Cancel
Save