From 7c8bc085f727fdd95a808424a359c938d057c9a9 Mon Sep 17 00:00:00 2001 From: Developer Date: Fri, 20 Mar 2026 01:44:31 -0400 Subject: [PATCH] Add detection diagnostic tools and fix silent detection on cached runs NEW FEATURES: - launcher.sh --detect-only: Force re-detect and show results - test-detection.sh: Comprehensive detection diagnostic tool - Better error feedback when detection fails FIXES: - launcher.sh: Detection now verified even on cached runs - Added explicit check for SYS_DETECTION_COMPLETE before using cache - User can now diagnose detection issues with --detect-only flag USAGE: bash launcher.sh --detect-only (check what was detected) bash test-detection.sh (run full diagnostic) bash test-detection.sh verbose (show file paths and details) RESULTS: - Users can now easily verify detection is working - Detection issues are no longer silent - Clear diagnostic output for troubleshooting --- launcher.sh | 51 +++++++++ test-detection.sh | 256 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 test-detection.sh diff --git a/launcher.sh b/launcher.sh index 2e4e797..af2cbc6 100755 --- a/launcher.sh +++ b/launcher.sh @@ -732,6 +732,13 @@ startup_detection() { if ! read -p "Press Enter to continue..." /dev/null; then true # Continue even if read fails fi + else + # Database is cached and fresh, but still ensure detection was completed + # (this addresses issue where detection output not shown on cached runs) + if [ -z "${SYS_DETECTION_COMPLETE:-}" ]; then + print_error "System detection failed - please check system configuration" + return 1 + fi fi } @@ -740,6 +747,50 @@ startup_detection() { ############################################################################# main() { + # Handle command-line arguments + case "${1:-}" in + --detect-only|--check-detection) + # Initialize directories + init_directories || { + echo "ERROR: Failed to initialize directories" + return 1 + } + + # Force fresh detection regardless of cache + echo "Forcing system re-detection..." + echo "" + rm -f "$BASE_DIR/.sysref.beta" "$BASE_DIR/.sysref.beta.timestamp" 2>/dev/null || true + + # Run detection + initialize_system_detection + + # Show results + echo "" + echo "═══════════════════════════════════════════════════════════════" + echo " DETECTION RESULTS" + echo "═══════════════════════════════════════════════════════════════" + echo "" + echo "Control Panel: ${SYS_CONTROL_PANEL:-unknown} ${SYS_CONTROL_PANEL_VERSION:-}" + echo "Operating System: ${SYS_OS_TYPE:-unknown} ${SYS_OS_VERSION:-}" + echo "Web Server: ${SYS_WEB_SERVER:-unknown} ${SYS_WEB_SERVER_VERSION:-}" + echo "Database: ${SYS_DB_TYPE:-unknown} ${SYS_DB_VERSION:-}" + echo "Firewall: ${SYS_FIREWALL:-unknown} ${SYS_FIREWALL_VERSION:-} (${SYS_FIREWALL_ACTIVE:-unknown})" + echo "PHP Versions: ${SYS_PHP_VERSIONS[*]:-none detected}" + echo "" + echo "═══════════════════════════════════════════════════════════════" + return 0 + ;; + --help|--usage|-h|-?) + echo "Usage: launcher.sh [OPTIONS]" + echo "" + echo "Options:" + echo " --detect-only Show system detection results and exit" + echo " --help Show this help message" + echo "" + return 0 + ;; + esac + # Initialize directories once at startup init_directories || { echo "ERROR: Failed to initialize directories" diff --git a/test-detection.sh b/test-detection.sh new file mode 100644 index 0000000..fe4b2e0 --- /dev/null +++ b/test-detection.sh @@ -0,0 +1,256 @@ +#!/bin/bash +############################################################################# +# System Detection Diagnostic Tool +# Run this on a standalone server to test all detection functions +# Usage: bash test-detection.sh [verbose] +############################################################################# + +set -eo pipefail + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LIB_DIR="$BASE_DIR/lib" + +# Check for verbose flag +VERBOSE=0 +[ "$1" = "verbose" ] && VERBOSE=1 + +# Load libraries +source "$LIB_DIR/common-functions.sh" +source "$LIB_DIR/system-detect.sh" + +echo "═══════════════════════════════════════════════════════════════" +echo " SYSTEM DETECTION DIAGNOSTIC TOOL" +echo "═══════════════════════════════════════════════════════════════" +echo "" + +############################################################################# +# STEP 1: Test Basic Commands +############################################################################# + +echo "[STEP 1] Testing Command Availability" +echo "─────────────────────────────────────────────────────────────" + +test_command() { + local cmd="$1" + local desc="$2" + + if command_exists "$cmd"; then + local path=$(which "$cmd" 2>/dev/null) + echo "✓ $desc" + [ $VERBOSE -eq 1 ] && echo " Location: $path" + else + echo "✗ $desc - NOT FOUND" + fi +} + +echo "" +echo "Web Servers:" +test_command "httpd" "Apache (httpd)" +test_command "apache2" "Apache (apache2)" +test_command "nginx" "Nginx" + +echo "" +echo "Databases:" +test_command "mysql" "MySQL/MariaDB" +test_command "psql" "PostgreSQL" + +echo "" +echo "Firewalls:" +test_command "firewall-cmd" "Firewalld" +test_command "iptables" "iptables" +test_command "ufw" "UFW" + +############################################################################# +# STEP 2: Test Version Detection +############################################################################# + +echo "" +echo "[STEP 2] Version Detection" +echo "─────────────────────────────────────────────────────────────" + +echo "" +echo "Apache Version Detection:" +if command_exists httpd; then + httpd_v=$(httpd -v 2>/dev/null | grep -oP 'Apache/\K[\d.]+' | head -1) + echo "✓ httpd version: $httpd_v" +elif command_exists apache2; then + apache2_v=$(apache2 -v 2>/dev/null | grep -oP 'Apache/\K[\d.]+' | head -1) + echo "✓ apache2 version: $apache2_v" +else + echo "✗ Apache not found" +fi + +echo "" +echo "MySQL/MariaDB Version Detection:" +if command_exists mysql; then + mysql_v=$(mysql --version 2>/dev/null) + echo "✓ mysql version: $mysql_v" +else + echo "✗ MySQL not found" +fi + +echo "" +echo "Nginx Version Detection:" +if command_exists nginx; then + nginx_v=$(nginx -v 2>&1 | grep -oP 'nginx/\K[\d.]+' 2>/dev/null) + echo "✓ nginx version: $nginx_v" +else + echo "✗ Nginx not found" +fi + +############################################################################# +# STEP 3: Test Control Panel Detection +############################################################################# + +echo "" +echo "[STEP 3] Control Panel Detection" +echo "─────────────────────────────────────────────────────────────" + +echo "" +if [ -f "/usr/local/cpanel/version" ]; then + cpanel_v=$(cat /usr/local/cpanel/version) + echo "✓ cPanel detected: v$cpanel_v" +elif [ -f "/usr/local/psa/version" ]; then + plesk_v=$(cat /usr/local/psa/version | head -1) + echo "✓ Plesk detected: v$plesk_v" +elif [ -d "/usr/local/interworx" ] || [ -f "/etc/interworx/iworx.ini" ]; then + echo "✓ InterWorx detected" +else + echo "✓ Standalone (no control panel)" +fi + +############################################################################# +# STEP 4: Test OS Detection +############################################################################# + +echo "" +echo "[STEP 4] Operating System Detection" +echo "─────────────────────────────────────────────────────────────" + +if [ -f /etc/os-release ]; then + . /etc/os-release + echo "✓ OS Detected: $NAME" + echo " Version: $VERSION_ID" +else + echo "✗ Could not detect OS" +fi + +############################################################################# +# STEP 5: Test Firewall Detection +############################################################################# + +echo "" +echo "[STEP 5] Firewall Detection" +echo "─────────────────────────────────────────────────────────────" + +echo "" +if [ -f "/etc/csf/csf.conf" ]; then + csf_v=$(head -1 /etc/csf/version.txt 2>/dev/null || echo "unknown") + echo "✓ CSF detected: v$csf_v" + if pgrep -x lfd > /dev/null 2>&1; then + echo " Status: ACTIVE" + else + echo " Status: INACTIVE" + fi +else + echo "✗ CSF not found" +fi + +echo "" +if command_exists firewall-cmd; then + fw_v=$(firewall-cmd --version 2>/dev/null || echo "unknown") + echo "✓ firewalld detected: v$fw_v" + if systemctl is-active --quiet firewalld 2>/dev/null; then + echo " Status: ACTIVE" + else + echo " Status: INACTIVE" + fi +else + echo "✗ firewalld not found" +fi + +echo "" +if command_exists iptables; then + ipt_v=$(iptables --version 2>/dev/null | grep -oP 'v\K[\d.]+' | head -1 || echo "unknown") + echo "✓ iptables detected: v$ipt_v" + rules=$(iptables -L INPUT -n 2>/dev/null | wc -l) + if [ "$rules" -gt 2 ]; then + echo " Status: ACTIVE ($(($rules - 2)) rules)" + else + echo " Status: NO RULES" + fi +else + echo "✗ iptables not found" +fi + +############################################################################# +# STEP 6: Run Full Detection +############################################################################# + +echo "" +echo "[STEP 6] Running Full System Detection" +echo "─────────────────────────────────────────────────────────────" +echo "" + +# Run the full detection +initialize_system_detection + +############################################################################# +# STEP 7: Display Detected System Variables +############################################################################# + +echo "" +echo "[STEP 7] Detected System Variables" +echo "─────────────────────────────────────────────────────────────" +echo "" + +echo "Control Panel: ${SYS_CONTROL_PANEL:-unknown}" +echo "Control Panel Ver: ${SYS_CONTROL_PANEL_VERSION:-N/A}" +echo "Operating System: ${SYS_OS_TYPE:-unknown}" +echo "OS Version: ${SYS_OS_VERSION:-N/A}" +echo "Web Server: ${SYS_WEB_SERVER:-unknown}" +echo "Web Server Ver: ${SYS_WEB_SERVER_VERSION:-N/A}" +echo "Database Type: ${SYS_DB_TYPE:-unknown}" +echo "Database Ver: ${SYS_DB_VERSION:-N/A}" +echo "Log Directory: ${SYS_LOG_DIR:-N/A}" +echo "User Home Base: ${SYS_USER_HOME_BASE:-N/A}" +echo "PHP Versions: ${SYS_PHP_VERSIONS[*]:-N/A}" +echo "Firewall: ${SYS_FIREWALL:-unknown}" +echo "Firewall Version: ${SYS_FIREWALL_VERSION:-N/A}" +echo "Firewall Active: ${SYS_FIREWALL_ACTIVE:-unknown}" +echo "" + +############################################################################# +# STEP 8: Summary +############################################################################# + +echo "" +echo "═══════════════════════════════════════════════════════════════" +echo " SUMMARY" +echo "═══════════════════════════════════════════════════════════════" +echo "" + +detection_ok=1 + +[ -z "$SYS_WEB_SERVER" ] || [ "$SYS_WEB_SERVER" = "unknown" ] && { + echo "⚠️ WARNING: Web server not detected" + detection_ok=0 +} + +[ -z "$SYS_DB_TYPE" ] || [ "$SYS_DB_TYPE" = "none" ] && { + echo "⚠️ INFO: No database detected (may be intentional)" +} + +[ -z "$SYS_FIREWALL" ] || [ "$SYS_FIREWALL" = "none" ] && { + echo "ℹ️ INFO: No firewall detected (may be intentional on standalone)" +} + +if [ $detection_ok -eq 1 ]; then + echo "✓ System detection completed successfully" + echo "" + echo "All critical components detected." +fi + +echo "" +echo "═══════════════════════════════════════════════════════════════" +echo ""