Alexandre
2025-05-15 10:18:37 +02:00
committed by GitHub
parent 19ec9498a8
commit 7c1046ff49

View File

@@ -4,7 +4,12 @@ set -e
# Default Variables
DEFAULT_BIRDSONGS_FOLDER="/data/clips/"
CONFIG_LOCATION="/config/config.yaml"
CONFIG_LOCATIONS=("/config/config.yaml" "/internal/conf/config.yaml")
if [ ! -f /config/config.yaml ]; then
bashio::log.warning "There is no config.yaml yet in the config folder, creating a default one. Please customize"
cp /internal/conf/config.yaml /config/
fi
#################
# Migrate Database
@@ -19,9 +24,12 @@ fi
######################
CURRENT_BIRDSONGS_FOLDER="clips/"
# Read the current folder from config files
if [ -f "$CONFIG_LOCATION" ]; then
CURRENT_BIRDSONGS_FOLDER="$(yq '.realtime.audio.export.path' "$CONFIG_LOCATION" | tr -d '\"')"
fi
for configloc in "${CONFIG_LOCATIONS[@]}"; do
if [ -f "$configloc" ]; then
CURRENT_BIRDSONGS_FOLDER="$(yq '.realtime.audio.export.path' "$configloc" | tr -d '\"')"
break
fi
done
CURRENT_BIRDSONGS_FOLDER="${CURRENT_BIRDSONGS_FOLDER:-$DEFAULT_BIRDSONGS_FOLDER}"
# Adjust default path if it matches the default string
@@ -52,9 +60,11 @@ bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon
if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then
bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
# Update config files with the new birdsongs folder path
if [ -f "$CONFIG_LOCATION" ]; then
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION"
fi
for configloc in "${CONFIG_LOCATIONS[@]}"; do
if [ -f "$configloc" ]; then
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$configloc"
fi
done
# Move files only if sqlite paths changed
if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then
bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
@@ -97,10 +107,12 @@ fi
bashio::log.info "Correcting configuration for defaults"
# Update database location in config files
if [ -f "$CONFIG_LOCATION" ]; then
yq -i -y ".output.sqlite.path = \"/config/birdnet.db\"" "$CONFIG_LOCATION"
bashio::log.info "... database is located in $CONFIG_LOCATION"
fi
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")"