Fix install sed and systemd services,working on bullseye test

This commit is contained in:
Samuel Ortion 2022-08-13 11:33:40 +02:00
parent 601b402db5
commit 29dcd4c999
9 changed files with 114 additions and 32 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ var/
.env
species_list.txt
push.sh

View File

@ -15,7 +15,7 @@ BirdNET-stream record sound on Linux computer and analyze it with the help of th
On debian based system, you can install BirdNET-stream with the following command:
```bash
curl -sL https://raw.githubusercontent.com/birdnet-stream/birdnet-stream/master/install.sh | bash
curl -sL https://raw.githubusercontent.com/UncleSamulus/BirdNET-stream/main/install.sh | bash
```
For finer control, or to adapt to your system, you can follow the instructions in the [INSTALL.md](./INSTALL.md) file.

0
TODO Normal file
View File

View File

@ -50,11 +50,14 @@ junk() {
junk="$junk $(find ${CHUNK_FOLDER}/out -type d -empty)"
# Get all empty record directories
treatement_folder=$(find "${CHUNK_FOLDER}/out" -type d ! -empty)
for folder in $treatement_folder; do
if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then
junk="$junk $folder"
fi
done
if [[ ! -z ${treatement_folder} ]]; then
for folder in $treatement_folder; do
echo $folder
if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then
junk="$junk $folder"
fi
done
fi
echo "$junk"
}

View File

@ -1,9 +1,38 @@
#! /usr/bin/env bash
record_chunk() {
DEBUG=${DEBUG:-0}
export PULSE_RUNTIME_PATH="/run/user/$(id -u)/pulse/"
debug() {
if [ $DEBUG -eq 1 ]; then
echo "$1"
fi
}
check_folder() {
if [[ ! -d "${CHUNK_FOLDER}" ]]; then
debug "CHUNK_FOLDER does not exist: ${CHUNK_FOLDER}"
debug "Creating recording dir"
mkdir -p "${CHUNK_FOLDER}/in"
fi
}
record_loop() {
DEVICE=$1
DURATION=$2
ffmpeg -f pulse -i ${DEVICE} -t ${DURATION} -vn -acodec pcm_s16le -ac 1 -ar 48000 file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav
debug "New recording loop."
while true; do
record $DEVICE $DURATION
done
}
record() {
DEVICE=$1
DURATION=$2
debug "Recording from $DEVICE for $DURATION seconds"
echo "" | ffmpeg -nostdin -f pulse -i ${DEVICE} -t ${DURATION} -vn -acodec pcm_s16le -ac 1 -ar 48000 file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav
}
config_filepath="./config/analyzer.conf"
@ -15,6 +44,8 @@ else
exit 1
fi
check_folder
[ -z $RECORDING_DURATION ] && RECORDING_DURATION=15
if [[ -z $AUDIO_DEVICE ]]; then
@ -22,16 +53,4 @@ if [[ -z $AUDIO_DEVICE ]]; then
exit 1
fi
check_folder() {
if [[ ! -d "${CHUNK_FOLDER}" ]]; then
echo "CHUNK_FOLDER does not exist: ${CHUNK_FOLDER}"
echo "Creating recording dir"
mkdir -p "${CHUNK_FOLDER}/in"
fi
}
check_folder
while true; do
record_chunk $AUDIO_DEVICE $RECORDING_DURATION
done
record_loop $AUDIO_DEVICE $RECORDING_DURATION

View File

@ -6,7 +6,8 @@ Description=BirdNET-stream Analyzis
[Service]
User=$USER
Group=$USER
ExecStart=/home/$USER/BirdNET-Analyzer/deamon/birdnet_analysis.sh
WorkingDirectory=$DIR
ExecStart=bash ./daemon/birdnet_analyzis.sh
Restart=always
RestartSec=3
Type=simple

View File

@ -4,9 +4,10 @@
Description=BirdNET-stream recording
[Service]
User=1000
Group=1000
ExecStart="bash /home/$USER/BirdNET-stream/daemon/birdnet_recording.sh"
User=$USER
Group=$DIR
WorkingDirectory=$DIR
ExecStart=bash ./daemon/birdnet_recording.sh"
Restart=always
RestartSec=3
Type=simple

View File

@ -1,5 +1,5 @@
#! /usr/bin/env bash
set -X
# set -x
set -e
DEBUG=${DEBUG:-0}
@ -23,7 +23,6 @@ debug() {
}
install_requirements() {
if
requirements=$1
# Install requirements
missing_requirements=""
@ -40,6 +39,12 @@ install_requirements() {
# Install BirdNET-stream
install_birdnetstream() {
# Check if repo is not already installed
workdir=$(pwd)
if [ -d "$workdir/BirdNET-stream" ]; then
debug "BirdNET-stream is already installed"
return
fi
# Clone BirdNET-stream
debug "Cloning BirdNET-stream from $REPOSITORY"
git clone --recurse-submodules $REPOSITORY
@ -56,14 +61,44 @@ install_birdnetstream() {
# Install systemd services
install_birdnetstream_services() {
cd BirdNET-stream
DIR=$(pwd)
GROUP=$USER
echo $DIR
debug "Setting up BirdNET stream systemd services"
sudo ln -s $PWD/BirdNET-stream/daemon/systemd/birdnet_recording.service /etc/systemd/system/birdnet_recording.service
sudo ln -s $PWD/BirdNET-stream/daemon/systemd/birdnet_analyzis.service /etc/systemd/system/birdnet_analyzis.service
services="birdnet_recording.service birdnet_analyzis.service"
for service in $services; do
sudo cp daemon/systemd/templates/$service /etc/systemd/system/
variables="DIR USER GROUP"
for variable in $variables; do
sudo sed -i "s|\$$variable|${!variable}|g" /etc/systemd/system/$service
done
done
sudo systemctl daemon-reload
sudo systemctl enable --now birdnet_recording.service birdnet_analyzis.service
sudo systemctl enable --now $services
}
install_web_interface() {
debug "Setting up web interface"
install_requirements "nginx php php-fpm composer nodejs npm"
cd BirdNET-stream
cd www
debug "Creating nginx configuration"
cp nginx.conf /etc/nginx/sites-available/birdnet-stream.conf
sudo ln -s /etc/nginx/sites-available/birdnet-stream.conf /etc/nginx/sites-enabled/birdnet-stream.conf
sudo systemctl enable --now nginx
sudo systemctl restart nginx
debug "Retrieving composer dependencies"
composer install
debug "Installing nodejs dependencies"
sudo npm install -g yarn
yarn build
debug "Building assets"
debug "Web interface is available"
}
main() {
# update
install_requirements $REQUIREMENTS
install_birdnetstream
install_birdnetstream_services

21
www/nginx.conf Normal file
View File

@ -0,0 +1,21 @@
server {
listen 80;
server_name birdnet.example.com;
root /var/www/html;
access_log /var/log/nginx/birdnet/birdnet-access.log;
error_log /var/log/nginx/birdnet/birdnet-error.log error;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}