From 1027428bfde3b1cdbeacd1e3ac57491c4a6ea3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 2 Feb 2026 17:59:47 +0100 Subject: [PATCH] [IMP] use mktemp and trap for temporary file cleanup Replace hardcoded temporary file paths with mktemp -d for secure temporary directory creation, and add a trap to automatically clean up on script exit (success, failure, or interruption). Benefits: - Automatic cleanup even on Ctrl+C or script errors - No leftover temporary files in the working directory - Secure temporary directory creation (proper permissions) - Files isolated in dedicated temp directory Added '|| true' to grep command since it returns exit code 1 when no matches are found, which would trigger set -e otherwise. --- prepare_db.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/prepare_db.sh b/prepare_db.sh index eb6de9d..c2a2873 100755 --- a/prepare_db.sh +++ b/prepare_db.sh @@ -1,12 +1,14 @@ #!/bin/bash set -euo pipefail -# Global variables ODOO_SERVICE="$1" DB_NAME="$2" DB_FINALE_MODEL="$3" DB_FINALE_SERVICE="$4" +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + echo "Start database preparation" # Check POSTGRES container is running @@ -56,21 +58,18 @@ EOF ) echo "Retrieve 404 addons... " echo "SQL REQUEST = $SQL_404_ADDONS_LIST" -query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > 404_addons || exit 1 +query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > "${TMPDIR}/404_addons" -# Keep only the installed add-ons INSTALLED_ADDONS="SELECT name FROM ir_module_module WHERE state='installed';" -query_postgres_container "$INSTALLED_ADDONS" "$DB_NAME" > installed_addons || exit 1 +query_postgres_container "$INSTALLED_ADDONS" "$DB_NAME" > "${TMPDIR}/installed_addons" -grep -Fx -f 404_addons installed_addons > final_404_addons -rm -f 404_addons installed_addons +grep -Fx -f "${TMPDIR}/404_addons" "${TMPDIR}/installed_addons" > "${TMPDIR}/final_404_addons" || true -# Ask confirmation to uninstall the selected add-ons echo " ==== ADD-ONS CHECK ==== Installed add-ons not available in final Odoo version: " -cat final_404_addons +cat "${TMPDIR}/final_404_addons" echo "