mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 02:11:01 +01:00
fix: auto-fix linting issues
This commit is contained in:
committed by
github-actions[bot]
parent
3539f328fb
commit
f5428e0950
@@ -6,46 +6,46 @@ 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'
|
||||
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."
|
||||
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
|
||||
# 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
|
||||
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
|
||||
# Wait for both services to stop
|
||||
wait
|
||||
|
||||
# Create the destination directory
|
||||
mkdir -p /config/TemporaryFiles
|
||||
# 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
|
||||
# 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."
|
||||
bashio::log.info "... files safe, allowing container to stop."
|
||||
else
|
||||
bashio::log.info "No StreamData directory to process."
|
||||
bashio::log.info "No StreamData directory to process."
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
###############
|
||||
@@ -23,24 +23,24 @@ bashio::log.info "Ensuring the file structure is correct:"
|
||||
echo "... creating default files"
|
||||
DEFAULT_FILES=("apprise.txt" "exclude_species_list.txt" "IdentifiedSoFar.txt" "disk_check_exclude.txt" "confirmed_species_list.txt" "blacklisted_images.txt" "whitelist_species_list.txt")
|
||||
for file in "${DEFAULT_FILES[@]}"; do
|
||||
if [ ! -f "/config/$file" ]; then
|
||||
echo "" >"/config/$file"
|
||||
fi
|
||||
if [ ! -f "/config/$file" ]; then
|
||||
echo "" > "/config/$file"
|
||||
fi
|
||||
done
|
||||
touch /config/include_species_list.txt # Ensure this is always created
|
||||
|
||||
# Set BirdSongs folder location from configuration if specified
|
||||
BIRDSONGS_FOLDER="/config/BirdSongs"
|
||||
if bashio::config.has_value "BIRDSONGS_FOLDER"; then
|
||||
BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")"
|
||||
echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION"
|
||||
mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created"
|
||||
chown -R pi:pi "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be given permissions for 1000:1000"
|
||||
if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then
|
||||
BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION"
|
||||
else
|
||||
bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs"
|
||||
fi
|
||||
BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")"
|
||||
echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION"
|
||||
mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created"
|
||||
chown -R pi:pi "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be given permissions for 1000:1000"
|
||||
if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then
|
||||
BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION"
|
||||
else
|
||||
bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create default folders
|
||||
@@ -49,12 +49,12 @@ mkdir -p "$BIRDSONGS_FOLDER/By_Date" "$BIRDSONGS_FOLDER/Charts"
|
||||
|
||||
# Use tmpfs if installed
|
||||
if df -T /tmp | grep -q "tmpfs"; then
|
||||
echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear"
|
||||
mkdir -p /tmp/StreamData /tmp/Processed
|
||||
[ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData"
|
||||
[ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed"
|
||||
sudo -u pi ln -fs /tmp/StreamData "$HOME/BirdSongs/StreamData"
|
||||
sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed"
|
||||
echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear"
|
||||
mkdir -p /tmp/StreamData /tmp/Processed
|
||||
[ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData"
|
||||
[ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed"
|
||||
sudo -u pi ln -fs /tmp/StreamData "$HOME/BirdSongs/StreamData"
|
||||
sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed"
|
||||
fi
|
||||
|
||||
# Set permissions for created files and folders
|
||||
@@ -67,19 +67,19 @@ cp "$HOME/BirdNET-Pi/birdnet.conf" "$HOME/BirdNET-Pi/birdnet.bak"
|
||||
|
||||
# Create default birdnet.conf if not existing
|
||||
if [ ! -f /config/birdnet.conf ]; then
|
||||
cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/
|
||||
cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/
|
||||
fi
|
||||
|
||||
# Create default birds.db
|
||||
if [ ! -f /config/birds.db ]; then
|
||||
echo "... creating initial db"
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
echo "... creating initial db"
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
elif [ "$(stat -c%s /config/birds.db)" -lt 10240 ]; then
|
||||
echo "... your db is corrupted, creating new one"
|
||||
rm /config/birds.db
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
echo "... your db is corrupted, creating new one"
|
||||
rm /config/birds.db
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
fi
|
||||
|
||||
# Symlink configuration files
|
||||
@@ -87,12 +87,12 @@ echo "... creating symlinks for configuration files"
|
||||
CONFIG_FILES=("$HOME/BirdNET-Pi/birdnet.conf" "$HOME/BirdNET-Pi/scripts/whitelist_species_list.txt" "$HOME/BirdNET-Pi/blacklisted_images.txt" "$HOME/BirdNET-Pi/scripts/birds.db" "$HOME/BirdNET-Pi/BirdDB.txt" "$HOME/BirdNET-Pi/scripts/disk_check_exclude.txt" "$HOME/BirdNET-Pi/apprise.txt" "$HOME/BirdNET-Pi/exclude_species_list.txt" "$HOME/BirdNET-Pi/include_species_list.txt" "$HOME/BirdNET-Pi/IdentifiedSoFar.txt" "$HOME/BirdNET-Pi/scripts/confirmed_species_list.txt")
|
||||
|
||||
for file in "${CONFIG_FILES[@]}"; do
|
||||
filename="${file##*/}"
|
||||
[ ! -f "/config/$filename" ] && touch "/config/$filename"
|
||||
[ -e "$file" ] && rm "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$HOME/BirdNET-Pi/scripts/$filename"
|
||||
sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename"
|
||||
filename="${file##*/}"
|
||||
[ ! -f "/config/$filename" ] && touch "/config/$filename"
|
||||
[ -e "$file" ] && rm "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$HOME/BirdNET-Pi/scripts/$filename"
|
||||
sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename"
|
||||
done
|
||||
|
||||
# Create thisrun.txt for legacy modes
|
||||
@@ -106,9 +106,9 @@ chown pi:pi /usr/local/bin/*
|
||||
|
||||
# Symlink BirdSongs folders
|
||||
for folder in By_Date Charts; do
|
||||
echo "... creating symlink for $BIRDSONGS_FOLDER/$folder"
|
||||
[ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder"
|
||||
sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder"
|
||||
echo "... creating symlink for $BIRDSONGS_FOLDER/$folder"
|
||||
[ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder"
|
||||
sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder"
|
||||
done
|
||||
|
||||
# Set permissions for newly created files and folders
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
######################
|
||||
@@ -19,32 +19,32 @@ fi
|
||||
|
||||
if [ -d /config/TemporaryFiles ]; then
|
||||
|
||||
# Check if there are .wav files in /config/TemporaryFiles
|
||||
if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then
|
||||
bashio::log.warning "Container was stopped while files were still being analyzed."
|
||||
echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData."
|
||||
# Check if there are .wav files in /config/TemporaryFiles
|
||||
if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then
|
||||
bashio::log.warning "Container was stopped while files were still being analyzed."
|
||||
echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData."
|
||||
|
||||
# Create the destination directory if it does not exist
|
||||
mkdir -p "$HOME"/BirdSongs/StreamData
|
||||
# Create the destination directory if it does not exist
|
||||
mkdir -p "$HOME"/BirdSongs/StreamData
|
||||
|
||||
# Count the number of .wav files to be moved
|
||||
file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l)
|
||||
echo "... found $file_count .wav files to restore."
|
||||
# Count the number of .wav files to be moved
|
||||
file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l)
|
||||
echo "... found $file_count .wav files to restore."
|
||||
|
||||
# Move the .wav files using `mv` to avoid double log entries
|
||||
mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/
|
||||
# Move the .wav files using `mv` to avoid double log entries
|
||||
mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/
|
||||
|
||||
# Update permissions only if files were moved successfully
|
||||
if [ "$file_count" -gt 0 ]; then
|
||||
chown -R pi:pi "$HOME"/BirdSongs/StreamData
|
||||
fi
|
||||
# Update permissions only if files were moved successfully
|
||||
if [ "$file_count" -gt 0 ]; then
|
||||
chown -R pi:pi "$HOME"/BirdSongs/StreamData
|
||||
fi
|
||||
|
||||
echo "... $file_count files restored successfully."
|
||||
else
|
||||
echo "... no .wav files found to restore."
|
||||
fi
|
||||
echo "... $file_count files restored successfully."
|
||||
else
|
||||
echo "... no .wav files found to restore."
|
||||
fi
|
||||
|
||||
# Clean up the source folder if it is empty
|
||||
rm -r /config/TemporaryFiles
|
||||
# Clean up the source folder if it is empty
|
||||
rm -r /config/TemporaryFiles
|
||||
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
######################
|
||||
@@ -25,22 +25,22 @@ configtemplate="$HOME"/BirdNET-Pi/birdnet.bak
|
||||
|
||||
# Ensure both files exist before proceeding
|
||||
if [ ! -f "$configcurrent" ] || [ ! -f "$configtemplate" ]; then
|
||||
bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present."
|
||||
exit 1
|
||||
bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract variable names from config template and read each one
|
||||
grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do
|
||||
# Check if the variable is in configcurrent, if not, append it
|
||||
if ! grep -q "^$var=" "$configcurrent"; then
|
||||
bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added"
|
||||
grep "^$var=" "$configtemplate" >>"$configcurrent"
|
||||
fi
|
||||
# Check for duplicates
|
||||
if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then
|
||||
bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one"
|
||||
sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent"
|
||||
fi
|
||||
# Check if the variable is in configcurrent, if not, append it
|
||||
if ! grep -q "^$var=" "$configcurrent"; then
|
||||
bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added"
|
||||
grep "^$var=" "$configtemplate" >> "$configcurrent"
|
||||
fi
|
||||
# Check for duplicates
|
||||
if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then
|
||||
bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one"
|
||||
sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent"
|
||||
fi
|
||||
done
|
||||
|
||||
##############
|
||||
@@ -48,8 +48,8 @@ done
|
||||
##############
|
||||
|
||||
if [[ "$(bashio::addon.port "80")" == 3000 ]]; then
|
||||
bashio::log.fatal "This is crazy but your port is set to 3000 and streamlit doesn't accept this port! You need to change it from the addon options and restart. Thanks"
|
||||
sleep infinity
|
||||
bashio::log.fatal "This is crazy but your port is set to 3000 and streamlit doesn't accept this port! You need to change it from the addon options and restart. Thanks"
|
||||
sleep infinity
|
||||
fi
|
||||
|
||||
##################
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
############
|
||||
@@ -19,66 +19,66 @@ fi
|
||||
|
||||
# Function to perform common setup steps
|
||||
common_steps() {
|
||||
# Attempt to connect to the MQTT broker
|
||||
TOPIC="birdnet"
|
||||
if mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "test" -u "$MQTT_USER" -P "$MQTT_PASS" -q 1 -d --will-topic "$TOPIC" --will-payload "Disconnected" --will-qos 1 --will-retain >/dev/null 2>&1; then
|
||||
# Adapt script with MQTT settings
|
||||
sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|\"%%mqtt_port%%\"|$MQTT_PORT|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_pass%%|$MQTT_PASS|g" /helpers/birdnet_to_mqtt.py
|
||||
# Attempt to connect to the MQTT broker
|
||||
TOPIC="birdnet"
|
||||
if mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "test" -u "$MQTT_USER" -P "$MQTT_PASS" -q 1 -d --will-topic "$TOPIC" --will-payload "Disconnected" --will-qos 1 --will-retain > /dev/null 2>&1; then
|
||||
# Adapt script with MQTT settings
|
||||
sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|\"%%mqtt_port%%\"|$MQTT_PORT|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_pass%%|$MQTT_PASS|g" /helpers/birdnet_to_mqtt.py
|
||||
|
||||
# Copy script to the appropriate directory
|
||||
cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chmod +x "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
# Copy script to the appropriate directory
|
||||
cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chmod +x "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
|
||||
# Add hooks to the main analysis script
|
||||
sed -i "/load_global_model, run_analysis/a from utils.birdnet_to_mqtt import automatic_mqtt_publish" "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
sed -i '/write_to_db(/a\ automatic_mqtt_publish(file, detection, os.path.basename(detection.file_name_extr))' "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
else
|
||||
bashio::log.fatal "MQTT connection failed, it will not be configured"
|
||||
fi
|
||||
# Add hooks to the main analysis script
|
||||
sed -i "/load_global_model, run_analysis/a from utils.birdnet_to_mqtt import automatic_mqtt_publish" "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
sed -i '/write_to_db(/a\ automatic_mqtt_publish(file, detection, os.path.basename(detection.file_name_extr))' "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
else
|
||||
bashio::log.fatal "MQTT connection failed, it will not be configured"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if MQTT service is available and not disabled
|
||||
if [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::services.available 'mqtt' && ! bashio::config.true 'MQTT_DISABLED'; then
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT addon is active on your system! Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
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.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT addon is active on your system! Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
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.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
|
||||
# Apply MQTT settings
|
||||
MQTT_HOST="$(bashio::services "mqtt" "host")"
|
||||
MQTT_PORT="$(bashio::services "mqtt" "port")"
|
||||
MQTT_USER="$(bashio::services "mqtt" "username")"
|
||||
MQTT_PASS="$(bashio::services "mqtt" "password")"
|
||||
# Apply MQTT settings
|
||||
MQTT_HOST="$(bashio::services "mqtt" "host")"
|
||||
MQTT_PORT="$(bashio::services "mqtt" "port")"
|
||||
MQTT_USER="$(bashio::services "mqtt" "username")"
|
||||
MQTT_PASS="$(bashio::services "mqtt" "password")"
|
||||
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
|
||||
# Check if manual MQTT configuration is provided
|
||||
elif [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::config.has_value "MQTT_HOST_manual" && bashio::config.has_value "MQTT_PORT_manual"; then
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT is manually configured in the addon options"
|
||||
bashio::log.blue "Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT is manually configured in the addon options"
|
||||
bashio::log.blue "Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
|
||||
# Apply manual MQTT settings
|
||||
MQTT_HOST="$(bashio::config "MQTT_HOST_manual")"
|
||||
MQTT_PORT="$(bashio::config "MQTT_PORT_manual")"
|
||||
MQTT_USER="$(bashio::config "MQTT_USER_manual")"
|
||||
MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")"
|
||||
# Apply manual MQTT settings
|
||||
MQTT_HOST="$(bashio::config "MQTT_HOST_manual")"
|
||||
MQTT_PORT="$(bashio::config "MQTT_PORT_manual")"
|
||||
MQTT_USER="$(bashio::config "MQTT_USER_manual")"
|
||||
MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")"
|
||||
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
################
|
||||
@@ -22,21 +22,21 @@ bashio::log.info "Adapting webui"
|
||||
# HA specific elements
|
||||
######################
|
||||
|
||||
if bashio::supervisor.ping 2>/dev/null; then
|
||||
# Remove services tab from webui
|
||||
echo "... removing System Controls from webui as should be used from HA"
|
||||
sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
if bashio::supervisor.ping 2> /dev/null; then
|
||||
# Remove services tab from webui
|
||||
echo "... removing System Controls from webui as should be used from HA"
|
||||
sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
|
||||
# Remove pulseaudio
|
||||
echo "... disabling pulseaudio as managed by HomeAssistant"
|
||||
grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do
|
||||
sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file"
|
||||
done
|
||||
# Remove pulseaudio
|
||||
echo "... disabling pulseaudio as managed by HomeAssistant"
|
||||
grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do
|
||||
sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file"
|
||||
done
|
||||
|
||||
# Check if port 80 is correctly configured
|
||||
if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then
|
||||
bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work."
|
||||
fi
|
||||
# Check if port 80 is correctly configured
|
||||
if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then
|
||||
bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work."
|
||||
fi
|
||||
fi
|
||||
|
||||
# General elements
|
||||
@@ -45,25 +45,25 @@ fi
|
||||
# Remove Ram drive option from webui
|
||||
echo "... removing Ram drive from webui as it is handled from HA"
|
||||
if grep -q "Ram drive" "$HOME/BirdNET-Pi/scripts/service_controls.php"; then
|
||||
sed -i '/Ram drive/{n;s/center"/center" style="display: none;"/;}' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
sed -i '/Ram drive/d' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
sed -i '/Ram drive/{n;s/center"/center" style="display: none;"/;}' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
sed -i '/Ram drive/d' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
fi
|
||||
|
||||
# Allow symlinks
|
||||
echo "... ensuring symlinks work"
|
||||
for files in "$HOME"/BirdNET-Pi/scripts/*.sh; do
|
||||
sed -i "s|find |find -L |g" "$files"
|
||||
sed -i "s|find -L -L |find -L |g" "$files"
|
||||
sed -i "s|find |find -L |g" "$files"
|
||||
sed -i "s|find -L -L |find -L |g" "$files"
|
||||
done
|
||||
|
||||
# Correct services to start as user pi
|
||||
echo "... updating services to start as user pi"
|
||||
if ! grep -q "/usr/bin/sudo" "$HOME/BirdNET-Pi/templates/birdnet_analysis.service"; then
|
||||
while IFS= read -r file; do
|
||||
if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then
|
||||
sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file"
|
||||
fi
|
||||
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print)
|
||||
while IFS= read -r file; do
|
||||
if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then
|
||||
sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file"
|
||||
fi
|
||||
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print)
|
||||
fi
|
||||
|
||||
# Allow pulseaudio system
|
||||
@@ -73,16 +73,16 @@ sed -i 's#pulseaudio --start#pulseaudio --start 2>/dev/null && pulseaudio --chec
|
||||
# Send services log to container logs
|
||||
echo "... redirecting services logs to container logs"
|
||||
while IFS= read -r file; do
|
||||
sed -i "/StandardError/d" "$file"
|
||||
sed -i "/StandardOutput/d" "$file"
|
||||
sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$file"
|
||||
sed -i "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file"
|
||||
sed -i "/StandardError/d" "$file"
|
||||
sed -i "/StandardOutput/d" "$file"
|
||||
sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$file"
|
||||
sed -i "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file"
|
||||
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*.service" -print)
|
||||
|
||||
# Preencode API key
|
||||
if [[ -f "$HOME/BirdNET-Pi/scripts/common.php" ]] && ! grep -q "221160312" "$HOME/BirdNET-Pi/scripts/common.php"; then
|
||||
sed -i "/return \$_SESSION\['my_config'\];/i\ \ \ \ if (isset(\$_SESSION\['my_config'\]) \&\& empty(\$_SESSION\['my_config'\]\['FLICKR_API_KEY'\])) {\n\ \ \ \ \ \ \ \ \$_SESSION\['my_config'\]\['FLICKR_API_KEY'\] = \"221160312e1c22\";\n\ \ \ \ }" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
sed -i "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
sed -i "/return \$_SESSION\['my_config'\];/i\ \ \ \ if (isset(\$_SESSION\['my_config'\]) \&\& empty(\$_SESSION\['my_config'\]\['FLICKR_API_KEY'\])) {\n\ \ \ \ \ \ \ \ \$_SESSION\['my_config'\]\['FLICKR_API_KEY'\] = \"221160312e1c22\";\n\ \ \ \ }" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
sed -i "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
fi
|
||||
|
||||
# Correct log services to show /proc/1/fd/1
|
||||
@@ -92,8 +92,8 @@ sed -i "s|birdnet_log.sh|cat /proc/1/fd/1|g" "$HOME/BirdNET-Pi/templates/birdnet
|
||||
|
||||
# Correct backup script
|
||||
if [[ -f "$HOME/BirdNET-Pi/scripts/backup_data.sh" ]]; then
|
||||
echo "... correct backup script"
|
||||
sed -i "/PHP_SERVICE=/c PHP_SERVICE=\$(systemctl list-unit-files -t service --no-pager | grep 'php' | grep 'fpm' | awk '{print \$1}')" "$HOME/BirdNET-Pi/scripts/backup_data.sh"
|
||||
echo "... correct backup script"
|
||||
sed -i "/PHP_SERVICE=/c PHP_SERVICE=\$(systemctl list-unit-files -t service --no-pager | grep 'php' | grep 'fpm' | awk '{print \$1}')" "$HOME/BirdNET-Pi/scripts/backup_data.sh"
|
||||
fi
|
||||
|
||||
# Caddyfile modifications
|
||||
@@ -101,27 +101,27 @@ echo "... modifying Caddyfile configurations"
|
||||
caddy fmt --overwrite /etc/caddy/Caddyfile
|
||||
#Change port to leave 80 free for certificate requests
|
||||
if ! grep -q "http://:8081" /etc/caddy/Caddyfile; then
|
||||
sed -i "s|http://|http://:8081|g" /etc/caddy/Caddyfile
|
||||
sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f /etc/caddy/Caddyfile.original ]; then
|
||||
rm /etc/caddy/Caddyfile.original
|
||||
fi
|
||||
sed -i "s|http://|http://:8081|g" /etc/caddy/Caddyfile
|
||||
sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f /etc/caddy/Caddyfile.original ]; then
|
||||
rm /etc/caddy/Caddyfile.original
|
||||
fi
|
||||
fi
|
||||
|
||||
# Correct webui paths
|
||||
echo "... correcting webui paths"
|
||||
if ! grep -q "/stats/" "$HOME/BirdNET-Pi/homepage/views.php"; then
|
||||
sed -i "s|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
sed -i "s|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
fi
|
||||
|
||||
# Correct systemctl path
|
||||
if [ -f /helpers/systemctl ] && [ -f /helpers/journalctl ]; then
|
||||
echo "... updating systemctl and journalctl"
|
||||
cp -rf /helpers/systemctl /bin/systemctl
|
||||
cp -rf /helpers/journalctl /bin/journalctl
|
||||
chown pi:pi /bin/systemctl /bin/journalctl
|
||||
chmod a+x /bin/systemctl /bin/journalctl
|
||||
echo "... updating systemctl and journalctl"
|
||||
cp -rf /helpers/systemctl /bin/systemctl
|
||||
cp -rf /helpers/journalctl /bin/journalctl
|
||||
chown pi:pi /bin/systemctl /bin/journalctl
|
||||
chmod a+x /bin/systemctl /bin/journalctl
|
||||
fi
|
||||
|
||||
# Allow reverse proxy for streamlit
|
||||
@@ -130,34 +130,34 @@ sed -i "s|plotly_streamlit.py --browser.gatherUsageStats|plotly_streamlit.py --s
|
||||
|
||||
# Clean saved mp3 files
|
||||
if [[ -f "$HOME/BirdNET-Pi/scripts/utils/reporting.py" ]]; then
|
||||
echo ".. add highpass and lowpass to sox extracts"
|
||||
sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py"
|
||||
echo ".. add highpass and lowpass to sox extracts"
|
||||
sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py"
|
||||
fi
|
||||
|
||||
# Correct timedatectl path
|
||||
echo "... updating timedatectl path"
|
||||
if [[ -f /helpers/timedatectl ]]; then
|
||||
mv /helpers/timedatectl /usr/bin/timedatectl
|
||||
chown pi:pi /usr/bin/timedatectl
|
||||
chmod a+x /usr/bin/timedatectl
|
||||
mv /helpers/timedatectl /usr/bin/timedatectl
|
||||
chown pi:pi /usr/bin/timedatectl
|
||||
chmod a+x /usr/bin/timedatectl
|
||||
fi
|
||||
|
||||
# Set RECS_DIR
|
||||
echo "... setting RECS_DIR to /tmp"
|
||||
grep -rl "RECS_DIR" "$HOME" --exclude="*.php" | while read -r file; do
|
||||
sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$file"
|
||||
sed -i "s|\$RECS_DIR|/tmp|g" "$file"
|
||||
sed -i "s|\${RECS_DIR}|/tmp|g" "$file"
|
||||
sed -i "/^RECS_DIR=/c RECS_DIR=/tmp" "$file"
|
||||
sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file"
|
||||
sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$file"
|
||||
sed -i "s|\$RECS_DIR|/tmp|g" "$file"
|
||||
sed -i "s|\${RECS_DIR}|/tmp|g" "$file"
|
||||
sed -i "/^RECS_DIR=/c RECS_DIR=/tmp" "$file"
|
||||
sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file"
|
||||
done
|
||||
mkdir -p /tmp
|
||||
|
||||
# Correct language labels according to birdnet.conf
|
||||
echo "... adapting labels according to birdnet.conf"
|
||||
if export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"; then
|
||||
bashio::log.info "Setting language to ${DATABASE_LANG:-en}"
|
||||
"$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &>/dev/null || bashio::log.warning "Failed to update language labels"
|
||||
bashio::log.info "Setting language to ${DATABASE_LANG:-en}"
|
||||
"$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &> /dev/null || bashio::log.warning "Failed to update language labels"
|
||||
else
|
||||
bashio::log.warning "DATABASE_LANG not found in configuration. Using default labels."
|
||||
bashio::log.warning "DATABASE_LANG not found in configuration. Using default labels."
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
#################
|
||||
@@ -24,9 +24,9 @@ ingress_entry=$(bashio::addon.ingress_entry)
|
||||
|
||||
# Quits if ingress is not active
|
||||
if [[ "$ingress_entry" != "/api"* ]]; then
|
||||
bashio::log.info "Ingress entry is not set, exiting configuration."
|
||||
sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh
|
||||
exit 0
|
||||
bashio::log.info "Ingress entry is not set, exiting configuration."
|
||||
sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh
|
||||
exit 0
|
||||
fi
|
||||
|
||||
bashio::log.info "Adapting for ingress"
|
||||
@@ -35,26 +35,26 @@ echo "... setting up nginx"
|
||||
# Check if the NGINX configuration file exists
|
||||
nginx_conf="/etc/nginx/servers/ingress.conf"
|
||||
if [ -f "$nginx_conf" ]; then
|
||||
sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf"
|
||||
sed -i "s/%%interface%%/${ingress_interface}/g" "$nginx_conf"
|
||||
sed -i "s|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf"
|
||||
sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf"
|
||||
sed -i "s/%%interface%%/${ingress_interface}/g" "$nginx_conf"
|
||||
sed -i "s|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf"
|
||||
else
|
||||
bashio::log.error "NGINX configuration file not found: $nginx_conf"
|
||||
exit 1
|
||||
bashio::log.error "NGINX configuration file not found: $nginx_conf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Disable log
|
||||
sed -i "/View Log/d" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
|
||||
echo "... ensuring restricted area access"
|
||||
echo "${ingress_entry}" >/ingress_url
|
||||
echo "${ingress_entry}" > /ingress_url
|
||||
|
||||
# Modify PHP file safely
|
||||
php_file="$HOME/BirdNET-Pi/scripts/common.php"
|
||||
if [ -f "$php_file" ]; then
|
||||
sed -i "/function is_authenticated/a if (strpos(\$_SERVER['HTTP_REFERER'], '/api/hassio_ingress') !== false && strpos(\$_SERVER['HTTP_REFERER'], trim(file_get_contents('/ingress_url'))) !== false) { \$ret = true; return \$ret; }" "$php_file"
|
||||
sed -i "/function is_authenticated/a if (strpos(\$_SERVER['HTTP_REFERER'], '/api/hassio_ingress') !== false && strpos(\$_SERVER['HTTP_REFERER'], trim(file_get_contents('/ingress_url'))) !== false) { \$ret = true; return \$ret; }" "$php_file"
|
||||
else
|
||||
bashio::log.warning "PHP file not found: $php_file"
|
||||
bashio::log.warning "PHP file not found: $php_file"
|
||||
fi
|
||||
|
||||
echo "... adapting Caddyfile for ingress"
|
||||
@@ -66,8 +66,8 @@ chmod +x /helpers/caddy_ingress.sh
|
||||
# Update the Caddyfile if update script exists
|
||||
caddy_update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f "$caddy_update_script" ]; then
|
||||
sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script"
|
||||
sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script"
|
||||
else
|
||||
bashio::log.error "Caddy update script not found: $caddy_update_script"
|
||||
exit 1
|
||||
bashio::log.error "Caddy update script not found: $caddy_update_script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
###############
|
||||
@@ -18,32 +18,32 @@ fi
|
||||
###############
|
||||
|
||||
if bashio::config.true 'ssl'; then
|
||||
bashio::log.info "SSL is enabled using addon options, setting up NGINX and Caddy."
|
||||
bashio::log.info "SSL is enabled using addon options, setting up NGINX and Caddy."
|
||||
|
||||
# Check required SSL configurations
|
||||
bashio::config.require.ssl
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
# Check required SSL configurations
|
||||
bashio::config.require.ssl
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
|
||||
# Ensure Caddyfile exists before modifying
|
||||
caddyfile="/etc/caddy/Caddyfile"
|
||||
if [ -f "$caddyfile" ]; then
|
||||
sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile"
|
||||
sed -i "s|http://:8081|https://:8081|g" "$caddyfile"
|
||||
else
|
||||
bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration."
|
||||
exit 1
|
||||
fi
|
||||
# Ensure Caddyfile exists before modifying
|
||||
caddyfile="/etc/caddy/Caddyfile"
|
||||
if [ -f "$caddyfile" ]; then
|
||||
sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile"
|
||||
sed -i "s|http://:8081|https://:8081|g" "$caddyfile"
|
||||
else
|
||||
bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure update_caddyfile.sh exists before modifying
|
||||
update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f "$update_script" ]; then
|
||||
sed -i "s|http://:8081|https://:8081|g" "$update_script"
|
||||
if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then
|
||||
sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"
|
||||
fi
|
||||
else
|
||||
bashio::log.error "Update script not found: $update_script, skipping SSL setup for update."
|
||||
exit 1
|
||||
fi
|
||||
# Ensure update_caddyfile.sh exists before modifying
|
||||
update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f "$update_script" ]; then
|
||||
sed -i "s|http://:8081|https://:8081|g" "$update_script"
|
||||
if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then
|
||||
sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"
|
||||
fi
|
||||
else
|
||||
bashio::log.error "Update script not found: $update_script, skipping SSL setup for update."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
######################
|
||||
@@ -19,19 +19,19 @@ fi
|
||||
|
||||
# Check if the CPU supports AVX2
|
||||
if [[ "$(uname -m)" = "x86_64" ]]; then
|
||||
if lscpu | grep -q "Flags"; then
|
||||
if ! lscpu | grep -q "avx2"; then
|
||||
bashio::log.warning "NON SUPPORTED CPU DETECTED"
|
||||
bashio::log.warning "Your cpu doesn't support avx2, the analyzer service will likely won't work"
|
||||
bashio::log.warning "Trying to install tensorflow instead of tflite_runtime instead. This might take some time (up to 5 minutes)."
|
||||
bashio::log.warning "You could try also Birdnet-Go which should supports your cpu"
|
||||
source /home/pi/BirdNET-Pi/birdnet/bin/activate
|
||||
mkdir -p /home/pi/.cache/pip || true &>/dev/null
|
||||
chmod 777 /home/pi/.cache/pip || true &>/dev/null
|
||||
pip3 uninstall -y tflite_runtime
|
||||
pip install --upgrade packaging==23.2
|
||||
pip3 install --upgrade --force-reinstall "https://github.com/snowzach/tensorflow-multiarch/releases/download/v2.16.1/tensorflow-2.16.1-cp311-cp311-linux_x86_64.whl"
|
||||
deactivate
|
||||
fi
|
||||
fi
|
||||
if lscpu | grep -q "Flags"; then
|
||||
if ! lscpu | grep -q "avx2"; then
|
||||
bashio::log.warning "NON SUPPORTED CPU DETECTED"
|
||||
bashio::log.warning "Your cpu doesn't support avx2, the analyzer service will likely won't work"
|
||||
bashio::log.warning "Trying to install tensorflow instead of tflite_runtime instead. This might take some time (up to 5 minutes)."
|
||||
bashio::log.warning "You could try also Birdnet-Go which should supports your cpu"
|
||||
source /home/pi/BirdNET-Pi/birdnet/bin/activate
|
||||
mkdir -p /home/pi/.cache/pip || true &> /dev/null
|
||||
chmod 777 /home/pi/.cache/pip || true &> /dev/null
|
||||
pip3 uninstall -y tflite_runtime
|
||||
pip install --upgrade packaging==23.2
|
||||
pip3 install --upgrade --force-reinstall "https://github.com/snowzach/tensorflow-multiarch/releases/download/v2.16.1/tensorflow-2.16.1-cp311-cp311-linux_x86_64.whl"
|
||||
deactivate
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -8,10 +8,10 @@ set -eu
|
||||
##################
|
||||
|
||||
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/
|
||||
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
|
||||
|
||||
##############
|
||||
@@ -21,71 +21,71 @@ fi
|
||||
# Set password
|
||||
bashio::log.info "Setting password for the user pi"
|
||||
if bashio::config.has_value "pi_password"; then
|
||||
echo "pi:$(bashio::config "pi_password")" | chpasswd
|
||||
echo "pi:$(bashio::config "pi_password")" | chpasswd
|
||||
fi
|
||||
bashio::log.info "Password set successfully for user pi."
|
||||
|
||||
# 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
|
||||
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
|
||||
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
|
||||
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
|
||||
bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD"
|
||||
for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file"
|
||||
fi
|
||||
done
|
||||
bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD"
|
||||
for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Fix timezone as per installer
|
||||
CURRENT_TIMEZONE="$(timedatectl show --value --property=Timezone)"
|
||||
[ -f /etc/timezone ] && echo "$CURRENT_TIMEZONE" | sudo tee /etc/timezone >/dev/null
|
||||
[ -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
|
||||
systemctl start cron > /dev/null
|
||||
|
||||
bashio::log.info "Starting dbus service"
|
||||
service dbus start >/dev/null
|
||||
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
|
||||
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
|
||||
echo "... starting livestream services"
|
||||
systemctl enable icecast2 > /dev/null
|
||||
systemctl start icecast2.service > /dev/null
|
||||
systemctl enable --now livestream.service > /dev/null
|
||||
fi
|
||||
|
||||
# Start
|
||||
|
||||
Reference in New Issue
Block a user