From 9c2777c8be172d378040af7458851009b2e29daa Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:45:26 +0200 Subject: [PATCH] Change audio clips from addon options https://github.com/alexbelgium/hassio-addons/issues/1457 --- birdnet-go/CHANGELOG.md | 2 + birdnet-go/config.json | 4 +- .../rootfs/etc/cont-init.d/01-structure.sh | 52 +++++++++++++++++++ .../rootfs/etc/cont-init.d/31-checks.sh | 2 +- 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 birdnet-go/rootfs/etc/cont-init.d/01-structure.sh diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 7bcd9fac9..e04aae017 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,3 +1,5 @@ +- New option : set the audio clip directory from addon options + ## 0.5.5-2 (25-06-2024) - Minor bugs fixed diff --git a/birdnet-go/config.json b/birdnet-go/config.json index 1491dd476..4c5e97ed8 100644 --- a/birdnet-go/config.json +++ b/birdnet-go/config.json @@ -77,6 +77,7 @@ ], "name": "Birdnet-go", "options": { + "BIRDSONGS_FOLDER": "/config/clips", "COMMAND": "realtime" }, "panel_admin": false, @@ -93,6 +94,7 @@ ], "schema": { "ALSA_CARD": "int?", + "BIRDSONGS_FOLDER": "str?", "COMMAND": "str", "TZ": "str?", "cifsdomain": "str?", @@ -108,5 +110,5 @@ "slug": "birdnet-go", "udev": true, "url": "https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-go", - "version": "0.5.5-2" + "version": "0.5.5-3" } diff --git a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh new file mode 100644 index 000000000..7ab137107 --- /dev/null +++ b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh @@ -0,0 +1,52 @@ +#!/usr/bin/with-contenv bashio +# shellcheck shell=bash +set -e + +################# +# Migrate files # +################# +if [ -f /data/birdnet.db ]; then + bashio::log.warning "Moving db to /config" + mv /data/birdnet.db /config +fi + +# Audio clips location +birdsongsloc="$(bashio::config "BIRDSONGS_FOLDER")" +birdsongsloc="${birdsongsloc:-/config/clips}" +birdsongsloc="${birdsongsloc%/}" +mkdir -p "$birdsongsloc" +if [ -d /data/clips ]; then + bashio::log.warning "Audio clips found in /data, moving to the new location" + cp -rnf /data/clips/* "$birdsongsloc"/ + rm -r /data/clips +fi + +#################### +# Correct defaults # +#################### +bashio::log.info "Correct config for defaults" + +# Database location +echo "... database location is /config/birdnet.db" +for configloc in /config/config.yaml /internal/conf/config.yaml; do + if [ -f "$configloc" ]; then + sed -i "/path: birdnet.db/c\ path: /config/birdnet.db # path to sqlite database" "$configloc" + sed -i "/path to sqlite database/c\ path: /config/birdnet.db # path to sqlite database" "$configloc" + fi +done + +# Birdsongs location +echo "... audio clips saved to $birdsongsloc" +for configloc in /config/config.yaml /internal/conf/config.yaml; do + if [ -f "$configloc" ]; then + sed -i "/path: clips/c\ path: $birdsongsloc # path to audio clip export directory" "$configloc" + sed -i "/audio clip export directory/c\ path: $birdsongsloc # path to audio clip export directory" "$configloc" + fi +done +# If default capture is set at 0%, increase it to 50% +current_volume="$(amixer sget Capture | grep -oP '\[\d+%]' | tr -d '[]%' | head -1)" 2>/dev/null || true +current_volume="${current_volume:-100}" +if [[ "$current_volume" -eq 0 ]]; then + amixer sset Capture 70% + bashio::log.warning "Microphone was off, volume set to 70%." +fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh b/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh index 71d8356e2..f9e2585f8 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh @@ -34,7 +34,7 @@ done # If default capture is set at 0%, increase it to 50% current_volume="$(amixer sget Capture | grep -oP '\[\d+%]' | tr -d '[]%' | head -1)" 2>/dev/null || true -current_volume="{current_volume:-100}" +current_volume="${current_volume:-100}" # Set the default microphone volume to 50% if it's currently at 0% if [[ "$current_volume" -eq 0 ]]; then