Skip to content

Commit

Permalink
Add birdweather_past_publication in update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tvoirand committed Dec 7, 2024
1 parent 0bdc488 commit c21c6d5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/update_birdnet_snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions scripts/update_db.sh
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."

0 comments on commit c21c6d5

Please sign in to comment.