From 5f1f2a3c0381d0a95aa5177afcc2094d83ffddef Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 11 Feb 2026 17:03:27 -0500 Subject: [PATCH] Add comprehensive dependency checking at startup New Function: check_dependencies() - Verifies all 4 critical binaries exist before proceeding - Binaries checked: mysqld, mysql, mysqldump, mysqladmin - Clear error messages with installation instructions per OS - Called early in main() before any interactive prompts Impact: - Prevents silent failures deep in the workflow - Saves user time by failing fast with clear error messages - Provides helpful package installation instructions - Supports CentOS/RHEL, Debian/Ubuntu, AlmaLinux - Runs once at startup (not repeatedly) Before: User could go through all 5 steps only to fail when mysqldump or mysqladmin was actually needed After: Dependencies validated immediately, clear error if missing Co-Authored-By: Claude Haiku 4.5 --- modules/backup/mysql-restore-to-sql.sh | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/modules/backup/mysql-restore-to-sql.sh b/modules/backup/mysql-restore-to-sql.sh index 1bdff9d..11eb358 100755 --- a/modules/backup/mysql-restore-to-sql.sh +++ b/modules/backup/mysql-restore-to-sql.sh @@ -79,6 +79,57 @@ cleanup_on_exit() { # Set trap for signals trap cleanup_on_exit EXIT INT TERM +################################################################################ +# DEPENDENCY CHECKING +################################################################################ + +# Verify all required binaries exist before proceeding +# Returns 1 if any critical dependency is missing +check_dependencies() { + local missing_deps=0 + local missing_list="" + + # Critical binaries required for script operation + local required_binaries=( + "mysqld:MySQL server daemon (required to start second instance)" + "mysql:MySQL client (required for database queries)" + "mysqldump:MySQL backup tool (required to create SQL dump)" + "mysqladmin:MySQL admin tool (required for shutdown)" + ) + + print_info "Verifying required dependencies..." + + for bin_info in "${required_binaries[@]}"; do + local bin="${bin_info%:*}" + local description="${bin_info#*:}" + + # Try to find the binary + if ! command -v "$bin" &> /dev/null; then + print_error " Missing: $bin - $description" + missing_deps=$((missing_deps + 1)) + missing_list="$missing_list - $bin\n" + else + print_success " Found: $bin" + fi + done + + if [ "$missing_deps" -gt 0 ]; then + echo "" + print_error "MISSING $missing_deps REQUIRED DEPENDENCY/IES" + echo "" + echo "Please install the following packages:" + echo -e "$missing_list" + echo "" + echo "On CentOS/RHEL: yum install mysql mysql-server" + echo "On Debian/Ubuntu: apt-get install mysql-client mysql-server" + echo "On AlmaLinux: dnf install mysql mysql-server" + return 1 + fi + + print_success "All required dependencies found" + return 0 +} + ################################################################################ # UTILITY FUNCTIONS ################################################################################ @@ -1839,6 +1890,13 @@ step5_create_dump() { # creates SQL dump, and provides usage instructions # Handles errors and signal interrupts with proper cleanup main() { + # CRITICAL: Check all required dependencies before proceeding + if ! check_dependencies; then + press_enter + exit 1 + fi + + echo "" show_intro echo -n "Continue? (y/n, or 0 to cancel): " read -r start