diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index e6c93a99cc..2243d3090f 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,3 +1,8 @@ +## nightly-20260615-2 (2026-06-23) +- MariaDB auto-config: create the `birdnet` database on first start if it does not exist (birdnet-go connects to a pre-existing schema and does not create it, causing "database doesn't exist" errors) +- MariaDB auto-config: disabling `mariadb_auto_config` now writes `output.mysql.enabled = false` and `output.sqlite.enabled = true` back to config.yaml, so turning the option off fully reverts to SQLite +- Added `mariadb-client` to the addon packages so the `mysql` CLI used for database creation is available inside the container + - MQTT auto-config now also enables BirdNET-Go's native Home Assistant MQTT auto-discovery: detection sensors appear in Home Assistant automatically with no manual YAML (existing UI/config.yaml edits are preserved) - MQTT auto-config seeds `realtime.mqtt.retain: true` (only when unset) so sensor states survive Home Assistant restarts - Added supervisor watchdog (tcp://[HOST]:[PORT:8080]) so the add-on is automatically restarted if BirdNET-Go stops responding diff --git a/birdnet-go/Dockerfile b/birdnet-go/Dockerfile index 0d1b656847..5274b7e18c 100644 --- a/birdnet-go/Dockerfile +++ b/birdnet-go/Dockerfile @@ -62,7 +62,7 @@ COPY ha_automodules.sh /ha_automodules.sh RUN chmod 744 /ha_automodules.sh && /ha_automodules.sh "$MODULES" && rm /ha_automodules.sh # Manual apps -ENV PACKAGES="alsa-utils libasound2-plugins nginx yq" +ENV PACKAGES="alsa-utils libasound2-plugins mariadb-client nginx yq" # Automatic apps & bashio COPY ha_autoapps.sh /ha_autoapps.sh diff --git a/birdnet-go/config.yaml b/birdnet-go/config.yaml index 7d4d8dbef3..7799a3bfe1 100644 --- a/birdnet-go/config.yaml +++ b/birdnet-go/config.yaml @@ -128,4 +128,4 @@ slug: birdnet-go udev: true url: https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-go usb: true -version: "nightly-20260615" +version: "nightly-20260615-2" diff --git a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh index 51a7f484ac..e83796ceec 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh @@ -6,8 +6,17 @@ set -e # credentials directly into BirdNET-Go's config.yaml. Upstream reads MySQL # settings only from YAML (no env-var overrides exist), so this is the only # way to auto-configure them. The behaviour is opt-in via the -# mariadb_auto_config addon option. When the option is off but MariaDB is -# detected, we log a one-shot hint pointing users at the option. +# mariadb_auto_config addon option. +# +# When the option is off but MariaDB is detected, we log a one-shot hint and +# ensure config.yaml falls back to SQLite (reverting any previously written +# mysql block). This is safe because BirdNET-Go's config.yaml defaults to +# SQLite and the mysql block is only ever written by this script. +# +# When the option is on we: +# 1. Create the "birdnet" database if it does not already exist — birdnet-go +# connects to an existing schema and does not create it automatically. +# 2. Write the MySQL credentials into config.yaml and disable SQLite. CONFIG_LOCATION="/config/config.yaml" MYSQL_DATABASE="birdnet" @@ -23,13 +32,22 @@ MYSQL_PASS="$(bashio::services 'mysql' 'password')" if ! bashio::config.true 'mariadb_auto_config'; then bashio::log.green "---" - bashio::log.yellow "Home Assistant MariaDB addon detected. Set 'mariadb_auto_config: true' in the addon options to wire it into BirdNET-Go automatically (and disable SQLite). Connection details:" + bashio::log.yellow "Home Assistant MariaDB addon detected but mariadb_auto_config is disabled; ensuring BirdNET-Go uses SQLite." + bashio::log.yellow "Set 'mariadb_auto_config: true' in the addon options to wire MariaDB into BirdNET-Go automatically. Connection details:" bashio::log.blue "Database user : ${MYSQL_USER}" bashio::log.blue "Database password: ${MYSQL_PASS}" bashio::log.blue "Database name : ${MYSQL_DATABASE}" bashio::log.blue "Host-name : ${MYSQL_HOST}" bashio::log.blue "Port : ${MYSQL_PORT}" bashio::log.green "---" + if [ -f "$CONFIG_LOCATION" ]; then + # Revert any previously written mysql block so the app uses SQLite. + # shellcheck disable=SC2016 + yq -i -y \ + '.output.mysql.enabled = false + | .output.sqlite.enabled = true' \ + "$CONFIG_LOCATION" + fi exit 0 fi @@ -39,12 +57,26 @@ if [ ! -f "$CONFIG_LOCATION" ]; then fi bashio::log.green "---" -bashio::log.blue "mariadb_auto_config enabled; writing Home Assistant MariaDB credentials into BirdNET-Go config and disabling SQLite" +bashio::log.blue "mariadb_auto_config enabled; creating MariaDB database and wiring credentials into BirdNET-Go config" bashio::log.blue "Host: ${MYSQL_HOST}:${MYSQL_PORT}" bashio::log.blue "User: ${MYSQL_USER}" -bashio::log.blue "Database: ${MYSQL_DATABASE} (will be created by BirdNET-Go on first connect)" +bashio::log.blue "Database: ${MYSQL_DATABASE}" bashio::log.green "---" +# Create the database — birdnet-go connects to an existing schema and does NOT +# create it automatically, so we must do it here. MYSQL_PWD avoids exposing +# the password via the process command line. +if ! MYSQL_PWD="${MYSQL_PASS}" mysql \ + --host="${MYSQL_HOST}" \ + --port="${MYSQL_PORT}" \ + --user="${MYSQL_USER}" \ + --connect-timeout=10 \ + -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null; then + bashio::log.error "Failed to create MariaDB database '${MYSQL_DATABASE}' — verify the MariaDB addon is running and the user has CREATE DATABASE privileges" + exit 1 +fi +bashio::log.blue "Database '${MYSQL_DATABASE}' is ready" + # Upstream config.go stores port as a string; pass it as such to match. # $host / $port / etc. are jq/yq variables, not shell expansions — the # single quotes around the filter are intentional.