From 3fe2e93d3daf7d4fdfc0a253af6bc6e9c01c79dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 2 Feb 2026 17:56:04 +0100 Subject: [PATCH] [IMP] use [[ instead of [ for conditionals Replace single bracket [ ] with double bracket [[ ]] for all test conditionals in the main scripts. Benefits of [[ over [: - No need to quote variables (though we still do for consistency) - Supports regex matching with =~ - Supports pattern matching with == and != - && and || work inside [[ ]] without escaping - More predictable behavior with empty strings - Is a bash keyword, not an external command Note: posbox scripts are left unchanged as they appear to be third-party code imported into the repository. --- prepare_db.sh | 2 +- upgrade.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/prepare_db.sh b/prepare_db.sh index a95a7d5..ff87cd2 100755 --- a/prepare_db.sh +++ b/prepare_db.sh @@ -16,7 +16,7 @@ if ! docker ps | grep -q "$DB_CONTAINER_NAME"; then fi EXT_EXISTS=$(query_postgres_container "SELECT 1 FROM pg_extension WHERE extname = 'dblink'" "$DB_NAME") || exit 1 -if [ "$EXT_EXISTS" != "1" ]; then +if [[ "$EXT_EXISTS" != "1" ]]; then query_postgres_container "CREATE EXTENSION dblink;" "$DB_NAME" || exit 1 fi diff --git a/upgrade.sh b/upgrade.sh index d95ef5c..b1f505c 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -47,10 +47,10 @@ FINALE_SERVICE_NAME="${FINALE_DB_NAME}" POSTGRES_CONTAINERS=$(docker ps --format '{{.Names}}' | grep postgres) POSTGRES_COUNT=$(echo "$POSTGRES_CONTAINERS" | grep -c .) -if [ "$POSTGRES_COUNT" -eq 0 ]; then +if [[ "$POSTGRES_COUNT" -eq 0 ]]; then echo "ERROR: No running PostgreSQL container found. Please start a PostgreSQL container and try again." >&2 exit 1 -elif [ "$POSTGRES_COUNT" -gt 1 ]; then +elif [[ "$POSTGRES_COUNT" -gt 1 ]]; then echo "ERROR: Multiple PostgreSQL containers found:" >&2 echo "$POSTGRES_CONTAINERS" >&2 echo "Please ensure only one PostgreSQL container is running." >&2 @@ -82,7 +82,7 @@ echo "Postgres service name .... $POSTGRES_SERVICE_NAME" query_postgres_container(){ local QUERY="$1" local DB_NAME="$2" - if [ -z "$QUERY" ]; then + if [[ -z "$QUERY" ]]; then return 0 fi local result @@ -135,7 +135,7 @@ echo " # Check origin database is in the local postgres DB_EXISTS=$(docker exec -it -u 70 "$POSTGRES_SERVICE_NAME" psql -tc "SELECT 1 FROM pg_database WHERE datname = '$ORIGIN_DB_NAME'" | tr -d '[:space:]') -if [ "$DB_EXISTS" ]; then +if [[ "$DB_EXISTS" ]]; then echo "UPGRADE: Database '$ORIGIN_DB_NAME' found." else echo "ERROR: Database '$ORIGIN_DB_NAME' not found in the local postgress service. Please add it and restart the upgrade process." @@ -144,7 +144,7 @@ fi # Check that the origin filestore exist REPERTOIRE="/srv/datastore/data/${ORIGIN_SERVICE_NAME}/var/lib/odoo/filestore/${ORIGIN_DB_NAME}" -if [ -d "$REPERTOIRE" ]; then +if [[ -d "$REPERTOIRE" ]]; then echo "UPGRADE: '$REPERTOIRE' filestore found." else echo "ERROR: '$REPERTOIRE' filestore not found, please add it and restart the upgrade process."