From 786348d815a897355eaf7d3780588da7010877a7 Mon Sep 17 00:00:00 2001 From: dalogue1 <133064876+dalogue1@users.noreply.github.com> Date: Wed, 24 Sep 2025 13:06:48 -0500 Subject: [PATCH] Automatic Update Feature (#424) * Update advanced.php Added a checkbox in the Advanced Settings page to enable Automatic Update * Update install_config.sh The AUTOMATIC_UPDATE parameter needs to be created in the BirdNET-Pi configuration file. * Update install_services.sh Add a cron job to the system to performa automatic updates. * Create automatic_update.cron The line to be added to the cron table to check for need to perform automatic update. * Create automatic_update.sh Script to perform the automatic update if the flag is set in the configuration. Also, the services are restarted after the update. * Update install_services.sh * Update automatic_update.sh * Update advanced.php Correct typo * Update update_birdnet_snippets.sh Add the automatic_update.cron to the list of cron jobs * Update update_birdnet_snippets.sh * Update automatic_update.cron Change automatic update to once a week on Sunday at 3AM * Update update_birdnet_snippets.sh Adjusted to add option to existing installations * Update automatic_update.sh Removed unnecessary call to restart_services.sh * Update advanced.php Cleaned up the Options section line spacing in the settings table * Update templates/automatic_update.cron Co-authored-by: Nachtzuster * Update scripts/update_birdnet_snippets.sh Co-authored-by: Nachtzuster * Delete scripts/automatic_update.sh * Update advanced.php Modified the description of the Automatic Update feature on the Advanced Configuration tab. * Update install_config.sh --------- Co-authored-by: Nachtzuster --- scripts/advanced.php | 28 ++++++++++++++++++++++------ scripts/install_config.sh | 6 ++++++ scripts/install_services.sh | 5 +++++ scripts/update_birdnet_snippets.sh | 7 ++++++- templates/automatic_update.cron | 2 ++ 5 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 templates/automatic_update.cron diff --git a/scripts/advanced.php b/scripts/advanced.php index dab6339..48ac7bc 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -203,6 +203,15 @@ if (isset($_GET["max_files_species"])) { $contents = preg_replace("/SILENCE_UPDATE_INDICATOR=.*/", "SILENCE_UPDATE_INDICATOR=0", $contents); } + if(isset($_GET["automatic_update"])) { + $automatic_update = 1; + if(strcmp($automatic_update,$config['AUTOMATIC_UPDATE']) !== 0) { + $contents = preg_replace("/AUTOMATIC_UPDATE=.*/", "AUTOMATIC_UPDATE=$automatic_update", $contents); + } + } else { + $contents = preg_replace("/AUTOMATIC_UPDATE=.*/", "AUTOMATIC_UPDATE=0", $contents); + } + if(isset($_GET["raw_spectrogram"])) { $raw_spectrogram = 1; if(strcmp($RAW_SPECTROGRAM,$config['RAW_SPECTROGRAM']) !== 0) { @@ -454,19 +463,26 @@ foreach($formats as $format){

The BirdNET-Pi URL is how the main page will be reached. If you want your installation to respond to an IP address, place that here, but be sure to indicate "http://".
Example for IP: http://192.168.0.109
Example if you own your own domain: https://virginia.birdnetpi.com


+

Options

+ - >
-

This allows you to quiet the display of how many commits your installation is behind by relative to the Github repo. This number appears next to "Tools" when you're 50 or more commits behind.

- + > +

This allows you to quiet the display of how many commits your installation is behind by relative to the Github repo. This number appears next to "Tools" when you're 50 or more commits behind.


+ + + > +

This configures an automatic update of the installation each Sunday at 3:00 AM but the timing can be changed using crontab.


+ - >
-

This allows you to remove the axes and labels of the spectrograms that are generated by Sox for each detection for a cleaner appearance.

+ > +

This allows you to remove the axes and labels of the spectrograms that are generated by Sox for each detection for a cleaner appearance.


-
+

This setting defines after how many days since last detection a species is considered rare. Default is 30 days.

+

diff --git a/scripts/install_config.sh b/scripts/install_config.sh index 3c4a334..a80281a 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -265,6 +265,12 @@ HEARTBEAT_URL= SILENCE_UPDATE_INDICATOR=0 +## AUTOMATIC_UPDATE is for specifying that the installation is automatically +## updated from the Github repo. The update time is by default every Sunday at 3:00 AM +## but can be adjusted using crontab. + +AUTOMATIC_UPDATE=0 + ## RAW_SPECTROGRAM is for removing the axes and labels of the spectrograms ## that are generated by Sox for each detection for a cleaner appearance. diff --git a/scripts/install_services.sh b/scripts/install_services.sh index 458c568..38690a1 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -383,6 +383,10 @@ install_weekly_cron() { sed "s/\$USER/$USER/g" $my_dir/templates/weekly_report.cron >> /etc/crontab } +install_automatic_update_cron() { + sed "s/\$USER/$USER/g" $my_dir/templates/automatic_update.cron >> /etc/crontab +} + chown_things() { chown -R $USER:$USER $HOME/Bird* } @@ -418,6 +422,7 @@ install_services() { install_birdnet_mount install_cleanup_cron install_weekly_cron + install_automatic_update_cron increase_caddy_timeout create_necessary_dirs diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh index 937b888..a5878d3 100755 --- a/scripts/update_birdnet_snippets.sh +++ b/scripts/update_birdnet_snippets.sh @@ -114,6 +114,10 @@ if ! grep -E '^MAX_FILES_SPECIES=' /etc/birdnet/birdnet.conf &>/dev/null;then echo "MAX_FILES_SPECIES=\"0\"" >> /etc/birdnet/birdnet.conf fi +if ! grep -E '^AUTOMATIC_UPDATE=' /etc/birdnet/birdnet.conf &>/dev/null;then + echo "AUTOMATIC_UPDATE=0" >> /etc/birdnet/birdnet.conf +fi + if ! grep -E '^RARE_SPECIES_THRESHOLD=' /etc/birdnet/birdnet.conf &>/dev/null;then echo '## RARE_SPECIES_THRESHOLD defines after how many days a species is considered as rare and highlighted on overview page' >> /etc/birdnet/birdnet.conf echo "RARE_SPECIES_THRESHOLD=\"30\"" >> /etc/birdnet/birdnet.conf @@ -235,10 +239,11 @@ if [ -L /usr/local/bin/birdnet_analysis.sh ];then fi # Clean state and update cron if all scripts are not installed -if [ "$(grep -o "#birdnet" /etc/crontab | wc -l)" -lt 5 ]; then +if [ "$(grep -o "#birdnet" /etc/crontab | wc -l)" -lt 6 ]; then sudo sed -i '/birdnet/,+1d' /etc/crontab sed "s/\$USER/$USER/g" "$HOME"/BirdNET-Pi/templates/cleanup.cron >> /etc/crontab sed "s/\$USER/$USER/g" "$HOME"/BirdNET-Pi/templates/weekly_report.cron >> /etc/crontab + sed "s/\$USER/$USER/g" "$HOME"/BirdNET-Pi/templates/automatic_update.cron >> /etc/crontab fi set +x diff --git a/templates/automatic_update.cron b/templates/automatic_update.cron new file mode 100644 index 0000000..9e93d8c --- /dev/null +++ b/templates/automatic_update.cron @@ -0,0 +1,2 @@ +#birdnet +0 3 * * 0 $USER /usr/local/bin/update_birdnet.sh -a >/dev/null 2>&1