fix: auto-fix linting issues

This commit is contained in:
alexbelgium
2025-06-10 10:06:17 +00:00
committed by github-actions[bot]
parent e5adbd266f
commit f728166b14
197 changed files with 5747 additions and 5714 deletions

View File

@@ -7,16 +7,16 @@ DEFAULT_BIRDSONGS_FOLDER="/data/clips/"
CONFIG_LOCATION="/config/config.yaml"
if [ ! -f "$CONFIG_LOCATION" ]; then
bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize"
curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION"
bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize"
curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION"
fi
#################
# Migrate Database
#################
if [ -f /data/birdnet.db ]; then
bashio::log.warning "Moving birdnet.db to /config/birdnet.db"
mv /data/birdnet.db /config
bashio::log.warning "Moving birdnet.db to /config/birdnet.db"
mv /data/birdnet.db /config
fi
######################
@@ -29,67 +29,67 @@ 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"
CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER"
fi
# Set the new birdsongs folder
BIRDSONGS_FOLDER="$(bashio::config "BIRDSONGS_FOLDER")"
BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER:-clips/}"
BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER%/}" # Remove trailing slash if present
BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER%/}" # Remove trailing slash if present
if [[ ! "$BIRDSONGS_FOLDER" == /* ]]; then
if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then
mkdir -p "/config/$BIRDSONGS_FOLDER"
fi
if [ -d "/data/$BIRDSONGS_FOLDER" ]; then
if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2>/dev/null)" ]; then
cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/
fi
rm -r "/data/$BIRDSONGS_FOLDER"
fi
ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER"
if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then
mkdir -p "/config/$BIRDSONGS_FOLDER"
fi
if [ -d "/data/$BIRDSONGS_FOLDER" ]; then
if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2>/dev/null)" ]; then
cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/
fi
rm -r "/data/$BIRDSONGS_FOLDER"
fi
ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER"
fi
bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon options"
# 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"
# Update config files with the new birdsongs folder path
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"
cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/
mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated"
fi
# Adapt the database
if [ -f /config/birdnet.db ]; then
# Prepare
backup="$(date +%Y%m%d_%H%M%S)"
bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before"
bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
# Update config files with the new birdsongs folder path
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"
cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/
mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated"
fi
# Adapt the database
if [ -f /config/birdnet.db ]; then
# Prepare
backup="$(date +%Y%m%d_%H%M%S)"
bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before"
# Create backup
if ! cp /config/birdnet.db "birdnet.db_$backup"; then
bashio::log.error "Failed to create a backup of the database. Aborting path modification."
exit 1
fi
# Create backup
if ! cp /config/birdnet.db "birdnet.db_$backup"; then
bashio::log.error "Failed to create a backup of the database. Aborting path modification."
exit 1
fi
# Execute the query using sqlite3
SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';"
if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored."
BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename
if [ -f "$BACKUP_FILE" ]; then
mv "$BACKUP_FILE" /config/birdnet.db
bashio::log.info "The database backup has been restored."
else
bashio::log.error "Backup file not found! Manual intervention required."
fi
else
echo "Paths have been successfully updated."
fi
fi
# Execute the query using sqlite3
SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';"
if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored."
BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename
if [ -f "$BACKUP_FILE" ]; then
mv "$BACKUP_FILE" /config/birdnet.db
bashio::log.info "The database backup has been restored."
else
bashio::log.error "Backup file not found! Manual intervention required."
fi
else
echo "Paths have been successfully updated."
fi
fi
fi
####################

View File

@@ -5,12 +5,12 @@ set -e
# Gives mariadb information
if bashio::services.available 'mysql'; then
bashio::log.green "---"
bashio::log.yellow "MariaDB addon is active on your system! If you want to use it instead of sqlite, here are the informations to encode :"
bashio::log.blue "Database user : $(bashio::services "mysql" "username")"
bashio::log.blue "Database password : $(bashio::services "mysql" "password")"
bashio::log.blue "Database name : birdnet"
bashio::log.blue "Host-name : $(bashio::services "mysql" "host")"
bashio::log.blue "Port : $(bashio::services "mysql" "port")"
bashio::log.green "---"
bashio::log.green "---"
bashio::log.yellow "MariaDB addon is active on your system! If you want to use it instead of sqlite, here are the informations to encode :"
bashio::log.blue "Database user : $(bashio::services "mysql" "username")"
bashio::log.blue "Database password : $(bashio::services "mysql" "password")"
bashio::log.blue "Database name : birdnet"
bashio::log.blue "Host-name : $(bashio::services "mysql" "host")"
bashio::log.blue "Port : $(bashio::services "mysql" "port")"
bashio::log.green "---"
fi

View File

@@ -5,11 +5,10 @@ set -e
# Gives mqtt information
if bashio::services.available 'mqtt'; then
bashio::log.green "---"
bashio::log.yellow "MQTT addon is active on your system! Add the MQTT details below to the Birdnet-go config.yaml :"
bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")"
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")"
bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
bashio::log.green "---"
bashio::log.green "---"
bashio::log.yellow "MQTT addon is active on your system! Add the MQTT details below to the Birdnet-go config.yaml :"
bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")"
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")"
bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
bashio::log.green "---"
fi

View File

@@ -11,11 +11,11 @@ echo " "
# Adjust microphone volume if needed
if command -v amixer >/dev/null 2>/dev/null; then
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 || true
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 || true
fi
########################
@@ -24,10 +24,10 @@ fi
bashio::log.info "Starting app..."
# shellcheck disable=SC2086
/usr/bin/entrypoint.sh birdnet-go realtime & true
/usr/bin/entrypoint.sh birdnet-go realtime &
true
# Wait for app to become available to start nginx
bashio::net.wait_for 8080 localhost 900
bashio::log.info "Starting NGinx..."
exec nginx