mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-14 13:49:09 +02:00
* fix(birdnet-pi): turn ALSA_CARD into a valid ALSA PCM name for REC_CARD 99-run.sh copied ALSA_CARD verbatim into REC_CARD, but BirdNET-Pi passes REC_CARD to "arecord -D" (scripts/birdnet_recording.sh) and "ffmpeg -f alsa -i" (scripts/livestream.sh), which expect an ALSA PCM name. A card index such as ALSA_CARD=1 therefore produced "Unknown PCM 1" and no recording at all. Build "plughw:CARD=<value>,DEV=0" from a card index or card id, and pass through a value that already is a PCM name. Also use sed --follow-symlinks so the rewrite no longer replaces the ~/BirdNET-Pi/birdnet.conf symlink with a detached copy of /config/birdnet.conf. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix: address CodeRabbit review * fix(birdnet-pi): bump version so the ALSA_CARD fix actually ships The PR changed 99-run.sh and added a CHANGELOG entry but left config.yaml untouched, so `version` still read 2026.08.02. Supervisor only offers a rebuild when `version` changes: without this the fix would have merged, the add-on would have kept running the old image, and the issue would have looked closed while ALSA_CARD stayed broken. 2026.08.15 matches the CHANGELOG heading this PR already adds, which is this add-on's convention — every past version lines up with a dated heading (2026.08.02, 2026.07.22, ...). Not a `.N` counter bump: birdnet-pi's `version` has drifted from updater.json's `upstream_version` (0.11), so the counter rule does not apply and the add-on's own date scheme governs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(birdnet-pi-zach): turn ALSA_CARD into a valid ALSA PCM name for REC_CARD birdnet-pi-zach/rootfs/etc/cont-init.d/99-run.sh carried a byte-identical copy of the same bug fixed in birdnet-pi by this PR: REC_CARD was copied verbatim from ALSA_CARD, but BirdNET-Pi passes REC_CARD to "arecord -D" and "ffmpeg -f alsa -i", which expect an ALSA PCM name, not a card index. sed -i also replaced the $HOME/BirdNET-Pi/birdnet.conf symlink with a detached copy on first use. Apply the same fix: build "plughw:CARD=<value>,DEV=0" from a card index or card id, pass through a value that already is a PCM name, and use sed --follow-symlinks against /config/birdnet.conf only. Documented in README_standalone.md, same as birdnet-pi. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix: resolve ALSA_CARD against real PCM names, not a fixed allowlist CodeRabbit and Codex both flagged that the passthrough check only recognized default/null/pulse/pipewire: any other colon-free ALSA PCM name (sysdefault, front, surround51, a custom .asoundrc alias, ...) was still misread as a card index/id and rewritten as plughw:CARD=<name>,DEV=0, which then fails to open. alsa-utils is already installed in both images, so check the value against "arecord -L" (an exact, whole-line match against its unindented PCM-name lines) instead of hardcoding the set of names ALSA ships with. Anything that isn't a real PCM name still falls through to the plughw:CARD= build, so a numeric index or a card id is handled exactly as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
122 lines
4.8 KiB
Bash
Executable File
122 lines
4.8 KiB
Bash
Executable File
#!/command/with-contenv bashio
|
|
# shellcheck shell=bash
|
|
|
|
set -eu
|
|
|
|
##################
|
|
# ALLOW RESTARTS #
|
|
##################
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
|
mkdir -p /etc/scripts-init
|
|
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
|
sed -i "/ rm/d" /ha_entrypoint.sh
|
|
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
|
fi
|
|
|
|
##############
|
|
# SET SYSTEM #
|
|
##############
|
|
|
|
# Set password
|
|
bashio::log.info "Setting password for the user pi"
|
|
if bashio::config.has_value "pi_password"; then
|
|
PI_PASSWORD="$(bashio::config "pi_password")"
|
|
elif [[ -n "${pi_password:-}" ]]; then
|
|
PI_PASSWORD="${pi_password}"
|
|
fi
|
|
|
|
if [[ -n "${PI_PASSWORD:-}" ]]; then
|
|
echo "pi:${PI_PASSWORD}" | chpasswd
|
|
bashio::log.info "Password set successfully for user pi."
|
|
else
|
|
# Set empty password to allow web terminal login when no password is configured
|
|
passwd -d pi
|
|
bashio::log.info "No password specified for user pi. Enabled passwordless login."
|
|
fi
|
|
|
|
# Use timezone defined in add-on options if available
|
|
bashio::log.info "Setting timezone :"
|
|
if bashio::config.has_value 'TZ'; then
|
|
TZ_VALUE="$(bashio::config 'TZ')"
|
|
if timedatectl set-timezone "$TZ_VALUE"; then
|
|
echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)."
|
|
else
|
|
bashio::log.warning "Couldn't set timezone to $TZ_VALUE. Refer to the list of valid timezones: https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html"
|
|
timedatectl set-ntp true &> /dev/null
|
|
fi
|
|
# Use BirdNET-defined timezone if no add-on option is provided
|
|
elif [ -f /data/timezone ]; then
|
|
BIRDN_CONFIG_TZ="$(cat /data/timezone)"
|
|
timedatectl set-ntp false &> /dev/null
|
|
if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then
|
|
echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config."
|
|
else
|
|
bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone."
|
|
timedatectl set-ntp true &> /dev/null
|
|
fi
|
|
# Fallback to automatic timezone if no manual settings are found
|
|
else
|
|
if timedatectl set-ntp true &> /dev/null; then
|
|
bashio::log.info "... automatic timezone enabled."
|
|
else
|
|
bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options."
|
|
fi
|
|
fi || true
|
|
|
|
# Use ALSA CARD defined in add-on options if available
|
|
if [ -n "${ALSA_CARD:-}" ]; then
|
|
# REC_CARD is passed as-is to "arecord -D" (scripts/birdnet_recording.sh) and to
|
|
# "ffmpeg -f alsa -i" (scripts/livestream.sh), so it must be an ALSA PCM name.
|
|
# ALSA_CARD holds a card index (1) or a card id (Audio), which are not PCM names:
|
|
# writing them as-is gives "Unknown PCM 1" and no recording at all. Build a PCM
|
|
# name from them, unless the value already is one of ALSA's own PCM names
|
|
# (checked against "arecord -L", e.g. default, null, pulse, sysdefault, front...).
|
|
if [[ "$ALSA_CARD" == *:* ]] || arecord -L 2> /dev/null | grep -qx "$ALSA_CARD"; then
|
|
REC_CARD="$ALSA_CARD"
|
|
else
|
|
REC_CARD="plughw:CARD=${ALSA_CARD},DEV=0"
|
|
fi
|
|
bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapted to use device $REC_CARD"
|
|
# --follow-symlinks : $HOME/BirdNET-Pi/birdnet.conf is a symlink to /config/birdnet.conf
|
|
# (01-structure.sh), and sed -i would replace it with a regular file, detaching it from
|
|
# the file the WebUI writes to. Only /config/birdnet.conf is updated directly, since the
|
|
# home-path symlink is writable by the pi/caddy user and could be repointed before this
|
|
# root-run script gets to it.
|
|
if [ -f /config/birdnet.conf ]; then
|
|
sed -i --follow-symlinks "/^REC_CARD/c\REC_CARD=$REC_CARD" /config/birdnet.conf
|
|
fi
|
|
fi
|
|
|
|
# Define permissions for audio
|
|
AUDIO_GID=$(stat -c %g /dev/snd/* | head -n1) \
|
|
&& (groupmod -o -g "$AUDIO_GID" audio 2> /dev/null || groupadd -o -g "$AUDIO_GID" audio || true) \
|
|
&& usermod -aG audio "${USER:-pi}" || true
|
|
|
|
# Fix timezone as per installer
|
|
CURRENT_TIMEZONE="$(timedatectl show --value --property=Timezone)"
|
|
[ -f /etc/timezone ] && echo "$CURRENT_TIMEZONE" | sudo tee /etc/timezone > /dev/null
|
|
|
|
bashio::log.info "Starting system services"
|
|
|
|
bashio::log.info "Starting cron service"
|
|
systemctl start cron > /dev/null
|
|
|
|
bashio::log.info "Starting dbus service"
|
|
service dbus start > /dev/null
|
|
|
|
bashio::log.info "Starting BirdNET-Pi services"
|
|
chmod +x "$HOME/BirdNET-Pi/scripts/restart_services.sh" > /dev/null
|
|
"$HOME/BirdNET-Pi/scripts/restart_services.sh" > /dev/null
|
|
|
|
# Start livestream services if enabled in configuration
|
|
if bashio::config.true "LIVESTREAM_BOOT_ENABLED"; then
|
|
echo "... starting livestream services"
|
|
systemctl enable icecast2 > /dev/null
|
|
systemctl start icecast2.service > /dev/null
|
|
systemctl enable --now livestream.service > /dev/null
|
|
fi
|
|
|
|
# Start
|
|
bashio::log.info "✅ Setup complete."
|