#!/bin/sh APP_NAME="frigate" ACTION="${1}" shift 1 get_image() { do_install_detail } do_install_detail() { local config port IMAGE_NAME LAN_IP local usbcoral hwaccel storage mqtt host coral type device echo "Fetching port from configuration..." port=$(uci get frigate.docker.port 2>/dev/null) [ -z "$port" ] && { echo "Error: Port not found in configuration."; exit 1; } echo "Fetching image name from configuration..." IMAGE_NAME=$(uci get frigate.docker.image 2>/dev/null) [ -z "$IMAGE_NAME" ] && { echo "Error: Image name not found in configuration."; exit 1; } echo "Fetching USB Coral path from configuration..." usbcoral=$(uci get frigate.docker.usbcoral 2>/dev/null) [ -z "$usbcoral" ] && { echo "Error: USB Coral path not found in configuration."; exit 1; } echo "Fetching hardware acceleration path from configuration..." hwaccel=$(uci get frigate.docker.hwaccel 2>/dev/null) [ -z "$hwaccel" ] && { echo "Error: Hardware acceleration path not found in configuration."; exit 1; } echo "Fetching storage path from configuration..." storage=$(uci get frigate.docker.storage 2>/dev/null) [ -z "$storage" ] && { echo "Error: Storage path not found in configuration."; exit 1; } echo "Fetching MQTT status from configuration..." mqtt=$(uci get frigate.mqtt.enabled 2>/dev/null) [ -z "$mqtt" ] && { echo "Error: MQTT status not found in configuration."; exit 1; } echo "Fetching MQTT host from configuration..." host=$(uci get frigate.mqtt.host 2>/dev/null) [ -z "$host" ] && { echo "Error: MQTT host not found in configuration."; exit 1; } echo "Fetching Coral status from configuration..." coral=$(uci get frigate.tpu.enabled 2>/dev/null) [ -z "$coral" ] && { echo "Error: Coral status not found in configuration."; exit 1; } echo "Fetching Coral type from configuration..." type=$(uci get frigate.tpu.type 2>/dev/null) [ -z "$type" ] && { echo "Error: Coral type not found in configuration."; exit 1; } echo "Fetching Coral device from configuration..." device=$(uci get frigate.tpu.device 2>/dev/null) [ -z "$device" ] && { echo "Error: Coral device not found in configuration."; exit 1; } LAN_IP=$(uci get network.lan.ipaddr) LAN_IP="${LAN_IP%/*}" [ -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 touch /opt/docker2/compose/frigate/config.yml touch /opt/docker2/compose/frigate/docker-compose.yml cat > /opt/docker2/compose/frigate/docker-compose.yml </dev/null) [ -z "$IMAGE_NAME" ] && IMAGE_NAME="ghcr.io/blakeblackshear/frigate:stable" CONTAINER_IDS=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.ID}}') echo "Stopping and removing containers..." for ID in $CONTAINER_IDS; do docker stop "$ID" docker rm "$ID" done docker rmi -f "$IMAGE_NAME" rm -r /opt/docker2/compose/frigate 2>/dev/null ;; "start" | "stop" | "restart") APP_NAME="frigate" CONTAINER_IDS=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.ID}}') for ID in $CONTAINER_IDS; do docker "${ACTION}" "${ID}" done ;; "status") APP_NAME="frigate" 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" }') if [ -z "$CONTAINER_NAME" ]; then echo "${APP_NAME} is not installed" else echo "${CONTAINER_STATUS}" fi ;; "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 ;; esac