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 <Nachtzuster@users.noreply.github.com>

* Update scripts/update_birdnet_snippets.sh

Co-authored-by: Nachtzuster <Nachtzuster@users.noreply.github.com>

* 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 <Nachtzuster@users.noreply.github.com>
This commit is contained in:
dalogue1
2025-09-24 13:06:48 -05:00
committed by GitHub
parent adef45f741
commit 786348d815
5 changed files with 41 additions and 7 deletions
+22 -6
View File
@@ -203,6 +203,15 @@ if (isset($_GET["max_files_species"])) {
$contents = preg_replace("/SILENCE_UPDATE_INDICATOR=.*/", "SILENCE_UPDATE_INDICATOR=0", $contents); $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"])) { if(isset($_GET["raw_spectrogram"])) {
$raw_spectrogram = 1; $raw_spectrogram = 1;
if(strcmp($RAW_SPECTROGRAM,$config['RAW_SPECTROGRAM']) !== 0) { if(strcmp($RAW_SPECTROGRAM,$config['RAW_SPECTROGRAM']) !== 0) {
@@ -454,19 +463,26 @@ foreach($formats as $format){
<input style="width:40ch;" name="birdnetpi_url" type="url" value="<?php print($newconfig['BIRDNETPI_URL']);?>" /><br> <input style="width:40ch;" name="birdnetpi_url" type="url" value="<?php print($newconfig['BIRDNETPI_URL']);?>" /><br>
<p>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 "<i>http://</i>".<br>Example for IP: <i>http://192.168.0.109</i><br>Example if you own your own domain: <i>https://virginia.birdnetpi.com</i></p> <p>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 "<i>http://</i>".<br>Example for IP: <i>http://192.168.0.109</i><br>Example if you own your own domain: <i>https://virginia.birdnetpi.com</i></p>
</td></tr></table><br> </td></tr></table><br>
<table class="settingstable"><tr><td> <table class="settingstable"><tr><td>
<h2>Options</h2> <h2>Options</h2>
<label for="silence_update_indicator">Silence Update Indicator: </label> <label for="silence_update_indicator">Silence Update Indicator: </label>
<input type="checkbox" name="silence_update_indicator" <?php if($newconfig['SILENCE_UPDATE_INDICATOR'] == 1) { echo "checked"; };?> ><br> <input type="checkbox" name="silence_update_indicator" <?php if($newconfig['SILENCE_UPDATE_INDICATOR'] == 1) { echo "checked"; };?> >
<p>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.</p> <p>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.</p><br>
<label for="automatic_update">Automatic Update: </label>
<input type="checkbox" name="automatic_update" <?php if($newconfig['AUTOMATIC_UPDATE'] == 1) { echo "checked"; };?> >
<p>This configures an automatic update of the installation each Sunday at 3:00 AM but the timing can be changed using crontab.</p><br>
<label for="raw_spectrogram">Minimalist Spectrograms: </label> <label for="raw_spectrogram">Minimalist Spectrograms: </label>
<input type="checkbox" name="raw_spectrogram" <?php if($newconfig['RAW_SPECTROGRAM'] == 1) { echo "checked"; };?> ><br> <input type="checkbox" name="raw_spectrogram" <?php if($newconfig['RAW_SPECTROGRAM'] == 1) { echo "checked"; };?> >
<p>This allows you to remove the axes and labels of the spectrograms that are generated by Sox for each detection for a cleaner appearance.</p> <p>This allows you to remove the axes and labels of the spectrograms that are generated by Sox for each detection for a cleaner appearance.</p><br>
<label for="rare_species_threshold">Rare Species Threshold (days): </label> <label for="rare_species_threshold">Rare Species Threshold (days): </label>
<input type="number" name="rare_species_threshold" min="1" value="<?php echo isset($newconfig['RARE_SPECIES_THRESHOLD']) ? $newconfig['RARE_SPECIES_THRESHOLD'] : 30; ?>"><br> <input type="number" name="rare_species_threshold" min="1" value="<?php echo isset($newconfig['RARE_SPECIES_THRESHOLD']) ? $newconfig['RARE_SPECIES_THRESHOLD'] : 30; ?>">
<p>This setting defines after how many days since last detection a species is considered rare. Default is 30 days.</p> <p>This setting defines after how many days since last detection a species is considered rare. Default is 30 days.</p>
</td></tr></table><br> </td></tr></table><br>
<table class="settingstable"><tr><td> <table class="settingstable"><tr><td>
+6
View File
@@ -265,6 +265,12 @@ HEARTBEAT_URL=
SILENCE_UPDATE_INDICATOR=0 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 ## RAW_SPECTROGRAM is for removing the axes and labels of the spectrograms
## that are generated by Sox for each detection for a cleaner appearance. ## that are generated by Sox for each detection for a cleaner appearance.
+5
View File
@@ -383,6 +383,10 @@ install_weekly_cron() {
sed "s/\$USER/$USER/g" $my_dir/templates/weekly_report.cron >> /etc/crontab 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_things() {
chown -R $USER:$USER $HOME/Bird* chown -R $USER:$USER $HOME/Bird*
} }
@@ -418,6 +422,7 @@ install_services() {
install_birdnet_mount install_birdnet_mount
install_cleanup_cron install_cleanup_cron
install_weekly_cron install_weekly_cron
install_automatic_update_cron
increase_caddy_timeout increase_caddy_timeout
create_necessary_dirs create_necessary_dirs
+6 -1
View File
@@ -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 echo "MAX_FILES_SPECIES=\"0\"" >> /etc/birdnet/birdnet.conf
fi 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 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 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 echo "RARE_SPECIES_THRESHOLD=\"30\"" >> /etc/birdnet/birdnet.conf
@@ -235,10 +239,11 @@ if [ -L /usr/local/bin/birdnet_analysis.sh ];then
fi fi
# Clean state and update cron if all scripts are not installed # 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 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/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/weekly_report.cron >> /etc/crontab
sed "s/\$USER/$USER/g" "$HOME"/BirdNET-Pi/templates/automatic_update.cron >> /etc/crontab
fi fi
set +x set +x
+2
View File
@@ -0,0 +1,2 @@
#birdnet
0 3 * * 0 $USER /usr/local/bin/update_birdnet.sh -a >/dev/null 2>&1