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 .env
species_list.txt 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: On debian based system, you can install BirdNET-stream with the following command:
```bash ```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. 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)" junk="$junk $(find ${CHUNK_FOLDER}/out -type d -empty)"
# Get all empty record directories # Get all empty record directories
treatement_folder=$(find "${CHUNK_FOLDER}/out" -type d ! -empty) treatement_folder=$(find "${CHUNK_FOLDER}/out" -type d ! -empty)
for folder in $treatement_folder; do if [[ ! -z ${treatement_folder} ]]; then
if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then for folder in $treatement_folder; do
junk="$junk $folder" echo $folder
fi if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then
done junk="$junk $folder"
fi
done
fi
echo "$junk" echo "$junk"
} }

View File

@ -1,9 +1,38 @@
#! /usr/bin/env bash #! /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 DEVICE=$1
DURATION=$2 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" config_filepath="./config/analyzer.conf"
@ -15,6 +44,8 @@ else
exit 1 exit 1
fi fi
check_folder
[ -z $RECORDING_DURATION ] && RECORDING_DURATION=15 [ -z $RECORDING_DURATION ] && RECORDING_DURATION=15
if [[ -z $AUDIO_DEVICE ]]; then if [[ -z $AUDIO_DEVICE ]]; then
@ -22,16 +53,4 @@ if [[ -z $AUDIO_DEVICE ]]; then
exit 1 exit 1
fi fi
check_folder() { record_loop $AUDIO_DEVICE $RECORDING_DURATION
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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
#! /usr/bin/env bash #! /usr/bin/env bash
set -X # set -x
set -e set -e
DEBUG=${DEBUG:-0} DEBUG=${DEBUG:-0}
@ -23,7 +23,6 @@ debug() {
} }
install_requirements() { install_requirements() {
if
requirements=$1 requirements=$1
# Install requirements # Install requirements
missing_requirements="" missing_requirements=""
@ -40,6 +39,12 @@ install_requirements() {
# Install BirdNET-stream # Install BirdNET-stream
install_birdnetstream() { 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 # Clone BirdNET-stream
debug "Cloning BirdNET-stream from $REPOSITORY" debug "Cloning BirdNET-stream from $REPOSITORY"
git clone --recurse-submodules $REPOSITORY git clone --recurse-submodules $REPOSITORY
@ -56,14 +61,44 @@ install_birdnetstream() {
# Install systemd services # Install systemd services
install_birdnetstream_services() { install_birdnetstream_services() {
cd BirdNET-stream
DIR=$(pwd)
GROUP=$USER
echo $DIR
debug "Setting up BirdNET stream systemd services" debug "Setting up BirdNET stream systemd services"
sudo ln -s $PWD/BirdNET-stream/daemon/systemd/birdnet_recording.service /etc/systemd/system/birdnet_recording.service services="birdnet_recording.service birdnet_analyzis.service"
sudo ln -s $PWD/BirdNET-stream/daemon/systemd/birdnet_analyzis.service /etc/systemd/system/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 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() { main() {
# update
install_requirements $REQUIREMENTS install_requirements $REQUIREMENTS
install_birdnetstream install_birdnetstream
install_birdnetstream_services 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;
}
}