From 490b03fb02f90bda5ff0c5066fac86558fb65b83 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:26:01 +0200 Subject: [PATCH] Create 31-checks.sh --- .../rootfs/etc/cont-init.d/31-checks.sh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh diff --git a/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh b/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh new file mode 100644 index 000000000..c1a4532bb --- /dev/null +++ b/birdnet-pi/rootfs/etc/cont-init.d/31-checks.sh @@ -0,0 +1,38 @@ +#!/command/with-contenv bashio +# shellcheck shell=bash +set -e + +###################### +# CHECK BIRDNET.CONF # +###################### + +echo " " +bashio::log.info "Checking your birndet.conf file integrity" + +# Set variables +configcurrent="$HOME"/BirdNET-Pi/birdnet.conf +configtemplate="$HOME"/BirdNET-Pi/birdnet.bak + +# 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 + # At which line was the variable in the initial file + bashio::log.yellow "...$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 expect for the first one" + awk -v var="$var" '{ if ($0 ~ "^[[:blank:]]*"var && c++ > 0) print "#" $0; else print $0; }' "$configcurrent" > temp && mv temp "$configcurrent" + fi +done + +############## +# CHECK PORT # +############## + +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 +fi