Update install_frigate.sh
This commit is contained in:
@@ -1,20 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ==========================================
|
||||
# Frigate NVR Installer for Proxmox 9.1 (LXC)
|
||||
# Optimized for PVE 9.x / Debian 13 Host
|
||||
# Frigate Installer for Existing Podman LXC
|
||||
# ==========================================
|
||||
|
||||
set -e
|
||||
|
||||
# --- Configuration Defaults ---
|
||||
CT_ID_DEFAULT="110"
|
||||
HOSTNAME_DEFAULT="frigate-nvr"
|
||||
DISK_SIZE_DEFAULT="20G" # Default disk size
|
||||
RAM_SIZE="4096" # 4GB RAM recommended
|
||||
CORE_COUNT="2"
|
||||
BRIDGE="vmbr0"
|
||||
TEMPLATE_SEARCH="debian-12" # We use Debian 12 container on PVE 9.1 for stability
|
||||
|
||||
# --- Colors ---
|
||||
GREEN='\033[0;32m'
|
||||
@@ -22,115 +15,94 @@ YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}=== Frigate LXC Installer (Proxmox 9.1 Optimized) ===${NC}"
|
||||
echo -e "${GREEN}=== Frigate Installer (Existing Podman LXC) ===${NC}"
|
||||
|
||||
# 1. Select Container ID
|
||||
read -p "Enter Container ID [${CT_ID_DEFAULT}]: " CT_ID
|
||||
# 1. Select Existing Container
|
||||
read -p "Enter Target Container ID [${CT_ID_DEFAULT}]: " CT_ID
|
||||
CT_ID=${CT_ID:-$CT_ID_DEFAULT}
|
||||
|
||||
# Check if ID exists
|
||||
if pct status $CT_ID &>/dev/null; then
|
||||
echo -e "${RED}Error: Container $CT_ID already exists.${NC}"
|
||||
if ! pct status $CT_ID &>/dev/null; then
|
||||
echo -e "${RED}Error: Container $CT_ID does not exist.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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}
|
||||
echo -e "${GREEN}Found Container $CT_ID.${NC}"
|
||||
|
||||
# 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}
|
||||
# 2. Check LXC Configuration (Nesting & Keyctl)
|
||||
# Podman requires nesting=1. We check the config file on the host.
|
||||
CONFIG_FILE="/etc/pve/lxc/${CT_ID}.conf"
|
||||
NEEDS_RESTART=false
|
||||
|
||||
# 4. Hardware Acceleration Check (Intel iGPU)
|
||||
if ! grep -q "features:.*nesting=1" "$CONFIG_FILE"; then
|
||||
echo -e "${YELLOW}Warning: 'nesting' feature is missing (required for Podman).${NC}"
|
||||
read -p "Enable nesting and reboot container? (y/n) [y]: " ENABLE_NESTING
|
||||
ENABLE_NESTING=${ENABLE_NESTING:-y}
|
||||
|
||||
if [[ "$ENABLE_NESTING" =~ ^[Yy]$ ]]; then
|
||||
# Append or modify features
|
||||
if grep -q "^features:" "$CONFIG_FILE"; then
|
||||
sed -i 's/^features: /features: nesting=1,/' "$CONFIG_FILE"
|
||||
else
|
||||
echo "features: nesting=1" >> "$CONFIG_FILE"
|
||||
fi
|
||||
echo -e "${GREEN}Nesting enabled.${NC}"
|
||||
NEEDS_RESTART=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# 3. 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
|
||||
# Check if already passed through
|
||||
if grep -q "dev/dri/renderD128" "$CONFIG_FILE"; then
|
||||
echo -e "${GREEN}iGPU passthrough detected in config.${NC}"
|
||||
IGPU_DETECTED=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# 5. Find Template
|
||||
echo -e "${YELLOW}Searching for Debian 12 template...${NC}"
|
||||
# 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
|
||||
echo -e "${YELLOW}Template not found locally. Searching system...${NC}"
|
||||
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.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}Downloading $TEMPLATE_NAME...${NC}"
|
||||
pveam download local $TEMPLATE_NAME
|
||||
TEMPLATE_VOL="local:vztmpl/$TEMPLATE_NAME"
|
||||
else
|
||||
echo -e "${GREEN}Using existing template: $TEMPLATE_VOL${NC}"
|
||||
fi
|
||||
|
||||
# 6. Create Container
|
||||
echo -e "${GREEN}Creating LXC Container $CT_ID...${NC}"
|
||||
pct create $CT_ID $TEMPLATE_VOL \
|
||||
--arch amd64 \
|
||||
--hostname "$HOSTNAME_DEFAULT" \
|
||||
--cores $CORE_COUNT \
|
||||
--memory $RAM_SIZE \
|
||||
--swap 512 \
|
||||
--storage local-lvm \
|
||||
--rootfs $DISK_SIZE \
|
||||
--net0 name=eth0,bridge=$BRIDGE,ip=$CT_IP \
|
||||
--features nesting=1,keyctl=1,fuse=1 \
|
||||
--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
|
||||
else
|
||||
echo -e "${YELLOW}Intel iGPU detected on host, but not passed to LXC.${NC}"
|
||||
read -p "Pass-through iGPU to this container? (y/n) [y]: " PASSTHROUGH_CONFIRM
|
||||
PASSTHROUGH_CONFIRM=${PASSTHROUGH_CONFIRM:-y}
|
||||
|
||||
if [[ "$PASSTHROUGH_CONFIRM" =~ ^[Yy]$ ]]; then
|
||||
echo -e "${GREEN}Adding iGPU passthrough to config...${NC}"
|
||||
cat <<EOF >> "$CONFIG_FILE"
|
||||
# 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
|
||||
chmod 666 /dev/dri/renderD128
|
||||
IGPU_DETECTED=true
|
||||
NEEDS_RESTART=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}Starting Container...${NC}"
|
||||
pct start $CT_ID
|
||||
# 4. Handle Restart if Config Changed
|
||||
if [ "$NEEDS_RESTART" = true ]; then
|
||||
echo -e "${YELLOW}Container configuration changed. Rebooting container...${NC}"
|
||||
pct stop $CT_ID && pct start $CT_ID
|
||||
echo -e "${YELLOW}Waiting for container to come back online...${NC}"
|
||||
sleep 5
|
||||
# Wait for network
|
||||
while ! pct exec $CT_ID -- ping -c 1 8.8.8.8 &> /dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
|
||||
# 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}"
|
||||
# Ensure container is running if we didn't reboot
|
||||
if [ "$(pct status $CT_ID | awk '{print $2}')" != "running" ]; then
|
||||
echo -e "${GREEN}Starting Container...${NC}"
|
||||
pct start $CT_ID
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
# 9. Install Software inside LXC
|
||||
echo -e "${GREEN}Updating Container & Installing Docker...${NC}"
|
||||
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"
|
||||
# 5. Install Podman inside LXC
|
||||
echo -e "${GREEN}Checking/Installing Podman inside Container...${NC}"
|
||||
pct exec $CT_ID -- bash -c "apt-get update"
|
||||
pct exec $CT_ID -- bash -c "apt-get install -y podman podman-compose"
|
||||
|
||||
# 10. Configure Frigate
|
||||
# 6. Configure Frigate Directories
|
||||
echo -e "${GREEN}Setting up Frigate Configuration...${NC}"
|
||||
|
||||
# Create directories
|
||||
pct exec $CT_ID -- mkdir -p /opt/frigate/config
|
||||
pct exec $CT_ID -- mkdir -p /opt/frigate/storage
|
||||
|
||||
@@ -151,24 +123,27 @@ cameras:
|
||||
enabled: False
|
||||
EOF"
|
||||
|
||||
# Create docker-compose.yml
|
||||
# Note: We conditionally uncomment the device mapping if iGPU was detected
|
||||
# 7. Create Docker Compose (Podman Compatible)
|
||||
# Note: Podman handles SHM differently, but podman-compose tries to mimic docker behavior.
|
||||
# We set privileged: true to ensure easy access to /dev/dri if passed through.
|
||||
|
||||
RENDER_LINE=""
|
||||
if [ "$IGPU_DETECTED" = true ]; then
|
||||
RENDER_LINE=" - /dev/dri/renderD128:/dev/dri/renderD128 # Intel HW Accel"
|
||||
RENDER_LINE=" - /dev/dri/renderD128:/dev/dri/renderD128"
|
||||
fi
|
||||
|
||||
pct exec $CT_ID -- bash -c "cat > /opt/frigate/docker-compose.yml <<EOF
|
||||
version: \"3.9\"
|
||||
services:
|
||||
frigate:
|
||||
container_name: frigate
|
||||
privileged: true
|
||||
privileged: true
|
||||
restart: unless-stopped
|
||||
image: ghcr.io/blakeblackshear/frigate:stable
|
||||
shm_size: \"128mb\"
|
||||
shm_size: \"128mb\"
|
||||
devices:
|
||||
$RENDER_LINE
|
||||
# - /dev/bus/usb:/dev/bus/usb # Uncomment for Coral USB
|
||||
# - /dev/bus/usb:/dev/bus/usb
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /opt/frigate/config:/config
|
||||
@@ -180,21 +155,20 @@ $RENDER_LINE
|
||||
ports:
|
||||
- \"5000:5000\"
|
||||
- \"8554:8554\"
|
||||
- \"8555:8555/tcp\"
|
||||
- \"8555:8555/udp\"
|
||||
- \"8555:8555/tcp\"
|
||||
- \"8555:8555/udp\"
|
||||
EOF"
|
||||
|
||||
# 11. Start Frigate
|
||||
echo -e "${GREEN}Starting Frigate...${NC}"
|
||||
pct exec $CT_ID -- bash -c "cd /opt/frigate && docker compose up -d"
|
||||
# 8. Start Frigate using Podman Compose
|
||||
echo -e "${GREEN}Starting Frigate with Podman...${NC}"
|
||||
# We use nohup or detach so the script doesn't hang waiting for output
|
||||
pct exec $CT_ID -- bash -c "cd /opt/frigate && podman-compose up -d"
|
||||
|
||||
# 12. Finish
|
||||
# 9. 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}"
|
||||
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 "Target Container: ${CT_ID}"
|
||||
echo -e "Frigate URL: ${YELLOW}http://${IP_ADDR}:5000${NC}"
|
||||
echo -e "Engine: Podman (managed via podman-compose)"
|
||||
echo -e "=========================================="
|
||||
Reference in New Issue
Block a user