Update 01-structure.sh

This commit is contained in:
Alexandre
2025-05-15 10:26:31 +02:00
committed by GitHub
parent 7b260f59f0
commit a685ff6add

View File

@@ -4,7 +4,7 @@ set -e
# Default Variables
DEFAULT_BIRDSONGS_FOLDER="/data/clips/"
CONFIG_LOCATIONS=("/config/config.yaml")
CONFIG_LOCATION="/config/config.yaml"
if [ ! -f /config/config.yaml ]; then
bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize"
@@ -24,12 +24,7 @@ fi
######################
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 '\"')"
break
fi
done
CURRENT_BIRDSONGS_FOLDER="$(yq '.realtime.audio.export.path' "$CONFIG_LOCATION" | tr -d '\"')"
CURRENT_BIRDSONGS_FOLDER="${CURRENT_BIRDSONGS_FOLDER:-$DEFAULT_BIRDSONGS_FOLDER}"
# Adjust default path if it matches the default string
@@ -60,11 +55,7 @@ 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
for configloc in "${CONFIG_LOCATIONS[@]}"; do
if [ -f "$configloc" ]; then
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$configloc"
fi
done
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION"
# 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"
@@ -107,16 +98,12 @@ fi
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
yq -i -y ".output.sqlite.path = \"/config/birdnet.db\"" "$CONFIG_LOCATION"
bashio::log.info "... database is located in /config/birdnet.db"
# Adjust microphone volume if needed
current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2>/dev/null || echo "100")"
current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2>/dev/null || echo "100")" || true
if [[ "$current_volume" -eq 0 ]]; then
amixer sset Capture 70%
bashio::log.warning "Microphone was off, volume set to 70%."
fi
fi || true