Files
hassio-addons/birdnet-pi-zach/rootfs/etc/cont-finish.d/savestreamdata.sh
Claude Code 748bcc7df1 Add birdnet-pi-zach addon (zach7036/BirdNET-Pi-Enhanced-Version fork)
Creates a new Home Assistant add-on that installs from zach7036's BirdNET-Pi-Enhanced-Version fork instead of the Nachtzuster/alexbelgium fork. Leaves the existing birdnet-pi addon untouched.

Key changes from birdnet-pi:
- Installer repointed to zach7036/BirdNET-Pi-Enhanced-Version/main/newinstaller.sh
- Removed alexbelgium repo rename sed (zach7036 fork already clones itself)
- Removed merge_open_prs PR-merging step (install stable main)
- Updated slug to birdnet-pi-zach, image to birdnet-pi-zach-{arch}
- Updated README/docs upstream description
- Unique apparmor profile name

The generic Dockerfile patches (strip sudo, remap my_dir, systemctl shims) apply unchanged to the new fork since it follows standard BirdNET-Pi layout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-10 10:30:04 +02:00

52 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# Maximum file size in bytes (50MB)
MAX_SIZE=$((50 * 1024 * 1024))
# Function to check if a file is a valid WAV
is_valid_wav() {
local file="$1"
# Check if the file contains a valid WAV header
file "$file" | grep -qE 'WAVE audio'
}
if [ -d "$HOME"/BirdSongs/StreamData ]; then
bashio::log.fatal "Container stopping, saving temporary files."
# Stop the services in parallel
if systemctl is-active --quiet birdnet_analysis; then
bashio::log.info "Stopping birdnet_analysis service."
systemctl stop birdnet_analysis &
fi
if systemctl is-active --quiet birdnet_recording; then
bashio::log.info "Stopping birdnet_recording service."
systemctl stop birdnet_recording &
fi
# Wait for both services to stop
wait
# Create the destination directory
mkdir -p /config/TemporaryFiles
# Move only valid WAV files under 50MB
shopt -s nullglob # Prevent errors if no files match
for file in "$HOME"/BirdSongs/StreamData/*.wav; do
if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then
if mv -v "$file" /config/TemporaryFiles/; then
bashio::log.info "Moved valid WAV file: $(basename "$file")"
else
bashio::log.error "Failed to move: $(basename "$file")"
fi
else
bashio::log.warning "Skipping invalid or large file: $(basename "$file")"
fi
done
bashio::log.info "... files safe, allowing container to stop."
else
bashio::log.info "No StreamData directory to process."
fi