Merge pull request #4 from mcguirepr89/rpialpha

Rpialpha
This commit is contained in:
mcguirepr89
2021-10-03 19:39:59 -04:00
committed by GitHub
18 changed files with 189 additions and 61 deletions
+2 -17
View File
@@ -52,24 +52,9 @@ An installation one-liner is available below for RaspiOS-ARM64 meeting the prequ
- *Note for Android users: it seems that the Pushed.co Mobile App does not work for Android devices, which is a huge bummer. If anyone knows of an Android alternative, or if anyone might be able to come up with a home-spun notification system, please let me know.* - *Note for Android users: it seems that the Pushed.co Mobile App does not work for Android devices, which is a huge bummer. If anyone knows of an Android alternative, or if anyone might be able to come up with a home-spun notification system, please let me know.*
## How to install ## How to install
#### Option 1 (Recommended) -- Install All Services Install All Services
1. In the terminal run: `curl -s https://raw.githubusercontent.com/mcguirepr89/BirdNET-Lite/rpi4/Birders_Guide_Installer.sh | bash` 1. In the terminal run: `curl -s https://raw.githubusercontent.com/mcguirepr89/BirdNET-Lite/rpialpha/Birders_Guide_Installer.sh | bash`
##### Options 2 & 3 require you setup 4GB of swapping. That step is included in the directions below.
#### Option 2 -- Pre-fill birdnet.conf
1. In the terminal run `git clone https://github.com/mcguirepr89/BirdNET-Lite.git ~/BirdNET-Lite`
1. You can copy the included *'birdnet.conf-defaults'* template to create and configure the BirdNET-Lite
to your needs before running the installer. Issue `cp ~/BirdNET-Lite/birdnet.conf-defaults ~/BirdNET-Lite/birdnet.conf`.
Edit the new *'birdnet.conf'* file to suit your needs and save it.
If you choose this method, the installation will be (nearly) non-interactive.
1. Setup zRAM swapping. Run `~/BirdNET-Lite/scripts/install_zram_service.sh && sudo reboot`
1. After the reboot, run `~/BirdNET-Lite/scripts/install_birdnet.sh`
#### Option 3 -- Interactive Installation
1. In the terminal run `git clone https://github.com/mcguirepr89/BirdNET-Lite.git ~/BirdNET-Lite`
1. Setup zRAM swapping. Run `~/BirdNET-Lite/scripts/install_zram_service.sh && sudo reboot`
1. After the reboot, run `~/BirdNET-Lite/scripts/install_birdnet.sh`
1. Follow the installation prompts to configure the BirdNET-Lite to your needs.
- Note: The installation should be run as a regular user. If run on an OS other than RaspiOS, be sure the regular user is in the sudoers file or the sudo group.
## Access your BirdNET-Lite ## Access your BirdNET-Lite
If you configured BirdNET-Lite with the Caddy webserver, you can access the extractions locally at If you configured BirdNET-Lite with the Caddy webserver, you can access the extractions locally at
+34 -12
View File
@@ -74,23 +74,38 @@ run_analysis() {
WEEK="$(echo "${WEEK_OF_YEAR} + 4" |bc -l)" WEEK="$(echo "${WEEK_OF_YEAR} + 4" |bc -l)"
fi fi
#WEEK=$(date +"%U")
cd ${HOME}/BirdNET-Lite || exit 1 cd ${HOME}/BirdNET-Lite || exit 1
for i in "${files[@]}";do for i in "${files[@]}";do
FILE_LENGTH="$(ffmpeg -i ${1}/${i} 2>&1 \
| awk -F. '/Duration/ {print $1}' \
| cut -d':' -f3-4)"
[ -z ${RECORDING_LENGTH} ] && RECORDING_LENGTH=12 [ -z ${RECORDING_LENGTH} ] && RECORDING_LENGTH=12
[ ${RECORDING_LENGTH} == "60" ] && RECORDING_LENGTH=01:00 [ ${RECORDING_LENGTH} == "60" ] && RECORDING_LENGTH=01:00
FILE_LENGTH="$(ffmpeg -i ${1}/${i} 2>&1 | awk -F. '/Duration/ {print $1}' | cut -d':' -f3-4)"
[ -z $FILE_LENGTH ] && sleep 3 && continue
echo "RECORDING_LENGTH set to ${RECORDING_LENGTH}"
a=1
if [ ${RECORDING_LENGTH} == "01:00" ];then if [ ${RECORDING_LENGTH} == "01:00" ];then
[ "${FILE_LENGTH}" == "${RECORDING_LENGTH}" ] || continue until [ "$(ffmpeg -i ${1}/${i} 2>&1 | awk -F. '/Duration/ {print $1}' | cut -d':' -f3-4)" == "${RECORDING_LENGTH}" ];do
sleep 1
[ $a -ge ${RECORDING_LENGTH} ] && sudo rm -f ${1}/${i} && break
a=$((a+1))
done
else else
[ "${FILE_LENGTH}" == "00:${RECORDING_LENGTH}" ] || continue until [ "$(ffmpeg -i ${1}/${i} 2>&1 | awk -F. '/Duration/ {print $1}' | cut -d':' -f3-4)" == "00:${RECORDING_LENGTH}" ];do
sleep 1
[ $a -ge ${RECORDING_LENGTH} ] && sudo rm -f ${1}/${i} && break
a=$((a+1))
done
fi fi
if [ -f ${1}/${i} ] && [ ! -f ${CUSTOM_LIST} ];then if [ -f ${1}/${i} ] && [ ! -f ${CUSTOM_LIST} ];then
set -x echo "python3 analyze.py \
--i "${1}/${i}" \
--o "${1}/${i}.csv" \
--lat "${LATITUDE}" \
--lon "${LONGITUDE}" \
--week "${WEEK}" \
--overlap "${OVERLAP}" \
--sensitivity "${SENSITIVITY}" \
--min_conf "${CONFIDENCE}""
python3 analyze.py \ python3 analyze.py \
--i "${1}/${i}" \ --i "${1}/${i}" \
--o "${1}/${i}.csv" \ --o "${1}/${i}.csv" \
@@ -100,9 +115,17 @@ run_analysis() {
--overlap "${OVERLAP}" \ --overlap "${OVERLAP}" \
--sensitivity "${SENSITIVITY}" \ --sensitivity "${SENSITIVITY}" \
--min_conf "${CONFIDENCE}" --min_conf "${CONFIDENCE}"
set +x
elif [ -f ${1}/${i} ] && [ -f ${CUSTOM_LIST} ];then elif [ -f ${1}/${i} ] && [ -f ${CUSTOM_LIST} ];then
set -x echo "python3 analyze.py \
--i "${1}/${i}" \
--o "${1}/${i}.csv" \
--lat "${LATITUDE}" \
--lon "${LONGITUDE}" \
--week "${WEEK}" \
--overlap "${OVERLAP}" \
--sensitivity "${SENSITIVITY}" \
--min_conf "${CONFIDENCE}" \
--custom_list "${CUSTOM_LIST}""
python3 analyze.py \ python3 analyze.py \
--i "${1}/${i}" \ --i "${1}/${i}" \
--o "${1}/${i}.csv" \ --o "${1}/${i}.csv" \
@@ -113,7 +136,6 @@ run_analysis() {
--sensitivity "${SENSITIVITY}" \ --sensitivity "${SENSITIVITY}" \
--min_conf "${CONFIDENCE}" \ --min_conf "${CONFIDENCE}" \
--custom_list "${CUSTOM_LIST}" --custom_list "${CUSTOM_LIST}"
set +x
fi fi
done done
} }
@@ -122,7 +144,7 @@ run_analysis() {
# Takes one argument: # Takes one argument:
# - {DIRECTORY} # - {DIRECTORY}
run_birdnet() { run_birdnet() {
echo "Starting run_birdnet() for \"${1:19}\"" echo "Starting run_birdnet() for ${1:19}"
get_files "${1}" get_files "${1}"
move_analyzed "${1}" move_analyzed "${1}"
run_analysis "${1}" run_analysis "${1}"
+24
View File
@@ -0,0 +1,24 @@
<form action="/scripts/restart_services.php">
<input type="submit" value="Restart ALL BirdNET-system Services">
</form>
<form action="/scripts/restart_birdnet_analysis.php">
<input type="submit" value="Restart BirdNET Analysis Service">
</form>
<form action="/scripts/restart_birdnet_recording.php">
<input type="submit" value="Restart Recording Service">
</form>
<form action="/scripts/restart_extraction.php">
<input type="submit" value="Restart Extraction Service">
</form>
<form action="/scripts/restart_caddy.php">
<input type="submit" value="Restart Caddy">
</form>
<form action="/scripts/reboot_system.php">
<input type="submit" value="Reboot BirdNET-system">
</form>
+22
View File
@@ -12,6 +12,7 @@ CONFIG_FILE="$(dirname ${my_dir})/birdnet.conf"
install_scripts() { install_scripts() {
echo "Installing BirdNET-Lite scripts to /usr/local/bin" echo "Installing BirdNET-Lite scripts to /usr/local/bin"
ln -sf ${my_dir}/* /usr/local/bin/ ln -sf ${my_dir}/* /usr/local/bin/
rm /usr/local/bin/index.html
} }
install_birdnet_analysis() { install_birdnet_analysis() {
@@ -77,6 +78,7 @@ create_necessary_dirs() {
[ -d ${EXTRACTED}/By_Common_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Common_Name [ -d ${EXTRACTED}/By_Common_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Common_Name
[ -d ${EXTRACTED}/By_Scientific_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Scientific_Name [ -d ${EXTRACTED}/By_Scientific_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Scientific_Name
[ -d ${PROCESSED} ] || sudo -u ${USER} mkdir -p ${PROCESSED} [ -d ${PROCESSED} ] || sudo -u ${USER} mkdir -p ${PROCESSED}
[ -L ${EXTRACTED}/scripts ] || sudo -u ${USER} ln -s $(dirname ${my_dir})/scripts ${EXTRACTED}
} }
install_alsa() { install_alsa() {
@@ -198,6 +200,7 @@ ${EXTRACTIONS_URL} {
birdnet ${HASHWORD} birdnet ${HASHWORD}
} }
reverse_proxy /stream localhost:8000 reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.3-fpm.sock
} }
http://birdnetsystem.local { http://birdnetsystem.local {
@@ -210,6 +213,7 @@ http://birdnetsystem.local {
birdnet ${HASHWORD} birdnet ${HASHWORD}
} }
reverse_proxy /stream localhost:8000 reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.3-fpm.sock
} }
http://birdlog.local { http://birdlog.local {
@@ -315,6 +319,23 @@ EOF
systemctl enable --now birdstats.service systemctl enable --now birdstats.service
} }
install_php() {
if ! which pip &> /dev/null || ! which php-fpm7.3;then
echo "Installing PHP and PHP-FPM"
apt -qq update
apt install -qqy php php-fpm
else
echo "PHP and PHP-FPM installed"
fi
echo "Configuring PHP for Caddy"
sed -i 's/www-data/caddy/g' /etc/php/7.3/fpm/pool.d/www.conf
systemctl restart php7.3-fpm.service
echo "Adding Caddy sudoers rule"
cat << EOF > /etc/sudoers.d/010_caddy-nopasswd
caddy ALL=(ALL) NOPASSWD: ALL
EOF
chmod 0440 /etc/sudoers.d/010_caddy-nopasswd
}
install_icecast() { install_icecast() {
if ! which icecast2;then if ! which icecast2;then
@@ -422,6 +443,7 @@ install_selected_services() {
install_Caddyfile install_Caddyfile
install_avahi_aliases install_avahi_aliases
install_gotty_logs install_gotty_logs
install_php
fi fi
if [ ! -z "${ICE_PWD}" ];then if [ ! -z "${ICE_PWD}" ];then
+4
View File
@@ -0,0 +1,4 @@
<?php
shell_exec("/home/pi/BirdNET-Lite/scripts/reboot_system.sh");
header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
?>
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sudo reboot
+18 -4
View File
@@ -1,9 +1,23 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Restart services # Restarts ALL services and removes ALL unprocessed audio
source /etc/birdnet/birdnet.conf source /etc/birdnet/birdnet.conf
sudo systemctl stop birdnet_recording.service sudo systemctl stop birdnet_recording.service
rm -rf ${RECS_DIR}/$(date +%B-%Y/%d-%A)/* sudo rm -rf ${RECS_DIR}/$(date +%B-%Y/%d-%A)/*
sudo systemctl start birdnet_recording.service sudo systemctl start birdnet_recording.service
sudo systemctl restart extraction.timer
sudo systemctl restart birdnet_analysis.service SERVICES=(avahi-alias@birdlog.local.service
avahi-alias@birdnetsystem.local.service
avahi-alias@birdstats.local.service
avahi-alias@extractionlog.local.service
birdnet_analysis.service
birdnet_log.service
birdstats.service
extraction.timer
extractionlog.service
livestream.service)
for i in "${SERVICES[@]}";do
sudo systemctl restart ${i}
done
+4
View File
@@ -0,0 +1,4 @@
<?php
shell_exec("/home/pi/BirdNET-Lite/scripts/restart_birdnet_analysis.sh");
header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
?>
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# Restars the main BirdNET analysis service
sudo systemctl restart birdnet_analysis.service
+4
View File
@@ -0,0 +1,4 @@
<?php
shell_exec("/home/pi/BirdNET-Lite/scripts/restart_birdnet_recording.sh");
header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
?>
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# Restars the BirdNET Recording service
sudo systemctl restart birdnet_recording.service
+4
View File
@@ -0,0 +1,4 @@
<?php
shell_exec("/home/pi/BirdNET-Lite/scripts/restart_caddy.sh");
header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
?>
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# Restars the caddy webserver
sudo systemctl restart caddy
+4
View File
@@ -0,0 +1,4 @@
<?php
shell_exec("/home/pi/BirdNET-Lite/scripts/restart_extraction.sh");
header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
?>
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# Restars the BirdNET Extraction service
sudo systemctl restart extraction.service
+4
View File
@@ -0,0 +1,4 @@
<?php
shell_exec("/home/pi/BirdNET-Lite/scripts/restart_birdnet.sh");
header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
?>
+31 -20
View File
@@ -3,26 +3,37 @@
# set -x # Uncomment to debug # set -x # Uncomment to debug
trap 'rm -f ${TMPFILE}' EXIT trap 'rm -f ${TMPFILE}' EXIT
source /etc/birdnet/birdnet.conf &> /dev/null source /etc/birdnet/birdnet.conf &> /dev/null
SCRIPTS=(/usr/local/bin/birdnet_analysis.sh SCRIPTS=(birdnet_analysis.sh
/usr/local/bin/birdnet_recording.sh birdnet_recording.sh
/usr/local/bin/birdnet_stats.sh birdnet_stats.sh
/usr/local/bin/cleanup.sh cleanup.sh
/usr/local/bin/clear_all_data.sh clear_all_data.sh
/usr/local/bin/disk_usage.sh disk_usage.sh
/usr/local/bin/dump_logs.sh dump_logs.sh
/usr/local/bin/extract_new_birdsounds.sh extract_new_birdsounds.sh
/usr/local/bin/install_birdnet.sh install_birdnet.sh
/usr/local/bin/install_config.sh install_config.sh
/usr/local/bin/install_services.sh install_services.sh
/usr/local/bin/install_tmux_services.sh install_tmux_services.sh
/usr/local/bin/install_zram_service.sh install_zram_service.sh
/usr/local/bin/livestream.sh livestream.sh
/usr/local/bin/pretty_date.sh pretty_date.sh
/usr/local/bin/reconfigure_birdnet.sh reboot_system.php
/usr/local/bin/restart_birdnet.sh reboot_system.sh
/usr/local/bin/species_notifier.sh reconfigure_birdnet.sh
/usr/local/bin/uninstall.sh restart_birdnet_analysis.php
/usr/local/bin/update_species.sh restart_birdnet_analysis.sh
restart_birdnet_recording.php
restart_birdnet_recording.sh
restart_birdnet.sh
restart_caddy.php
restart_caddy.sh
restart_extraction.php
restart_extraction.sh
restart_services.php
species_notifier.sh
uninstall.sh
update_species.sh
${HOME}/.gotty) ${HOME}/.gotty)
+20 -8
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>BirdNET-Lite Extractions</title> <title>BirdNET-Lite System</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<style> <style>
@@ -308,13 +308,13 @@ footer {
<header> <header>
<h1> <h1>
<a href="">BirdNET-Lite Extractions</a> <a href="">BirdNET-Lite System</a>
</h1> </h1>
</header> </header>
<main> <main>
<div class="meta"> <div class="meta">
<div id="summary"> <div id="summary">
<span class="meta-item"><b>4</b> directories</span> <span class="meta-item"><b>5</b> directories</span>
<span class="meta-item"><b>1</b> file</span> <span class="meta-item"><b>1</b> file</span>
<span class="meta-item"><input type="text" placeholder="filter" id="filter" onkeyup='filter()'></span> <span class="meta-item"><input type="text" placeholder="filter" id="filter" onkeyup='filter()'></span>
</div> </div>
@@ -347,7 +347,7 @@ footer {
</a> </a>
</td> </td>
<td data-order="-1">&mdash;</td> <td data-order="-1">&mdash;</td>
<td class="hideable"><time datetime="2021-09-28T23:31:31Z">09/28/2021 11:31:31 PM +00:00</time></td> <td class="hideable"><time datetime="2021-10-03T23:13:48Z">10/03/2021 11:13:48 PM +00:00</time></td>
<td class="hideable"></td> <td class="hideable"></td>
</tr> </tr>
<tr class="file"> <tr class="file">
@@ -359,7 +359,7 @@ footer {
</a> </a>
</td> </td>
<td data-order="-1">&mdash;</td> <td data-order="-1">&mdash;</td>
<td class="hideable"><time datetime="2021-09-28T23:31:31Z">09/28/2021 11:31:31 PM +00:00</time></td> <td class="hideable"><time datetime="2021-10-03T23:13:48Z">10/03/2021 11:13:48 PM +00:00</time></td>
<td class="hideable"></td> <td class="hideable"></td>
</tr> </tr>
<tr class="file"> <tr class="file">
@@ -371,7 +371,7 @@ footer {
</a> </a>
</td> </td>
<td data-order="-1">&mdash;</td> <td data-order="-1">&mdash;</td>
<td class="hideable"><time datetime="2021-09-28T23:31:31Z">09/28/2021 11:31:31 PM +00:00</time></td> <td class="hideable"><time datetime="2021-10-03T23:13:48Z">10/03/2021 11:13:48 PM +00:00</time></td>
<td class="hideable"></td> <td class="hideable"></td>
</tr> </tr>
<tr class="file"> <tr class="file">
@@ -383,7 +383,19 @@ footer {
</a> </a>
</td> </td>
<td data-order="-1">&mdash;</td> <td data-order="-1">&mdash;</td>
<td class="hideable"><time datetime="2021-09-28T23:30:36Z">09/28/2021 11:30:36 PM +00:00</time></td> <td class="hideable"><time datetime="2021-10-03T23:23:16Z">10/03/2021 11:23:16 PM +00:00</time></td>
<td class="hideable"></td>
</tr>
<tr class="file">
<td></td>
<td>
<a href="./scripts/">
<svg width="1.5em" height="1em" version="1.1" viewBox="0 0 317 259"><use xlink:href="#folder-shortcut"></use></svg>
<span class="name">scripts</span>
</a>
</td>
<td data-order="-1">&mdash;</td>
<td class="hideable"><time datetime="2021-10-03T23:13:48Z">10/03/2021 11:13:48 PM +00:00</time></td>
<td class="hideable"></td> <td class="hideable"></td>
</tr> </tr>
<tr class="file"> <tr class="file">
@@ -395,7 +407,7 @@ footer {
</a> </a>
</td> </td>
<td data-order="0">0 B</td> <td data-order="0">0 B</td>
<td class="hideable"><time datetime="2021-09-28T23:28:21Z">09/28/2021 11:28:21 PM +00:00</time></td> <td class="hideable"><time datetime="2021-10-03T23:29:52Z">10/03/2021 11:29:52 PM +00:00</time></td>
<td class="hideable"></td> <td class="hideable"></td>
</tr> </tr>
</tbody> </tbody>