forked from mcguirepr89/BirdNET-Pi
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add birdweather_past_publication in update scripts
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ chmod g+r $HOME | |
# remove world-writable perms | ||
chmod -R o-w ~/BirdNET-Pi/templates/* | ||
|
||
# update database schema | ||
$my_dir/update_db.sh | ||
|
||
APT_UPDATED=0 | ||
PIP_UPDATED=0 | ||
|
||
|
@@ -147,6 +150,29 @@ if grep -q 'birdnet_server.service' "$HOME/BirdNET-Pi/templates/birdnet_analysis | |
systemctl daemon-reload && restart_services.sh | ||
fi | ||
|
||
|
||
# Ensure networkd-dispatcher is installed | ||
if ! dpkg -s networkd-dispatcher >/dev/null 2>&1; then | ||
echo "networkd-dispatcher is not installed. Installing it now..." | ||
sudo apt update -qq | ||
sudo apt install -qqy networkd-dispatcher | ||
fi | ||
|
||
# Add BirdWeather past publication service if not already installed | ||
export PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3" | ||
BIRDWEATHER_PAST_DISPATCHER_SCRIPT="$HOME/BirdNET-Pi/templates/50-birdweather-past-publication" | ||
BIRDWEATHER_PAST_SERVICE_FILE="/usr/lib/systemd/system/[email protected]" | ||
if [ ! -f "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" ] || [ ! -f "$BIRDWEATHER_PAST_SERVICE_FILE" ]; then | ||
echo "Installing BirdWeather past publication service..." | ||
install_birdweather_past_publication | ||
fi | ||
# Set ownership to root for the birdweather publication networkd-dispatcher script | ||
if [ -f "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" ]; then | ||
sudo chown root:root "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" | ||
sudo chmod 755 "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" | ||
fi | ||
|
||
|
||
TMP_MOUNT=$(systemd-escape -p --suffix=mount "$RECS_DIR/StreamData") | ||
if ! [ -f "$HOME/BirdNET-Pi/templates/$TMP_MOUNT" ]; then | ||
install_birdnet_mount | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
DB_PATH="$HOME/BirdNET-Pi/scripts/birds.db" | ||
|
||
echo "Checking database schema for updates" | ||
|
||
# Check if the tables exist | ||
DETECTIONS_TABLE_EXISTS=$(sqlite3 "$DB_PATH" "SELECT name FROM sqlite_master WHERE type='table' AND name='detections';") | ||
SCRIPTS_MTD_TABLE_EXISTS=$(sqlite3 "$DB_PATH" "SELECT name FROM sqlite_master WHERE type='table' AND name='scripts_metadata';") | ||
|
||
if [ -z "$DETECTIONS_TABLE_EXISTS" ]; then | ||
echo "Table 'detections' does not exist. Creating table..." | ||
sqlite3 "$DB_PATH" << EOF | ||
CREATE TABLE IF NOT EXISTS detections ( | ||
Date DATE, | ||
Time TIME, | ||
Sci_Name VARCHAR(100) NOT NULL, | ||
Com_Name VARCHAR(100) NOT NULL, | ||
Confidence FLOAT, | ||
Lat FLOAT, | ||
Lon FLOAT, | ||
Cutoff FLOAT, | ||
Week INT, | ||
Sens FLOAT, | ||
Overlap FLOAT, | ||
File_Name VARCHAR(100) NOT NULL); | ||
CREATE INDEX "detections_Com_Name" ON "detections" ("Com_Name"); | ||
CREATE INDEX "detections_Date_Time" ON "detections" ("Date" DESC, "Time" DESC); | ||
EOF | ||
echo "Table 'detections' created successfully." | ||
elif [ -z "$SCRIPTS_MTD_TABLE_EXISTS" ]; then | ||
echo "Table 'scripts_metadata' does not exist. Creating table..." | ||
sqlite3 "$DB_PATH" << EOF | ||
CREATE TABLE IF NOT EXISTS scripts_metadata ( | ||
script_name TEXT PRIMARY KEY, | ||
last_run DATETIME | ||
); | ||
EOF | ||
echo "Table 'scripts_metadata' created successfully." | ||
else | ||
echo "Tables 'detections' and 'scripts_metadata' already exist. No changes made." | ||
fi | ||
|
||
echo "Database schema update complete." |