diff --git a/README.md b/README.md index e8bb1a7..bb225d3 100644 --- a/README.md +++ b/README.md @@ -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.* ## How to install -#### Option 1 (Recommended) -- Install All Services -1. In the terminal run: `curl -s https://raw.githubusercontent.com/mcguirepr89/BirdNET-Lite/rpi4/Birders_Guide_Installer.sh | bash` +Install All Services +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 If you configured BirdNET-Lite with the Caddy webserver, you can access the extractions locally at diff --git a/scripts/birdnet_analysis.sh b/scripts/birdnet_analysis.sh index a4c7ccb..72a8a37 100755 --- a/scripts/birdnet_analysis.sh +++ b/scripts/birdnet_analysis.sh @@ -74,23 +74,38 @@ run_analysis() { WEEK="$(echo "${WEEK_OF_YEAR} + 4" |bc -l)" fi - #WEEK=$(date +"%U") cd ${HOME}/BirdNET-Lite || exit 1 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 [ ${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 - [ "${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 - [ "${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 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 \ --i "${1}/${i}" \ --o "${1}/${i}.csv" \ @@ -100,9 +115,17 @@ run_analysis() { --overlap "${OVERLAP}" \ --sensitivity "${SENSITIVITY}" \ --min_conf "${CONFIDENCE}" - set +x 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 \ --i "${1}/${i}" \ --o "${1}/${i}.csv" \ @@ -113,7 +136,6 @@ run_analysis() { --sensitivity "${SENSITIVITY}" \ --min_conf "${CONFIDENCE}" \ --custom_list "${CUSTOM_LIST}" - set +x fi done } @@ -122,7 +144,7 @@ run_analysis() { # Takes one argument: # - {DIRECTORY} run_birdnet() { - echo "Starting run_birdnet() for \"${1:19}\"" + echo "Starting run_birdnet() for ${1:19}" get_files "${1}" move_analyzed "${1}" run_analysis "${1}" diff --git a/scripts/index.html b/scripts/index.html new file mode 100644 index 0000000..0e158b2 --- /dev/null +++ b/scripts/index.html @@ -0,0 +1,24 @@ +
+ + + + + + + + + + + diff --git a/scripts/install_services.sh b/scripts/install_services.sh index 0a3365d..e4d8ffb 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -12,6 +12,7 @@ CONFIG_FILE="$(dirname ${my_dir})/birdnet.conf" install_scripts() { echo "Installing BirdNET-Lite scripts to /usr/local/bin" ln -sf ${my_dir}/* /usr/local/bin/ + rm /usr/local/bin/index.html } 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_Scientific_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Scientific_Name [ -d ${PROCESSED} ] || sudo -u ${USER} mkdir -p ${PROCESSED} + [ -L ${EXTRACTED}/scripts ] || sudo -u ${USER} ln -s $(dirname ${my_dir})/scripts ${EXTRACTED} } install_alsa() { @@ -198,6 +200,7 @@ ${EXTRACTIONS_URL} { birdnet ${HASHWORD} } reverse_proxy /stream localhost:8000 + php_fastcgi unix//run/php/php7.3-fpm.sock } http://birdnetsystem.local { @@ -210,6 +213,7 @@ http://birdnetsystem.local { birdnet ${HASHWORD} } reverse_proxy /stream localhost:8000 + php_fastcgi unix//run/php/php7.3-fpm.sock } http://birdlog.local { @@ -315,6 +319,23 @@ EOF 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() { if ! which icecast2;then @@ -422,6 +443,7 @@ install_selected_services() { install_Caddyfile install_avahi_aliases install_gotty_logs + install_php fi if [ ! -z "${ICE_PWD}" ];then diff --git a/scripts/reboot_system.php b/scripts/reboot_system.php new file mode 100644 index 0000000..2e385ad --- /dev/null +++ b/scripts/reboot_system.php @@ -0,0 +1,4 @@ + diff --git a/scripts/reboot_system.sh b/scripts/reboot_system.sh new file mode 100755 index 0000000..e45727e --- /dev/null +++ b/scripts/reboot_system.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sudo reboot diff --git a/scripts/restart_birdnet.sh b/scripts/restart_birdnet.sh index de456c2..e42cf34 100755 --- a/scripts/restart_birdnet.sh +++ b/scripts/restart_birdnet.sh @@ -1,9 +1,23 @@ #!/usr/bin/env bash -# Restart services +# Restarts ALL services and removes ALL unprocessed audio source /etc/birdnet/birdnet.conf 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 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 + diff --git a/scripts/restart_birdnet_analysis.php b/scripts/restart_birdnet_analysis.php new file mode 100644 index 0000000..2c050a1 --- /dev/null +++ b/scripts/restart_birdnet_analysis.php @@ -0,0 +1,4 @@ + diff --git a/scripts/restart_birdnet_analysis.sh b/scripts/restart_birdnet_analysis.sh new file mode 100755 index 0000000..c40b3e8 --- /dev/null +++ b/scripts/restart_birdnet_analysis.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Restars the main BirdNET analysis service +sudo systemctl restart birdnet_analysis.service diff --git a/scripts/restart_birdnet_recording.php b/scripts/restart_birdnet_recording.php new file mode 100644 index 0000000..9c61cd4 --- /dev/null +++ b/scripts/restart_birdnet_recording.php @@ -0,0 +1,4 @@ + diff --git a/scripts/restart_birdnet_recording.sh b/scripts/restart_birdnet_recording.sh new file mode 100755 index 0000000..bc9f5b8 --- /dev/null +++ b/scripts/restart_birdnet_recording.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Restars the BirdNET Recording service +sudo systemctl restart birdnet_recording.service diff --git a/scripts/restart_caddy.php b/scripts/restart_caddy.php new file mode 100644 index 0000000..3de0dd9 --- /dev/null +++ b/scripts/restart_caddy.php @@ -0,0 +1,4 @@ + diff --git a/scripts/restart_caddy.sh b/scripts/restart_caddy.sh new file mode 100755 index 0000000..43edcca --- /dev/null +++ b/scripts/restart_caddy.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Restars the caddy webserver +sudo systemctl restart caddy diff --git a/scripts/restart_extraction.php b/scripts/restart_extraction.php new file mode 100644 index 0000000..f847580 --- /dev/null +++ b/scripts/restart_extraction.php @@ -0,0 +1,4 @@ + diff --git a/scripts/restart_extraction.sh b/scripts/restart_extraction.sh new file mode 100755 index 0000000..81aadf0 --- /dev/null +++ b/scripts/restart_extraction.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Restars the BirdNET Extraction service +sudo systemctl restart extraction.service diff --git a/scripts/restart_services.php b/scripts/restart_services.php new file mode 100644 index 0000000..f6be0aa --- /dev/null +++ b/scripts/restart_services.php @@ -0,0 +1,4 @@ + diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 4fe4ee0..c8f2f53 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -3,26 +3,37 @@ # set -x # Uncomment to debug trap 'rm -f ${TMPFILE}' EXIT source /etc/birdnet/birdnet.conf &> /dev/null -SCRIPTS=(/usr/local/bin/birdnet_analysis.sh -/usr/local/bin/birdnet_recording.sh -/usr/local/bin/birdnet_stats.sh -/usr/local/bin/cleanup.sh -/usr/local/bin/clear_all_data.sh -/usr/local/bin/disk_usage.sh -/usr/local/bin/dump_logs.sh -/usr/local/bin/extract_new_birdsounds.sh -/usr/local/bin/install_birdnet.sh -/usr/local/bin/install_config.sh -/usr/local/bin/install_services.sh -/usr/local/bin/install_tmux_services.sh -/usr/local/bin/install_zram_service.sh -/usr/local/bin/livestream.sh -/usr/local/bin/pretty_date.sh -/usr/local/bin/reconfigure_birdnet.sh -/usr/local/bin/restart_birdnet.sh -/usr/local/bin/species_notifier.sh -/usr/local/bin/uninstall.sh -/usr/local/bin/update_species.sh +SCRIPTS=(birdnet_analysis.sh +birdnet_recording.sh +birdnet_stats.sh +cleanup.sh +clear_all_data.sh +disk_usage.sh +dump_logs.sh +extract_new_birdsounds.sh +install_birdnet.sh +install_config.sh +install_services.sh +install_tmux_services.sh +install_zram_service.sh +livestream.sh +pretty_date.sh +reboot_system.php +reboot_system.sh +reconfigure_birdnet.sh +restart_birdnet_analysis.php +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) diff --git a/templates/index.html b/templates/index.html index bd3d304..c7fae41 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,7 +1,7 @@ -