From 89cc3be05e7f0bc20760692c412dc8382ddb9b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 2 Feb 2026 21:57:52 +0100 Subject: [PATCH] [IMP] simplify PostgreSQL container detection with readarray Replace double grep pattern with readarray for cleaner container detection: - Single grep call instead of two - Native bash array instead of string manipulation - Array length check instead of grep -c - Proper formatting when listing multiple containers The readarray approach is more idiomatic and avoids edge cases with empty strings and newline handling. --- upgrade.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/upgrade.sh b/upgrade.sh index 50cdcd3..099ae02 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -41,20 +41,19 @@ export FINALE_DB_NAME="ou${FINAL_VERSION}" readonly FINALE_DB_NAME readonly FINALE_SERVICE_NAME="${FINALE_DB_NAME}" -postgres_containers=$(docker ps --format '{{.Names}}' | grep postgres || true) -postgres_count=$(echo "$postgres_containers" | grep -c . || echo 0) +readarray -t postgres_containers < <(docker ps --format '{{.Names}}' | grep postgres || true) -if [[ "$postgres_count" -eq 0 ]]; then +if [[ ${#postgres_containers[@]} -eq 0 ]]; then log_error "No running PostgreSQL container found. Please start a PostgreSQL container and try again." exit 1 -elif [[ "$postgres_count" -gt 1 ]]; then +elif [[ ${#postgres_containers[@]} -gt 1 ]]; then log_error "Multiple PostgreSQL containers found:" - echo "$postgres_containers" >&2 + printf ' %s\n' "${postgres_containers[@]}" >&2 log_error "Please ensure only one PostgreSQL container is running." exit 1 fi -export POSTGRES_SERVICE_NAME="$postgres_containers" +export POSTGRES_SERVICE_NAME="${postgres_containers[0]}" readonly POSTGRES_SERVICE_NAME log_step "INPUT PARAMETERS"