Skip to content

A live bird collage card for your Home Assistant dashboard.

added "Clear all data" button and "Shutdown BirdNET-Lite" button

Patrick McGuire47a5c6443056
diff --git a/scripts/clear_all_data.php b/scripts/clear_all_data.php
new file mode 100644
index 00000000..606aa784
--- /dev/null
+++ b/scripts/clear_all_data.php
@@ -0,0 +1,4 @@
+<?php
+shell_exec("/home/pi/BirdNET-Lite/scripts/clear_all_data.sh");
+header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
+?>
diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh
index b43bc259..41a5d02c 100755
--- a/scripts/clear_all_data.sh
+++ b/scripts/clear_all_data.sh
@@ -4,38 +4,19 @@
# you are okay will losing all the data that you've collected and processed
# so far.
source /etc/birdnet/birdnet.conf
-
-echo "
-This script removes all data that has been collected. It is tantamount to
-starting all data-collection from scratch. Only run this if you are sure
-you are okay with losing all the data that you've collected and processed
-so far.
-
-"
-read -n1 -p "Are you sure you want to wipe away ALL data?" YN
-echo
-while true; do
- case $YN in
- [Yy]) break;;
- *) echo "Exiting since you didn't answer with Y or y." && exit;;
- esac
-done
-
echo "Stopping services"
sudo systemctl stop birdnet_recording.service
echo "Removing all data . . . "
sudo rm -drf "${RECS_DIR}"
rm "${IDFILE}"
-
echo "Recreating necessary directories"
-[ -d ${RECS_DIR} ] || mkdir -p ${RECS_DIR}
-[ -d ${EXTRACTED} ] || mkdir -p ${EXTRACTED}
-[ -d ${EXTRACTED}/By_Date ] || mkdir -p ${EXTRACTED}/By_Date
-[ -d ${EXTRACTED}/By_Common_Name ] || mkdir -p ${EXTRACTED}/By_Common_Name
-[ -d ${EXTRACTED}/By_Scientific_Name ] || mkdir -p ${EXTRACTED}/By_Scientific_Name
-[ -d ${PROCESSED} ] || mkdir -p ${PROCESSED}
-cp ~/BirdNET-Lite/templates/index.html ${EXTRACTED}/
-
-
+[ -d ${RECS_DIR} ] || sudo -u ${BIRDNET_USER} mkdir -p ${RECS_DIR}
+[ -d ${EXTRACTED} ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}
+[ -d ${EXTRACTED}/By_Date ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}/By_Date
+[ -d ${EXTRACTED}/By_Common_Name ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}/By_Common_Name
+[ -d ${EXTRACTED}/By_Scientific_Name ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}/By_Scientific_Name
+[ -d ${PROCESSED} ] || sudo -u ${BIRDNET_USER} mkdir -p ${PROCESSED}
+[ -L ${EXTRACTED}/scripts ] || sudo -u ${BIRDNET_USER} ln -s /home/pi/BirdNET-Lite/scripts ${EXTRACTED}/
+sudo -u ${BIRDNET_USER} cp ~/BirdNET-Lite/templates/index.html ${EXTRACTED}/
echo "Restarting services"
sudo systemctl restart birdnet_recording.service
diff --git a/scripts/index.html b/scripts/index.html
index 0e158b24..38d52c78 100644
--- a/scripts/index.html
+++ b/scripts/index.html
@@ -18,7 +18,17 @@
<input type="submit" value="Restart Caddy">
</form>
+<form action="/scripts/clear_all_data.php">
+ <input type="submit" value="Clear ALL data">
+</form>
+
<form action="/scripts/reboot_system.php">
<input type="submit" value="Reboot BirdNET-system">
</form>
+<form action="/scripts/shutdown_system.php">
+ <input type="submit" value="Shutdown BirdNET-system">
+</form>
+
+
+
diff --git a/scripts/shutdown_system.php b/scripts/shutdown_system.php
new file mode 100644
index 00000000..b765831d
--- /dev/null
+++ b/scripts/shutdown_system.php
@@ -0,0 +1,4 @@
+<?php
+shell_exec("/home/pi/BirdNET-Lite/scripts/shutdown_system.sh");
+header('Location: http://birdnetsystem.local/scripts/index.html?success=true');
+?>
diff --git a/scripts/shutdown_system.sh b/scripts/shutdown_system.sh
new file mode 100755
index 00000000..d2eff34e
--- /dev/null
+++ b/scripts/shutdown_system.sh
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+sudo shutdown now