From 7a9b1f88aa9457a16463558b4895cc19b7932de0 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:23:06 +0100 Subject: [PATCH] Update 01-structure.sh --- .../rootfs/etc/cont-init.d/01-structure.sh | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh index 3b138f6cc..9f59fbfb5 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh @@ -62,17 +62,22 @@ if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${$BIRDSONGS_FOLDER%/}" ]]; then cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/ mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated" fi - # Define the SQLite database file - DB_FILE="your_database.db" - # SQL query to update the paths - SQL_QUERY="UPDATE notes SET clip_name = REPLACE(clip_name, 'clips/', '/zlkrj/zer');" - # Execute the query using sqlite3 - sqlite3 "$DB_FILE" "$SQL_QUERY" - # Check if the operation was successful - if [ $? -eq 0 ]; then - echo "Paths have been successfully updated." - else - bashio::log.warning "An error occurred while updating the paths." + # Adapt the database + if [ -f /config/birdnet.db ]; then + # SQL query to update the paths + bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup will be created before" + cp /config/birdnet.db /config/birdnet.db_$(date +%Y%m%d_%H%M%S) + SQL_QUERY="UPDATE notes SET clip_name = REPLACE(clip_name, '^${CURRENT_BIRDSONGS_FOLDER}/', '${BIRDSONGS_FOLDER%/}/');" + + # Execute the query using sqlite3 + sqlite3 /config/birdnet.db "$SQL_QUERY" + + # Check if the operation was successful + if [ $? -eq 0 ]; then + echo "Paths have been successfully updated." + else + bashio::log.warning "An error occurred while updating the paths." + fi fi fi