Fix install sed and systemd services,working on bullseye test
This commit is contained in:
parent
601b402db5
commit
29dcd4c999
|
@ -5,3 +5,5 @@ var/
|
||||||
.env
|
.env
|
||||||
|
|
||||||
species_list.txt
|
species_list.txt
|
||||||
|
|
||||||
|
push.sh
|
|
@ -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.
|
||||||
|
|
|
@ -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)
|
||||||
|
if [[ ! -z ${treatement_folder} ]]; then
|
||||||
for folder in $treatement_folder; do
|
for folder in $treatement_folder; do
|
||||||
|
echo $folder
|
||||||
if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then
|
if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then
|
||||||
junk="$junk $folder"
|
junk="$junk $folder"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
echo "$junk"
|
echo "$junk"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
@ -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
|
45
install.sh
45
install.sh
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue