From 511e884a9b47146ec16efdef5d4a2be4bb297f48 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:24:31 +0100 Subject: [PATCH 1/3] Update CHANGELOG.md --- birdnet-go/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 8a1fe6f9e..0c1df1c40 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,3 +1,5 @@ +- BREAKING CHANGE : force implementation + ## 20250103-5 (16-01-2025) - Fix ingress issues From 32d39ea3e5145daa458ff7d675a83f1015c6e7c0 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:36:55 +0100 Subject: [PATCH 2/3] Update 01-structure.sh --- .../rootfs/etc/cont-init.d/01-structure.sh | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 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 439b9a926..52794a3f7 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh @@ -2,7 +2,7 @@ # shellcheck shell=bash set -e -# Required Commands +# Ensure required commands are installed for cmd in yq amixer; do command -v "$cmd" >/dev/null 2>&1 || { bashio::log.fatal "$cmd is required but not installed. Exiting."; exit 1; } done @@ -11,23 +11,19 @@ done DEFAULT_BIRDSONGS_FOLDER="/data/clips/" CONFIG_LOCATIONS=("/config/config.yaml" "/internal/conf/config.yaml") -# Database location -bashio::log.info "Setting database location to /config/birdnet.db" -for configloc in "${CONFIG_LOCATIONS[@]}"; do - if [ -f "$configloc" ]; then - yq -i -y ".output.sqlite.path = \"/config/birdnet.db\"" "$configloc" - bashio::log.info "Updated database path in $configloc" - fi -done - +################# # Migrate Database +################# if [ -f /data/birdnet.db ]; then - bashio::log.warning "Moving db to /config" + bashio::log.warning "Moving birdnet.db to /config/birdnet.db" mv /data/birdnet.db /config fi -# Birdsongs Folder +###################### +# Birdsongs Location +###################### CURRENT_BIRDSONGS_FOLDER="clips/" +# Read the current folder from config files for configloc in "${CONFIG_LOCATIONS[@]}"; do if [ -f "$configloc" ]; then CURRENT_BIRDSONGS_FOLDER="$(yq '.realtime.audio.export.path' "$configloc" | tr -d '\"')" @@ -36,6 +32,12 @@ for configloc in "${CONFIG_LOCATIONS[@]}"; do done CURRENT_BIRDSONGS_FOLDER="${CURRENT_BIRDSONGS_FOLDER:-$DEFAULT_BIRDSONGS_FOLDER}" +# Adjust default path if it matches the default string +if [[ "$CURRENT_BIRDSONGS_FOLDER" == "clips/" ]]; then + CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER" +fi + +# Set the new birdsongs folder BIRDSONGS_FOLDER="$(bashio::config "BIRDSONGS_FOLDER")" BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER:-/config/clips}" BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER%/}" @@ -43,8 +45,9 @@ if ! mkdir -p "$BIRDSONGS_FOLDER"; then bashio::log.fatal "Cannot create $BIRDSONGS_FOLDER." exit 1 fi +bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon options" -# Migrate Files if Folder Changed +# Migrate data if the folder has changed if [[ "$CURRENT_BIRDSONGS_FOLDER" != "$BIRDSONGS_FOLDER" ]]; then bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then @@ -52,6 +55,8 @@ if [[ "$CURRENT_BIRDSONGS_FOLDER" != "$BIRDSONGS_FOLDER" ]]; then cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/ mv "$CURRENT_BIRDSONGS_FOLDER" "${CURRENT_BIRDSONGS_FOLDER}_migrated" fi + + # Update config files with the new birdsongs folder path for configloc in "${CONFIG_LOCATIONS[@]}"; do if [ -f "$configloc" ]; then yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$configloc" @@ -59,7 +64,20 @@ if [[ "$CURRENT_BIRDSONGS_FOLDER" != "$BIRDSONGS_FOLDER" ]]; then done fi -# Volume Adjustment +#################### +# Correct Defaults +#################### +bashio::log.info "Correcting configuration for defaults" + +# Update database location in config files +for configloc in "${CONFIG_LOCATIONS[@]}"; do + if [ -f "$configloc" ]; then + yq -i -y ".output.sqlite.path = \"/config/birdnet.db\"" "$configloc" + bashio::log.info "... database is located in $configloc" + fi +done + +# Adjust microphone volume if needed current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2>/dev/null || echo "100")" if [[ "$current_volume" -eq 0 ]]; then amixer sset Capture 70% From cdb072b0b2b4324b2251bbee953b3e8cded8d377 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:37:42 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- birdnet-go/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 0c1df1c40..efedc5f7a 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,4 +1,4 @@ -- BREAKING CHANGE : force implementation +- BREAKING CHANGE : improve implementation of addon options such as Birdsongs folder. Please check the log at first start if anything is different than you expected ## 20250103-5 (16-01-2025) - Fix ingress issues