[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
This commit is contained in:
@@ -9,6 +9,20 @@ set -euo pipefail
|
|||||||
readonly DATASTORE_PATH="/srv/datastore/data"
|
readonly DATASTORE_PATH="/srv/datastore/data"
|
||||||
readonly FILESTORE_SUBPATH="var/lib/odoo/filestore"
|
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_info() { printf "[INFO] %s\n" "$*"; }
|
||||||
log_warn() { printf "[WARN] %s\n" "$*" >&2; }
|
log_warn() { printf "[WARN] %s\n" "$*" >&2; }
|
||||||
log_error() { printf "[ERROR] %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 DATASTORE_PATH FILESTORE_SUBPATH
|
||||||
export -f log_info log_warn log_error log_step
|
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
|
export -f query_postgres_container copy_database copy_filestore exec_python_script_in_odoo_shell
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ if [[ $# -lt 4 ]]; then
|
|||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
check_required_commands
|
||||||
|
|
||||||
readonly ORIGIN_VERSION="$1"
|
readonly ORIGIN_VERSION="$1"
|
||||||
readonly FINAL_VERSION="$2"
|
readonly FINAL_VERSION="$2"
|
||||||
readonly ORIGIN_DB_NAME="$3"
|
readonly ORIGIN_DB_NAME="$3"
|
||||||
|
|||||||
Reference in New Issue
Block a user