Leaner code

This commit is contained in:
Alexandre
2024-10-05 10:23:09 +02:00
committed by GitHub
parent 2fde15678a
commit c1ce391313

View File

@@ -7,24 +7,29 @@ set -e
###################### ######################
echo " " echo " "
bashio::log.info "Checking your birndet.conf file integrity" bashio::log.info "Checking your birdnet.conf file integrity"
# Set variables # Set variables
configcurrent="$HOME"/BirdNET-Pi/birdnet.conf configcurrent="$HOME"/BirdNET-Pi/birdnet.conf
configtemplate="$HOME"/BirdNET-Pi/birdnet.bak 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
fi
# Extract variable names from config template and read each one # Extract variable names from config template and read each one
grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do
# Check if the variable is in configcurrent, if not, append it # Check if the variable is in configcurrent, if not, append it
if ! grep -q "^$var=" "$configcurrent"; then if ! grep -q "^$var=" "$configcurrent"; then
# At which line was the variable in the initial file bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added"
bashio::log.yellow "...$var was missing from your birdnet.conf file, it was re-added" echo "$(grep "^$var=" "$configtemplate")" >> "$configcurrent"
grep "^$var=" "$configtemplate" >> "$configcurrent"
fi fi
# Check for duplicates # Check for duplicates
if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then
bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out expect for the first one" bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one"
awk -v var="$var" '{ if ($0 ~ "^[[:blank:]]*"var && c++ > 0) print "#" $0; else print $0; }' "$configcurrent" > temp && mv temp "$configcurrent" sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent"
fi fi
done done
@@ -33,8 +38,8 @@ done
############## ##############
if [[ "$(bashio::addon.port "80")" == 3000 ]]; then 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" 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 sleep infinity
fi fi
################## ##################
@@ -53,6 +58,6 @@ sed -i "/restart_services/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.
sed -i "s|/etc/birdnet/birdnet.conf|/config/birdnet.conf|g" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh sed -i "s|/etc/birdnet/birdnet.conf|/config/birdnet.conf|g" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh
# Execute update_birdnet_snippets # Execute update_birdnet_snippets
/."$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh
echo " " echo " "