#!/bin/sh APP_NAME="frigate" ACTION="${1}" shift 1 get_image() { do_install_detail } do_install_detail() { local config port IMAGE_NAME username password LAN_IP local usbcoral hwaccel storage mqtt host coral type device config=$(uci get frigate.@frigate_config[0].config_path 2>/dev/null) port=$(uci get frigate.@frigate_config[0].port 2>/dev/null) IMAGE_NAME=$(uci get frigate.@frigate_config[0].image 2>/dev/null) usbcoral=$(uci get frigate.@frigate_config[0].usbcoral 2>/dev/null) hwaccel=$(uci get frigate.@frigate_config[0].hwaccel 2>/dev/null) storage=$(uci get frigate.@frigate_config[0].storage 2>/dev/null) mqtt=$(uci get frigate.@frigate_config[0].mqtt 2>/dev/null) host=$(uci get frigate.@frigate_config[0].host 2>/dev/null) coral=$(uci get frigate.@frigate_config[0].coral 2>/dev/null) type=$(uci get frigate.@frigate_config[0].type 2>/dev/null) device=$(uci get frigate.@frigate_config[0].device 2>/dev/null) username=$(uci get frigate.@frigate_config[0].username 2>/dev/null) password=$(uci get frigate.@frigate_config[0].password 2>/dev/null) APP_NAME="frigate" GEN_PASS=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c 14; echo) GEN_PASS2=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c 14; echo) LAN_IP=$(uci get network.lan.ipaddr) LAN_IP="${LAN_IP%/*}" if [ -z "$config" ]; then echo "config path is empty!" exit 1 fi [ -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 # Write global settings to config.yml using yq # Replace these uci get commands with actual commands to get these variables local usbcoral=$(uci get frigate.@frigate_config[0].usbcoral) local hwaccel=$(uci get frigate.@frigate_config[0].hwaccel) local storage=$(uci get frigate.@frigate_config[0].storage) local mqtt=$(uci get frigate.@frigate_config[0].mqtt) local host=$(uci get frigate.@frigate_config[0].host) local coral=$(uci get frigate.@frigate_config[0].coral) local type=$(uci get frigate.@frigate_config[0].type) 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_NAMES=$(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_STATUS" ]; 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