2024-03-30 13:15:03 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Copyright (c) 2021-2024 tteck
|
|
|
|
# Authors: tteck (tteckster)
|
|
|
|
# License: MIT
|
|
|
|
# https://github.com/tteck/Proxmox/raw/main/LICENSE
|
|
|
|
|
|
|
|
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
|
|
|
|
color
|
|
|
|
verb_ip6
|
|
|
|
catch_errors
|
|
|
|
setting_up_container
|
|
|
|
network_check
|
|
|
|
update_os
|
|
|
|
|
|
|
|
msg_info "Installing Dependencies (Patience)"
|
2024-05-14 07:27:16 +02:00
|
|
|
$STD apt-get install -y {curl,sudo,mc,git,gpg,automake,build-essential,xz-utils,libtool,ccache,pkg-config,libgtk-3-dev,libavcodec-dev,libavformat-dev,libswscale-dev,libv4l-dev,libxvidcore-dev,libx264-dev,libjpeg-dev,libpng-dev,libtiff-dev,gfortran,openexr,libatlas-base-dev,libssl-dev,libtbb2,libtbb-dev,libdc1394-22-dev,libopenexr-dev,libgstreamer-plugins-base1.0-dev,libgstreamer1.0-dev,gcc,gfortran,libopenblas-dev,liblapack-dev,libusb-1.0-0-dev,jq}
|
2024-03-30 13:15:03 +01:00
|
|
|
msg_ok "Installed Dependencies"
|
|
|
|
|
|
|
|
msg_info "Installing Python3 Dependencies"
|
2024-04-09 03:21:08 +02:00
|
|
|
$STD apt-get install -y {python3,python3-dev,python3-setuptools,python3-distutils,python3-pip}
|
2024-03-30 13:15:03 +01:00
|
|
|
msg_ok "Installed Python3 Dependencies"
|
|
|
|
|
|
|
|
msg_info "Installing Node.js"
|
|
|
|
mkdir -p /etc/apt/keyrings
|
|
|
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
|
|
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
|
|
|
|
$STD apt-get update
|
|
|
|
$STD apt-get install -y nodejs
|
|
|
|
msg_ok "Installed Node.js"
|
|
|
|
|
|
|
|
msg_info "Installing go2rtc"
|
|
|
|
mkdir -p /usr/local/go2rtc/bin
|
|
|
|
cd /usr/local/go2rtc/bin
|
|
|
|
wget -qO go2rtc "https://github.com/AlexxIT/go2rtc/releases/latest/download/go2rtc_linux_amd64"
|
|
|
|
chmod +x go2rtc
|
|
|
|
$STD ln -svf /usr/local/go2rtc/bin/go2rtc /usr/local/bin/go2rtc
|
|
|
|
msg_ok "Installed go2rtc"
|
|
|
|
|
2024-04-27 12:39:42 +02:00
|
|
|
msg_info "Setting Up Hardware Acceleration"
|
|
|
|
$STD apt-get -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools}
|
2024-03-30 13:15:03 +01:00
|
|
|
if [[ "$CTTYPE" == "0" ]]; then
|
|
|
|
chgrp video /dev/dri
|
|
|
|
chmod 755 /dev/dri
|
|
|
|
chmod 660 /dev/dri/*
|
|
|
|
fi
|
2024-04-27 12:39:42 +02:00
|
|
|
msg_ok "Set Up Hardware Acceleration"
|
2024-05-14 07:27:16 +02:00
|
|
|
RELEASE=$(curl -s https://api.github.com/repos/blakeblackshear/frigate/releases/latest | jq -r '.tag_name')
|
2024-05-14 08:13:07 +02:00
|
|
|
msg_ok "Stop spinner to prevent segmentation fault"
|
2024-03-30 13:15:03 +01:00
|
|
|
msg_info "Installing Frigate $RELEASE (Perseverance)"
|
2024-05-14 08:00:33 +02:00
|
|
|
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
2024-03-30 13:15:03 +01:00
|
|
|
cd ~
|
|
|
|
mkdir -p /opt/frigate/models
|
|
|
|
wget -q https://github.com/blakeblackshear/frigate/archive/refs/tags/${RELEASE}.tar.gz -O frigate.tar.gz
|
|
|
|
tar -xzf frigate.tar.gz -C /opt/frigate --strip-components 1
|
|
|
|
rm -rf frigate.tar.gz
|
|
|
|
cd /opt/frigate
|
|
|
|
$STD pip3 wheel --wheel-dir=/wheels -r /opt/frigate/docker/main/requirements-wheels.txt
|
|
|
|
cp -a /opt/frigate/docker/main/rootfs/. /
|
|
|
|
export TARGETARCH="amd64"
|
|
|
|
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections
|
|
|
|
$STD /opt/frigate/docker/main/install_deps.sh
|
|
|
|
$STD ln -svf /usr/lib/btbn-ffmpeg/bin/ffmpeg /usr/local/bin/ffmpeg
|
|
|
|
$STD ln -svf /usr/lib/btbn-ffmpeg/bin/ffprobe /usr/local/bin/ffprobe
|
|
|
|
$STD pip3 install -U /wheels/*.whl
|
|
|
|
ldconfig
|
|
|
|
$STD pip3 install -r /opt/frigate/docker/main/requirements-dev.txt
|
|
|
|
$STD /opt/frigate/.devcontainer/initialize.sh
|
|
|
|
$STD make version
|
|
|
|
cd /opt/frigate/web
|
|
|
|
$STD npm install
|
|
|
|
$STD npm run build
|
|
|
|
cp -r /opt/frigate/web/dist/* /opt/frigate/web/
|
|
|
|
cp -r /opt/frigate/config/. /config
|
|
|
|
sed -i '/^s6-svc -O \.$/s/^/#/' /opt/frigate/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run
|
2024-04-01 12:36:57 +02:00
|
|
|
cat <<EOF >/config/config.yml
|
|
|
|
mqtt:
|
|
|
|
enabled: false
|
|
|
|
cameras:
|
|
|
|
test:
|
|
|
|
ffmpeg:
|
2024-04-01 14:19:44 +02:00
|
|
|
#hwaccel_args: preset-vaapi
|
2024-04-01 12:36:57 +02:00
|
|
|
inputs:
|
|
|
|
- path: /media/frigate/person-bicycle-car-detection.mp4
|
|
|
|
input_args: -re -stream_loop -1 -fflags +genpts
|
|
|
|
roles:
|
|
|
|
- detect
|
|
|
|
- rtmp
|
|
|
|
detect:
|
|
|
|
height: 1080
|
|
|
|
width: 1920
|
|
|
|
fps: 5
|
|
|
|
EOF
|
|
|
|
ln -sf /config/config.yml /opt/frigate/config/config.yml
|
2024-04-27 12:39:42 +02:00
|
|
|
if [[ "$CTTYPE" == "0" ]]; then
|
|
|
|
sed -i -e 's/^kvm:x:104:$/render:x:104:root,frigate/' -e 's/^render:x:105:root$/kvm:x:105:/' /etc/group
|
|
|
|
else
|
|
|
|
sed -i -e 's/^kvm:x:104:$/render:x:104:frigate/' -e 's/^render:x:105:$/kvm:x:105:/' /etc/group
|
|
|
|
fi
|
2024-04-15 18:47:22 +02:00
|
|
|
echo "tmpfs /tmp/cache tmpfs defaults 0 0" >> /etc/fstab
|
2024-03-30 13:15:03 +01:00
|
|
|
msg_ok "Installed Frigate $RELEASE"
|
|
|
|
|
2024-04-16 11:39:00 +02:00
|
|
|
if grep -q -o -m1 'avx[^ ]*' /proc/cpuinfo; then
|
2024-04-19 17:30:27 +02:00
|
|
|
msg_ok "AVX Support Detected"
|
2024-04-16 11:39:00 +02:00
|
|
|
msg_info "Installing Openvino Object Detection Model (Resilience)"
|
|
|
|
$STD pip install -r /opt/frigate/docker/main/requirements-ov.txt
|
|
|
|
cd /opt/frigate/models
|
|
|
|
export ENABLE_ANALYTICS=NO
|
|
|
|
$STD /usr/local/bin/omz_downloader --name ssdlite_mobilenet_v2 --num_attempts 2
|
|
|
|
$STD /usr/local/bin/omz_converter --name ssdlite_mobilenet_v2 --precision FP16 --mo /usr/local/bin/mo
|
2024-04-16 22:09:11 +02:00
|
|
|
cd /
|
|
|
|
cp -r /opt/frigate/models/public/ssdlite_mobilenet_v2 openvino-model
|
|
|
|
wget -q https://github.com/openvinotoolkit/open_model_zoo/raw/master/data/dataset_classes/coco_91cl_bkgr.txt -O openvino-model/coco_91cl_bkgr.txt
|
|
|
|
sed -i 's/truck/car/g' openvino-model/coco_91cl_bkgr.txt
|
2024-04-16 11:39:00 +02:00
|
|
|
cat <<EOF >>/config/config.yml
|
|
|
|
detectors:
|
|
|
|
ov:
|
|
|
|
type: openvino
|
|
|
|
device: AUTO
|
|
|
|
model:
|
|
|
|
path: /openvino-model/FP16/ssdlite_mobilenet_v2.xml
|
|
|
|
model:
|
|
|
|
width: 300
|
|
|
|
height: 300
|
|
|
|
input_tensor: nhwc
|
|
|
|
input_pixel_format: bgr
|
|
|
|
labelmap_path: /openvino-model/coco_91cl_bkgr.txt
|
|
|
|
EOF
|
2024-04-19 17:06:40 +02:00
|
|
|
msg_ok "Installed Openvino Object Detection Model"
|
2024-04-16 11:39:00 +02:00
|
|
|
else
|
|
|
|
cat <<EOF >>/config/config.yml
|
|
|
|
model:
|
|
|
|
path: /cpu_model.tflite
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2024-04-19 17:30:27 +02:00
|
|
|
msg_info "Installing Coral Object Detection Model (Patience)"
|
2024-04-16 11:39:00 +02:00
|
|
|
cd /opt/frigate
|
2024-03-30 13:15:03 +01:00
|
|
|
export CCACHE_DIR=/root/.ccache
|
|
|
|
export CCACHE_MAXSIZE=2G
|
|
|
|
wget -q https://github.com/libusb/libusb/archive/v1.0.26.zip
|
|
|
|
unzip -q v1.0.26.zip
|
2024-03-30 16:15:57 +01:00
|
|
|
rm v1.0.26.zip
|
2024-03-30 13:15:03 +01:00
|
|
|
cd libusb-1.0.26
|
|
|
|
$STD ./bootstrap.sh
|
|
|
|
$STD ./configure --disable-udev --enable-shared
|
|
|
|
$STD make -j $(nproc --all)
|
|
|
|
cd /opt/frigate/libusb-1.0.26/libusb
|
|
|
|
mkdir -p /usr/local/lib
|
|
|
|
$STD /bin/bash ../libtool --mode=install /usr/bin/install -c libusb-1.0.la '/usr/local/lib'
|
|
|
|
mkdir -p /usr/local/include/libusb-1.0
|
|
|
|
$STD /usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0'
|
|
|
|
ldconfig
|
2024-04-05 14:43:31 +02:00
|
|
|
cd /
|
2024-03-30 13:15:03 +01:00
|
|
|
wget -qO edgetpu_model.tflite https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite
|
|
|
|
wget -qO cpu_model.tflite https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess.tflite
|
|
|
|
cp /opt/frigate/labelmap.txt /labelmap.txt
|
|
|
|
wget -qO cpu_audio_model.tflite https://tfhub.dev/google/lite-model/yamnet/classification/tflite/1?lite-format=tflite
|
|
|
|
cp /opt/frigate/audio-labelmap.txt /audio-labelmap.txt
|
2024-04-01 13:19:13 +02:00
|
|
|
mkdir -p /media/frigate
|
2024-04-01 13:05:24 +02:00
|
|
|
wget -qO /media/frigate/person-bicycle-car-detection.mp4 https://github.com/intel-iot-devkit/sample-videos/raw/master/person-bicycle-car-detection.mp4
|
2024-04-16 11:39:00 +02:00
|
|
|
msg_ok "Installed Coral Object Detection Model"
|
2024-03-30 13:15:03 +01:00
|
|
|
|
|
|
|
msg_info "Building Nginx with Custom Modules"
|
|
|
|
$STD /opt/frigate/docker/main/build_nginx.sh
|
|
|
|
sed -i 's/exec nginx/exec \/usr\/local\/nginx\/sbin\/nginx/g' /opt/frigate/docker/main/rootfs/etc/s6-overlay/s6-rc.d/nginx/run
|
2024-04-17 19:21:26 +02:00
|
|
|
sed -i 's/error_log \/dev\/stdout warn\;/error_log \/dev\/shm\/logs\/nginx\/current warn\;/' /usr/local/nginx/conf/nginx.conf
|
|
|
|
sed -i 's/access_log \/dev\/stdout main\;/access_log \/dev\/shm\/logs\/nginx\/current main\;/' /usr/local/nginx/conf/nginx.conf
|
2024-03-30 13:15:03 +01:00
|
|
|
msg_ok "Built Nginx"
|
|
|
|
|
|
|
|
msg_info "Creating Services"
|
2024-04-01 18:43:15 +02:00
|
|
|
cat <<EOF >/etc/systemd/system/create_directories.service
|
|
|
|
[Unit]
|
|
|
|
Description=Create necessary directories for logs
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
ExecStart=/bin/bash -c '/bin/mkdir -p /dev/shm/logs/{frigate,go2rtc,nginx} && /bin/touch /dev/shm/logs/{frigate/current,go2rtc/current,nginx/current} && /bin/chmod -R 777 /dev/shm/logs'
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
systemctl enable -q --now create_directories
|
|
|
|
sleep 3
|
2024-03-30 13:15:03 +01:00
|
|
|
cat <<EOF >/etc/systemd/system/go2rtc.service
|
|
|
|
[Unit]
|
|
|
|
Description=go2rtc service
|
|
|
|
After=network.target
|
2024-04-01 18:43:15 +02:00
|
|
|
After=create_directories.service
|
2024-03-30 13:15:03 +01:00
|
|
|
StartLimitIntervalSec=0
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
Restart=always
|
|
|
|
RestartSec=1
|
|
|
|
User=root
|
2024-04-19 16:48:10 +02:00
|
|
|
ExecStartPre=+rm /dev/shm/logs/go2rtc/current
|
2024-03-30 13:15:03 +01:00
|
|
|
ExecStart=bash /opt/frigate/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run
|
2024-04-01 18:43:15 +02:00
|
|
|
StandardOutput=file:/dev/shm/logs/go2rtc/current
|
|
|
|
StandardError=file:/dev/shm/logs/go2rtc/current
|
2024-03-30 13:15:03 +01:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
systemctl enable -q --now go2rtc
|
|
|
|
sleep 3
|
|
|
|
cat <<EOF >/etc/systemd/system/frigate.service
|
|
|
|
[Unit]
|
|
|
|
Description=Frigate service
|
|
|
|
After=go2rtc.service
|
2024-04-01 18:43:15 +02:00
|
|
|
After=create_directories.service
|
2024-03-30 13:15:03 +01:00
|
|
|
StartLimitIntervalSec=0
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
Restart=always
|
|
|
|
RestartSec=1
|
|
|
|
User=root
|
2024-04-19 16:48:10 +02:00
|
|
|
ExecStartPre=+rm /dev/shm/logs/frigate/current
|
2024-03-30 13:15:03 +01:00
|
|
|
ExecStart=bash /opt/frigate/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run
|
2024-04-01 18:43:15 +02:00
|
|
|
StandardOutput=file:/dev/shm/logs/frigate/current
|
|
|
|
StandardError=file:/dev/shm/logs/frigate/current
|
2024-03-30 13:15:03 +01:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
systemctl enable -q --now frigate
|
|
|
|
sleep 3
|
|
|
|
cat <<EOF >/etc/systemd/system/nginx.service
|
|
|
|
[Unit]
|
|
|
|
Description=Nginx service
|
|
|
|
After=frigate.service
|
2024-04-01 18:43:15 +02:00
|
|
|
After=create_directories.service
|
2024-03-30 13:15:03 +01:00
|
|
|
StartLimitIntervalSec=0
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
Restart=always
|
|
|
|
RestartSec=1
|
|
|
|
User=root
|
2024-04-19 16:48:10 +02:00
|
|
|
ExecStartPre=+rm /dev/shm/logs/nginx/current
|
2024-03-30 13:15:03 +01:00
|
|
|
ExecStart=bash /opt/frigate/docker/main/rootfs/etc/s6-overlay/s6-rc.d/nginx/run
|
2024-04-01 18:43:15 +02:00
|
|
|
StandardOutput=file:/dev/shm/logs/nginx/current
|
|
|
|
StandardError=file:/dev/shm/logs/nginx/current
|
2024-03-30 13:15:03 +01:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
systemctl enable -q --now nginx
|
|
|
|
msg_ok "Configured Services"
|
|
|
|
|
|
|
|
motd_ssh
|
|
|
|
customize
|
|
|
|
|
|
|
|
msg_info "Cleaning up"
|
2024-05-02 19:26:16 +02:00
|
|
|
$STD apt-get -y autoremove
|
|
|
|
$STD apt-get -y autoclean
|
2024-03-30 13:15:03 +01:00
|
|
|
msg_ok "Cleaned"
|