From d104616861a7b3f2e0166fb2cfaaa1e05f006c45 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 11:25:22 -0500 Subject: [PATCH] Add dependency checks with helpful error messages Script now verifies required (lsblk, lspci, etc.) and optional (smartctl, ceph, bc, nvme) dependencies at startup. - Exits with clear error if required dependencies are missing - Warns about missing optional dependencies with reduced functionality - Directs users to freshStartScript for easy installation - Checks for sudo access needed for SMART operations Fixes: https://code.lotusguild.org/LotusGuild/driveAtlas/issues/3 Co-Authored-By: Claude Opus 4.5 --- driveAtlas.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/driveAtlas.sh b/driveAtlas.sh index f46c452..9e139c2 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -5,6 +5,70 @@ # Maps physical drive bays to logical device names using PCI paths #============================================================================== +#------------------------------------------------------------------------------ +# Dependency Checks +# Verifies required commands are available before running +#------------------------------------------------------------------------------ + +# Required dependencies (script will not function without these) +REQUIRED_DEPS=(lsblk lspci readlink hostname) + +# Optional dependencies (enhanced functionality) +OPTIONAL_DEPS=(smartctl ceph ceph-volume bc nvme) + +FRESH_START_URL="http://10.10.10.63:3000/LotusGuild/freshStartScript/raw/branch/main/freshStart.sh" + +#------------------------------------------------------------------------------ +# check_dependencies +# +# Verifies required and optional commands are available. +# Exits with error if required dependencies are missing. +# Warns about missing optional dependencies. +#------------------------------------------------------------------------------ +check_dependencies() { + local missing_required=() + local missing_optional=() + + # Check required dependencies + for cmd in "${REQUIRED_DEPS[@]}"; do + if ! command -v "$cmd" &>/dev/null; then + missing_required+=("$cmd") + fi + done + + # Check optional dependencies + for cmd in "${OPTIONAL_DEPS[@]}"; do + if ! command -v "$cmd" &>/dev/null; then + missing_optional+=("$cmd") + fi + done + + # Report missing required dependencies and exit + if [[ ${#missing_required[@]} -gt 0 ]]; then + echo "ERROR: Missing required dependencies: ${missing_required[*]}" >&2 + echo "" >&2 + echo "Please install the missing packages or run the fresh start script:" >&2 + echo " curl -s $FRESH_START_URL | bash" >&2 + echo "" >&2 + exit 1 + fi + + # Warn about missing optional dependencies + if [[ ${#missing_optional[@]} -gt 0 ]]; then + echo "Note: Some optional features unavailable. Missing: ${missing_optional[*]}" >&2 + echo " Install them or run: curl -s $FRESH_START_URL | bash" >&2 + echo "" >&2 + fi + + # Check for sudo access (needed for smartctl) + if command -v smartctl &>/dev/null && ! sudo -n true 2>/dev/null; then + echo "Note: SMART data requires sudo access. Run with sudo for full functionality." >&2 + fi +} + +# Run dependency check at script start +check_dependencies + #------------------------------------------------------------------------------ # Chassis Type Definitions # These define the physical layout and display formatting for each chassis type