A live bird collage card for your Home Assistant dashboard.
Add Purge Threshold
Christopher Leinbachbdc58028160f
diff --git a/scripts/advanced.php b/scripts/advanced.phpindex fd484d49..468e4df9 100644--- a/scripts/advanced.php+++ b/scripts/advanced.php@@ -130,6 +130,13 @@ if(isset($_GET['submit'])) {}}+ if (isset($_GET["purge_threshold"])) {+ $purge_threshold = $_GET["purge_threshold"];+ if (strcmp($purge_threshold, $config['PURGE_THERSHOLD']) !== 0) {+ $contents = preg_replace("/PURGE_THERSHOLD=.*/", "PURGE_THERSHOLD=$purge_threshold", $contents);+ }+}+if (isset($_GET["max_files_species"])) {$max_files_species = $_GET["max_files_species"];if (strcmp($max_files_species, $config['MAX_FILES_SPECIES']) !== 0) {@@ -297,6 +304,11 @@ $newconfig = get_config();<input name="full_disk" type="radio" id="keep" value="keep" <?php if (strcmp($newconfig['FULL_DISK'], "keep") == 0) { echo "checked"; }?>>Keep</label><p>When the disk becomes full, you can choose to 'purge' old files to make room for new ones or 'keep' your data and stop all services instead.<br>Note: you can exclude specific files from 'purge' on the Recordings page.</p><br>+ <label for="purge_threshold">Purge Threshold (Disk Used %):</label>+ <input name="purge_threshold" type="number" style="width:6em;" min="20" max="99" step="1" value="<?php print($newconfig['PURGE_THRESHOLD']);?>"/>+ </td></tr><tr><td>+ <p>Defines how full the disk should be before the purge operations occur.<br>Note: This variable is still active if Keep is set. This means that the servies will be stopped at the purge threshold.</p>+ </td></tr><tr><td><label for="max_files_species">Amount of files to keep for each species :</label><input name="max_files_species" type="number" style="width:6em;" min="0" step="1" value="<?php print($newconfig['MAX_FILES_SPECIES']);?>"/></td></tr><tr><td>diff --git a/scripts/disk_check.sh b/scripts/disk_check.shindex c6c98d8f..ba5b5e64 100755--- a/scripts/disk_check.sh+++ b/scripts/disk_check.sh@@ -3,8 +3,9 @@ set -xsource /etc/birdnet/birdnet.confused="$(df -h ${EXTRACTED} | tail -n1 | awk '{print $5}')"+purge_threshold="${PURGE_THRESHOLD:-95}"-if [ "${used//%}" -ge 95 ]; then+if [ "${used//%}" -ge "$purge_threshold" ]; thencase $FULL_DISK inpurge) echo "Removing oldest data"@@ -34,7 +35,7 @@ if [ "${used//%}" -ge 95 ]; thenesacfisleep 1-if [ "${used//%}" -ge 95 ]; then+if [ "${used//%}" -ge "$purge_threshold" ]; thencase $FULL_DISK inpurge) echo "Removing more data"rm -rfv ${PROCESSED}/*;;diff --git a/scripts/install_config.sh b/scripts/install_config.shindex 665d4827..44bf19dc 100755--- a/scripts/install_config.sh+++ b/scripts/install_config.sh@@ -136,6 +136,10 @@ COLOR_SCHEME="light"FULL_DISK=purge+## PURGE_THRESHOLD can be set to configure at what disk full percentage the+## purge operations are triggered.+PURGE_THRESHOLD=95+## Maximum amount of files to keep for a given specie (0 = keep all)## Files from the last 7 days, and files protected from purge, are not taken into## account in this numberdiff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.shindex 7d90cc30..acbd4c40 100755--- a/scripts/update_birdnet_snippets.sh+++ b/scripts/update_birdnet_snippets.sh@@ -100,6 +100,10 @@ if ! grep -E '^COLOR_SCHEME=' /etc/birdnet/birdnet.conf &>/dev/null;thenecho "COLOR_SCHEME=\"light\"" >> /etc/birdnet/birdnet.conffi+if ! grep -E '^PURGE_THRESHOLD=' /etc/birdnet/birdnet.conf &>/dev/null;then+ echo "PURGE_THRESHOLD=\"95\"" >> /etc/birdnet/birdnet.conf+fi+if ! grep -E '^MAX_FILES_SPECIES=' /etc/birdnet/birdnet.conf &>/dev/null;thenecho "MAX_FILES_SPECIES=\"0\"" >> /etc/birdnet/birdnet.conffi