From 00c12769bc2d6df41300a4f572dba6718a4a94ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 2 Feb 2026 18:00:55 +0100 Subject: [PATCH] [IMP] add external command verification at startup Add check_required_commands() function to verify that all required external tools are available before the script begins execution: - docker: Container runtime - compose: Docker compose wrapper (0k-scripts) - sudo: Required for filestore operations Benefits: - Fails fast with a clear error message listing missing commands - Prevents cryptic 'command not found' errors mid-execution - Documents script dependencies explicitly - Called immediately after argument validation in upgrade.sh --- lib/common.sh | 15 +++++++++++++++ upgrade.sh | 2 ++ 2 files changed, 17 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 98f935a..deead8d 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -9,6 +9,20 @@ set -euo pipefail readonly DATASTORE_PATH="/srv/datastore/data" readonly FILESTORE_SUBPATH="var/lib/odoo/filestore" +check_required_commands() { + local missing=() + for cmd in docker compose sudo; do + if ! command -v "$cmd" &>/dev/null; then + missing+=("$cmd") + fi + done + if [[ ${#missing[@]} -gt 0 ]]; then + log_error "Required commands not found: ${missing[*]}" + log_error "Please install them before running this script." + exit 1 + fi +} + log_info() { printf "[INFO] %s\n" "$*"; } log_warn() { printf "[WARN] %s\n" "$*" >&2; } log_error() { printf "[ERROR] %s\n" "$*" >&2; } @@ -64,4 +78,5 @@ exec_python_script_in_odoo_shell() { export DATASTORE_PATH FILESTORE_SUBPATH export -f log_info log_warn log_error log_step +export -f check_required_commands export -f query_postgres_container copy_database copy_filestore exec_python_script_in_odoo_shell diff --git a/upgrade.sh b/upgrade.sh index 2ce195b..50cdcd3 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -29,6 +29,8 @@ if [[ $# -lt 4 ]]; then usage fi +check_required_commands + readonly ORIGIN_VERSION="$1" readonly FINAL_VERSION="$2" readonly ORIGIN_DB_NAME="$3"