Update install_frigate.sh

This commit is contained in:
maq
2025-12-15 18:16:47 -08:00
parent 63deeec445
commit d1d8c74dff

View File

@@ -1,8 +1,8 @@
#!/bin/bash
# ==========================================
# Frigate NVR Installer for Proxmox LXC
# Replicates "Helper Script" functionality
# Frigate NVR Installer for Proxmox 9.1 (LXC)
# Optimized for PVE 9.x / Debian 13 Host
# ==========================================
set -e
@@ -10,11 +10,11 @@ set -e
# --- Configuration Defaults ---
CT_ID_DEFAULT="110"
HOSTNAME_DEFAULT="frigate-nvr"
DISK_SIZE="20G" # Frigate needs space for recordings
RAM_SIZE="4096" # 4GB RAM recommended for detection
DISK_SIZE_DEFAULT="20G" # Default disk size
RAM_SIZE="4096" # 4GB RAM recommended
CORE_COUNT="2"
BRIDGE="vmbr0"
TEMPLATE_SEARCH="debian-12"
TEMPLATE_SEARCH="debian-12" # We use Debian 12 container on PVE 9.1 for stability
# --- Colors ---
GREEN='\033[0;32m'
@@ -22,7 +22,7 @@ YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== Frigate LXC Installer ===${NC}"
echo -e "${GREEN}=== Frigate LXC Installer (Proxmox 9.1 Optimized) ===${NC}"
# 1. Select Container ID
read -p "Enter Container ID [${CT_ID_DEFAULT}]: " CT_ID
@@ -34,21 +34,37 @@ if pct status $CT_ID &>/dev/null; then
exit 1
fi
# 2. Select IP Address
# 2. Disk Size Prompt
read -p "Enter Disk Size (e.g., 20G, 50G) [${DISK_SIZE_DEFAULT}]: " DISK_SIZE
DISK_SIZE=${DISK_SIZE:-$DISK_SIZE_DEFAULT}
# 3. Select IP Address
read -p "Enter IP Address (e.g., 192.168.1.50/24) or type 'dhcp' [dhcp]: " CT_IP
CT_IP=${CT_IP:-dhcp}
# 3. Find Template
# 4. Hardware Acceleration Check (Intel iGPU)
IGPU_DETECTED=false
if [ -e /dev/dri/renderD128 ]; then
echo -e "${YELLOW}Intel iGPU detected at /dev/dri/renderD128${NC}"
read -p "Pass-through iGPU to Frigate container? (y/n) [y]: " PASSTHROUGH_CONFIRM
PASSTHROUGH_CONFIRM=${PASSTHROUGH_CONFIRM:-y}
if [[ "$PASSTHROUGH_CONFIRM" =~ ^[Yy]$ ]]; then
IGPU_DETECTED=true
fi
fi
# 5. Find Template
echo -e "${YELLOW}Searching for Debian 12 template...${NC}"
TEMPLATE_VOL=$(pveam list local | grep "$TEMPLATE_SEARCH" | tail -n 1 | awk '{print $2}')
# Update template list first to ensure we find it
pveam update > /dev/null
TEMPLATE_VOL=$(pveam list local | grep "$TEMPLATE_SEARCH" | sort | tail -n 1 | awk '{print $2}')
if [ -z "$TEMPLATE_VOL" ]; then
# Fallback to checking available system templates if not downloaded locally
echo -e "${YELLOW}Template not found locally. Searching system...${NC}"
TEMPLATE_NAME=$(pveam available --section system | grep "$TEMPLATE_SEARCH" | tail -n 1 | awk '{print $2}')
TEMPLATE_NAME=$(pveam available --section system | grep "$TEMPLATE_SEARCH" | sort | tail -n 1 | awk '{print $2}')
if [ -z "$TEMPLATE_NAME" ]; then
echo -e "${RED}Error: No Debian 12 template found. Run 'pveam update' first.${NC}"
echo -e "${RED}Error: No Debian 12 template found.${NC}"
exit 1
fi
@@ -56,12 +72,10 @@ if [ -z "$TEMPLATE_VOL" ]; then
pveam download local $TEMPLATE_NAME
TEMPLATE_VOL="local:vztmpl/$TEMPLATE_NAME"
else
# Format local volume string correctly if found via pveam list
# Usually pveam list returns "local:vztmpl/debian-12..."
echo -e "${GREEN}Using existing template: $TEMPLATE_VOL${NC}"
fi
# 4. Create Container
# 6. Create Container
echo -e "${GREEN}Creating LXC Container $CT_ID...${NC}"
pct create $CT_ID $TEMPLATE_VOL \
--arch amd64 \
@@ -76,20 +90,44 @@ pct create $CT_ID $TEMPLATE_VOL \
--unprivileged 1 \
--onboot 1
# 7. Apply Hardware Pass-through (if selected)
if [ "$IGPU_DETECTED" = true ]; then
echo -e "${GREEN}Configuring iGPU pass-through in /etc/pve/lxc/${CT_ID}.conf...${NC}"
# Allow access to the render device cgroup
cat <<EOF >> /etc/pve/lxc/${CT_ID}.conf
# Hardware Acceleration Pass-through
lxc.cgroup2.devices.allow: c 226:128 rwm
lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
EOF
# Ensure permissions on host (simple fix for unprivileged containers)
chmod 666 /dev/dri/renderD128
fi
echo -e "${GREEN}Starting Container...${NC}"
pct start $CT_ID
# Wait for network
echo -e "${YELLOW}Waiting for container network...${NC}"
sleep 10
# 8. Wait for network (Robust Check)
echo -e "${YELLOW}Waiting for network connection...${NC}"
MAX_RETRIES=30
COUNT=0
while ! pct exec $CT_ID -- ping -c 1 8.8.8.8 &> /dev/null; do
sleep 1
((COUNT++))
if [ $COUNT -ge $MAX_RETRIES ]; then
echo -e "${RED}Error: Container failed to get network access.${NC}"
exit 1
fi
done
echo -e "${GREEN}Network Connected!${NC}"
# 5. Install Software inside LXC
# 9. Install Software inside LXC
echo -e "${GREEN}Updating Container & Installing Docker...${NC}"
# We assume the container has internet access.
pct exec $CT_ID -- bash -c "apt-get update && apt-get install -y curl"
pct exec $CT_ID -- bash -c "apt-get update && apt-get install -y curl ca-certificates gnupg"
pct exec $CT_ID -- bash -c "curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh"
# 6. Configure Frigate
# 10. Configure Frigate
echo -e "${GREEN}Setting up Frigate Configuration...${NC}"
# Create directories
@@ -102,7 +140,7 @@ mqtt:
enabled: False
cameras:
test_camera: # A dummy camera to let Frigate start without errors
test_camera:
ffmpeg:
inputs:
- path: /media/frigate/clips/test.mp4
@@ -114,41 +152,49 @@ cameras:
EOF"
# Create docker-compose.yml
# Note: We conditionally uncomment the device mapping if iGPU was detected
RENDER_LINE=""
if [ "$IGPU_DETECTED" = true ]; then
RENDER_LINE=" - /dev/dri/renderD128:/dev/dri/renderD128 # Intel HW Accel"
fi
pct exec $CT_ID -- bash -c "cat > /opt/frigate/docker-compose.yml <<EOF
version: \"3.9\"
services:
frigate:
container_name: frigate
privileged: true # Optional, helps with hardware access
privileged: true
restart: unless-stopped
image: ghcr.io/blakeblackshear/frigate:stable
shm_size: \"64mb\" # Increase for high resolution cameras
shm_size: \"128mb\"
devices:
# - /dev/dri/renderD128 # Uncomment for Intel HW Accel
# - /dev/bus/usb # Uncomment for Coral USB
$RENDER_LINE
# - /dev/bus/usb:/dev/bus/usb # Uncomment for Coral USB
volumes:
- /etc/localtime:/etc/localtime:ro
- /opt/frigate/config:/config
- /opt/frigate/storage:/media/frigate
- type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
- type: tmpfs
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- \"5000:5000\"
- \"8554:8554\" # RTSP feeds
- \"8555:8555/tcp\" # WebRTC
- \"8555:8555/udp\" # WebRTC
- \"8554:8554\"
- \"8555:8555/tcp\"
- \"8555:8555/udp\"
EOF"
# 7. Start Frigate
# 11. Start Frigate
echo -e "${GREEN}Starting Frigate...${NC}"
pct exec $CT_ID -- bash -c "cd /opt/frigate && docker compose up -d"
# 8. Finish
# 12. Finish
IP_ADDR=$(pct exec $CT_ID -- ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
echo -e "=========================================="
echo -e "${GREEN}Installation Complete!${NC}"
echo -e "Frigate is running at: ${YELLOW}http://${IP_ADDR}:5000${NC}"
echo -e "Default Config Location: /opt/frigate/config/config.yml"
if [ "$IGPU_DETECTED" = true ]; then
echo -e "Intel iGPU: ${GREEN}Enabled & Passed Through${NC}"
fi
echo -e "Default Config: /opt/frigate/config/config.yml"
echo -e "=========================================="