From 0bdc488a402ebfcd6fc949931ee69eacffa8ae8b Mon Sep 17 00:00:00 2001 From: Thibaut Voirand Date: Sat, 7 Dec 2024 18:03:50 +0100 Subject: [PATCH] Add past_birdweather_publication in install scripts --- scripts/install_helpers.sh | 30 ++++++++++++++++++++++++++++++ scripts/install_services.sh | 10 +++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/scripts/install_helpers.sh b/scripts/install_helpers.sh index 1a885b3c..192b4dc1 100644 --- a/scripts/install_helpers.sh +++ b/scripts/install_helpers.sh @@ -70,3 +70,33 @@ install_tmp_mount() { echo "tmp.mount is $STATE, skipping" fi } + +install_birdweather_past_publication() { + cat << EOF > $HOME/BirdNET-Pi/templates/birdweather_past_publication@.service +[Unit] +Description=BirdWeather Publication for %i interface +After=network-online.target +Wants=network-online.target +[Service] +Type=oneshot +User=${USER} +ExecStartPre= /bin/sh -c 'n=0; until curl --silent --head --fail https://app.birdweather.com || [ \$n -ge 30 ]; do n=\$((n+1)); sleep 5; done;' +ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/birdweather_past_publication.py +EOF + cat << EOF > $HOME/BirdNET-Pi/templates/50-birdweather-past-publication +#!/bin/bash +UNIT_NAME="birdweather_past_publication@\$IFACE.service" +# Check if the service is active and then start it +if systemctl is-active --quiet "\$UNIT_NAME"; then + echo "\$UNIT_NAME is already running." +else + echo "Starting \$UNIT_NAME..." + systemctl start "\$UNIT_NAME" +fi +EOF + chmod +x $HOME/BirdNET-Pi/templates/50-birdweather-past-publication + chown root:root $HOME/BirdNET-Pi/templates/50-birdweather-past-publication + ln -sf $HOME/BirdNET-Pi/templates/50-birdweather-past-publication /etc/networkd-dispatcher/routable.d + ln -sf $HOME/BirdNET-Pi/templates/birdweather_past_publication@.service /usr/lib/systemd/system + systemctl enable systemd-networkd +} diff --git a/scripts/install_services.sh b/scripts/install_services.sh index c623ce24..ab06e52a 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -20,7 +20,7 @@ install_depends() { apt install -qqy caddy sqlite3 php-sqlite3 php-fpm php-curl php-xml php-zip php icecast2 \ pulseaudio avahi-utils sox libsox-fmt-mp3 alsa-utils ffmpeg \ wget curl unzip bc \ - python3-pip python3-venv lsof net-tools inotify-tools + python3-pip python3-venv lsof net-tools inotify-tools networkd-dispatcher } set_hostname() { @@ -387,6 +387,13 @@ install_weekly_cron() { chown_things() { chown -R $USER:$USER $HOME/Bird* + + # Set ownership to root for the birdweather publication networkd-dispatcher script + BIRDWEATHER_PAST_DISPATCHER_SCRIPT="$HOME/BirdNET-Pi/templates/50-birdweather-past-publication" + if [ -f "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" ]; then + sudo chown root:root "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" + sudo chmod 755 "$BIRDWEATHER_PAST_DISPATCHER_SCRIPT" + fi } increase_caddy_timeout() { @@ -409,6 +416,7 @@ install_services() { install_Caddyfile install_avahi_aliases install_birdnet_analysis + install_birdweather_past_publication install_birdnet_stats_service install_recording_service install_custom_recording_service # But does not enable