From a54e6ae3dae1d71bcd6f1683843287170e4c5f80 Mon Sep 17 00:00:00 2001 From: Sergey Revyakin Date: Tue, 21 Apr 2026 14:56:46 +0700 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D0=B2=D0=B0=D0=BB=D0=B8=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BD=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D1=85=20=D0=B1=D0=B5=D0=B7=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20hack=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install_all.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++--- restart_all.sh | 46 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 5 deletions(-) diff --git a/install_all.sh b/install_all.sh index 905e9ec..1cb5ae2 100755 --- a/install_all.sh +++ b/install_all.sh @@ -24,6 +24,8 @@ SDR_UNITS=( dronedetector-sdr-2400.service ) +CONFIGURED_SDR_UNITS=() + log() { printf '[install_all] %s\n' "$*" } @@ -33,6 +35,51 @@ die() { exit 1 } +sdr_unit_env_key() { + local unit="$1" + local band="${unit#dronedetector-sdr-}" + band="${band%.service}" + printf 'hack_%s\n' "$band" +} + +get_env_value() { + local key="$1" + awk -F= -v key="$key" ' + $1 == key { + value = substr($0, index($0, "=") + 1) + sub(/^[[:space:]]+/, "", value) + sub(/[[:space:]]+$/, "", value) + gsub(/^"/, "", value) + gsub(/"$/, "", value) + gsub(/^'\''/, "", value) + gsub(/'\''$/, "", value) + print value + exit + } + ' "${PROJECT_ROOT}/.env" +} + +populate_configured_sdr_units() { + CONFIGURED_SDR_UNITS=() + + local unit env_key env_value + for unit in "${SDR_UNITS[@]}"; do + env_key="$(sdr_unit_env_key "$unit")" + env_value="$(get_env_value "$env_key")" + if [[ -n "$env_value" ]]; then + CONFIGURED_SDR_UNITS+=("$unit") + else + log "Skipping ${unit}: ${env_key} is empty in .env" + fi + done + + if [[ "${#CONFIGURED_SDR_UNITS[@]}" -eq 0 ]]; then + log "No SDR units are configured in .env" + else + log "Configured SDR units: ${CONFIGURED_SDR_UNITS[*]}" + fi +} + print_failure_logs() { log "Collecting diagnostics..." systemctl --no-pager --full status dronedetector-compose.service || true @@ -216,7 +263,7 @@ install_systemd_units() { systemctl enable dronedetector-compose.service systemctl restart dronedetector-compose.service - for unit in "${SDR_UNITS[@]}"; do + for unit in "${CONFIGURED_SDR_UNITS[@]}"; do systemctl enable "$unit" systemctl restart "$unit" done @@ -241,7 +288,7 @@ verify_installation() { log "Verifying services" wait_for_systemd_active dronedetector-compose.service 30 || die "dronedetector-compose.service is not active" - for unit in "${SDR_UNITS[@]}"; do + for unit in "${CONFIGURED_SDR_UNITS[@]}"; do wait_for_systemd_active "$unit" 45 || die "$unit is not active" done @@ -251,7 +298,7 @@ verify_installation() { running_services="$(docker compose -f "$COMPOSE_FILE" ps --status running --services || true)" printf '%s\n' "$running_services" | grep -Fxq "dronedetector-server-to-master" || die "server_to_master is not running" - printf '%s\n' "$running_services" | grep -Fxq "dronedetector-nn-server" || die "NN_server is not running" + printf '%s\n' "$running_services" | grep -Fxq "dronedetector-telemetry-server" || die "telemetry_server is not running" log "Verification completed" } @@ -264,6 +311,7 @@ main() { extract_local_source_archives preflight + populate_configured_sdr_units install_host_non_python_deps setup_sdr_python_env install_docker_if_needed diff --git a/restart_all.sh b/restart_all.sh index 6617f4e..e7b9101 100755 --- a/restart_all.sh +++ b/restart_all.sh @@ -17,10 +17,51 @@ SDR_UNITS=( dronedetector-sdr-2400.service ) +CONFIGURED_SDR_UNITS=() + log() { printf '[restart_all] %s\n' "$*" } +sdr_unit_env_key() { + local unit="$1" + local band="${unit#dronedetector-sdr-}" + band="${band%.service}" + printf 'hack_%s\n' "$band" +} + +get_env_value() { + local key="$1" + awk -F= -v key="$key" ' + $1 == key { + value = substr($0, index($0, "=") + 1) + sub(/^[[:space:]]+/, "", value) + sub(/[[:space:]]+$/, "", value) + gsub(/^"/, "", value) + gsub(/"$/, "", value) + gsub(/^'\''/, "", value) + gsub(/'\''$/, "", value) + print value + exit + } + ' "${PROJECT_ROOT}/.env" +} + +populate_configured_sdr_units() { + CONFIGURED_SDR_UNITS=() + + local unit env_key env_value + for unit in "${SDR_UNITS[@]}"; do + env_key="$(sdr_unit_env_key "$unit")" + env_value="$(get_env_value "$env_key")" + if [[ -n "$env_value" ]]; then + CONFIGURED_SDR_UNITS+=("$unit") + else + log "Skipping ${unit}: ${env_key} is empty in .env" + fi + done +} + if [[ -x /usr/bin/sudo ]]; then SUDO=(sudo) else @@ -39,7 +80,7 @@ restart_docker_services() { restart_sdr_services() { log "Restarting SDR systemd units" - for unit in "${SDR_UNITS[@]}"; do + for unit in "${CONFIGURED_SDR_UNITS[@]}"; do ${SUDO[@]} systemctl restart "$unit" done } @@ -49,7 +90,7 @@ print_status() { docker compose -f "$COMPOSE_FILE" ps || true log "SDR status" - for unit in "${SDR_UNITS[@]}"; do + for unit in "${CONFIGURED_SDR_UNITS[@]}"; do if ${SUDO[@]} systemctl is-active --quiet "$unit"; then printf '%s: active\n' "$unit" else @@ -59,6 +100,7 @@ print_status() { } main() { + populate_configured_sdr_units restart_docker_services restart_sdr_services print_status