Skip to content

A live bird collage card for your Home Assistant dashboard.

Automatic Update Feature (#424)

dalogue1786348d815a8
diff --git a/scripts/advanced.php b/scripts/advanced.php
index dab63399..48ac7bc7 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){
<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>
</td></tr></table><br>
+
<table class="settingstable"><tr><td>
<h2>Options</h2>
+
<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>
- <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>
-
+ <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><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>
- <input type="checkbox" name="raw_spectrogram" <?php if($newconfig['RAW_SPECTROGRAM'] == 1) { echo "checked"; };?> ><br>
- <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>
+ <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><br>
<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>
+
</td></tr></table><br>
<table class="settingstable"><tr><td>
diff --git a/scripts/install_config.sh b/scripts/install_config.sh
index 3c4a334f..a80281ad 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 458c568d..38690a19 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 937b8881..a5878d36 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 00000000..9e93d8cb
--- /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