From 88e4553b945926fafb067442e161450edd27a5cc Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Sat, 2 Oct 2021 18:07:15 -0400 Subject: [PATCH] added birdnet.conf changes check -- needs more testing, but seems to work well --- Birders_Guide_Installer.sh | 2 ++ birdnet.conf-defaults | 2 ++ scripts/birdnet_analysis.sh | 22 +++++++++++++++++++++- scripts/extract_new_birdsounds.sh | 1 - scripts/install_config.sh | 4 +++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Birders_Guide_Installer.sh b/Birders_Guide_Installer.sh index 4406ee2..44065a0 100755 --- a/Birders_Guide_Installer.sh +++ b/Birders_Guide_Installer.sh @@ -415,6 +415,8 @@ RECORDING_LENGTH= EXTRACTION_LENGTH= +LAST_RUN= +THIS_RUN= EOF [ -d /etc/birdnet ] || sudo mkdir /etc/birdnet sudo ln -sf ${my_dir}/birdnet.conf /etc/birdnet/birdnet.conf diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults index ea0e8ee..569b557 100644 --- a/birdnet.conf-defaults +++ b/birdnet.conf-defaults @@ -251,3 +251,5 @@ VENV=$(dirname ${my_dir})/miniforge/envs/birdnet RECORDING_LENGTH= EXTRACTION_LENGTH= + +LAST_RUN= diff --git a/scripts/birdnet_analysis.sh b/scripts/birdnet_analysis.sh index f3e9dd5..a4c7ccb 100755 --- a/scripts/birdnet_analysis.sh +++ b/scripts/birdnet_analysis.sh @@ -2,6 +2,25 @@ # Runs BirdNET-Lite #set -x source /etc/birdnet/birdnet.conf +# Document this run's birdnet.conf settings +# Make a temporary file to compare the current birdnet.conf with +# the birdnet.conf as it was the last time this script was called +make_thisrun() { + sleep .4 + awk '!/#/ && !/^$/ {print}' /etc/birdnet/birdnet.conf \ + > >(tee "${THIS_RUN}") + sleep .5 +} +make_thisrun &> /dev/null +if ! diff ${LAST_RUN} ${THIS_RUN};then + echo "The birdnet.conf file has changed" + echo "Reloading services" + cat ${THIS_RUN} > ${LAST_RUN} + until restart_birdnet.sh;do + sleep 1 + done +fi + CUSTOM_LIST="/home/pi/BirdNET-Lite/custom_species_list.txt" # Create an array of the audio files @@ -38,6 +57,7 @@ move_analyzed() { # Uses one argument: # - {DIRECTORY} run_analysis() { + sleep .5 echo "Starting run_analysis() for ${1:19}" @@ -58,7 +78,6 @@ run_analysis() { cd ${HOME}/BirdNET-Lite || exit 1 for i in "${files[@]}";do - set -x FILE_LENGTH="$(ffmpeg -i ${1}/${i} 2>&1 \ | awk -F. '/Duration/ {print $1}' \ | cut -d':' -f3-4)" @@ -71,6 +90,7 @@ run_analysis() { fi if [ -f ${1}/${i} ] && [ ! -f ${CUSTOM_LIST} ];then + set -x python3 analyze.py \ --i "${1}/${i}" \ --o "${1}/${i}.csv" \ diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh index f0b133b..798f07d 100755 --- a/scripts/extract_new_birdsounds.sh +++ b/scripts/extract_new_birdsounds.sh @@ -8,7 +8,6 @@ trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG trap 'echo "\"${last_command}\" command exited with code $?."' EXIT # Remove temporary file trap 'rm -f $TMPFILE' EXIT - source /etc/birdnet/birdnet.conf # Set Variables diff --git a/scripts/install_config.sh b/scripts/install_config.sh index eb24fe7..c1402b7 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -368,7 +368,7 @@ INSTALL_NOMACHINE=${INSTALL_NOMACHINE} ## devices from the output of running 'aplay -L' REC_CARD=${REC_CARD} - + ## PROCESSED is the directory where the formerly 'Analyzed' files are moved ## after extractions have been made from them. This includes both WAVE and ## BirdNET.selection.txt files. @@ -437,6 +437,8 @@ RECORDING_LENGTH= EXTRACTION_LENGTH= +LAST_RUN=$(dirname ${my_dir})/lastrun.txt +THIS_RUN=$(dirname ${my_dir})/thisrun.txt EOF [ -d /etc/birdnet ] || sudo mkdir /etc/birdnet sudo ln -sf $(dirname ${my_dir})/birdnet.conf /etc/birdnet/birdnet.conf