Add test-launcher.sh for cross-platform verification

Created standalone test launcher to verify multi-platform support
before modifying production launcher.sh.

Features:
- Platform-specific domain discovery (cPanel, Plesk, standalone)
- Uses panel-agnostic functions from domain-discovery.sh
- Compares results with production database
- Safe to run without affecting launcher.sh

Test Results on cPanel:
-  Successfully detects platform (cpanel)
-  Finds users (1 user)
-  Finds domains (1 main domain)
-  Finds databases (1 database)
-  Extracts docroot, logs, PHP version correctly

Next: Test on Plesk server to verify Plesk detection works

Documentation:
- FINAL_AUDIT_VERIFIED.md - Complete audit after quad-checking
- CORRECTED_AUDIT_SUMMARY.md - Summary of corrections
- CROSS_PLATFORM_PLAN.md - Implementation roadmap

Usage:
  bash test-launcher.sh

Output:
  Creates .sysref-test file for inspection
  Compares with production .sysref if exists
  Shows platform detection and sample domain data

Status:  Ready for Plesk testing
This commit is contained in:
cschantz
2025-12-24 15:09:38 -05:00
parent 316a35f93c
commit 621906517e
4 changed files with 1166 additions and 0 deletions
+275
View File
@@ -0,0 +1,275 @@
#!/bin/bash
###############################################################################
# TEST LAUNCHER - Cross-Platform Verification
# Tests multi-platform reference database building without modifying launcher.sh
###############################################################################
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export TOOLKIT_BASE_DIR="$SCRIPT_DIR"
# Source libraries
LIB_DIR="$SCRIPT_DIR/lib"
source "$LIB_DIR/common-functions.sh"
source "$LIB_DIR/system-detect.sh"
source "$LIB_DIR/domain-discovery.sh"
source "$LIB_DIR/user-manager.sh"
# Test database location
TEST_SYSREF_DB="${TOOLKIT_BASE_DIR}/.sysref-test"
TEST_SYSREF_TIMESTAMP="${TOOLKIT_BASE_DIR}/.sysref-test.timestamp"
###############################################################################
# PLATFORM-SPECIFIC DOMAIN BUILDERS
###############################################################################
build_domains_cpanel_test() {
print_info "Using cPanel-optimized domain discovery..."
local users=($(list_all_users))
local current=0
local total=0
# Count domains
for user in "${users[@]}"; do
local userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}/${user}"
if [ -d "$userdata_dir" ]; then
total=$((total + $(find "$userdata_dir" -type f ! -name "*.cache" ! -name "*.yaml" ! -name "*.json" ! -name "main*" ! -name "cache" ! -name "*_SSL" 2>/dev/null | wc -l)))
fi
done
# Process domains
declare -A seen_domains
for user in "${users[@]}"; do
local userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}/${user}"
if [ -d "$userdata_dir" ]; then
for config_file in "$userdata_dir"/*; do
[ ! -f "$config_file" ] && continue
local basename=$(basename "$config_file")
# Skip cache files
[[ "$basename" =~ \.cache$|\.yaml$|\.json$|^main|^cache$|_SSL$ ]] && continue
local domain="$basename"
local doc_root=$(grep "^documentroot:" "$config_file" | awk '{print $2}' || true)
local log_path=$(grep "target:.*domlogs" "$config_file" | head -1 | awk '{print $2}' || true)
local php_version=$(grep "^phpversion:" "$config_file" | awk '{print $2}' || true)
current=$((current + 1))
show_progress $current $total "Processing cPanel domains..."
echo "DOMAIN|$domain|$user|$doc_root|$log_path|$php_version|cpanel" >> "$TEST_SYSREF_DB"
seen_domains["$domain"]=1
done
fi
done
finish_progress
}
build_domains_plesk_test() {
print_info "Using Plesk-specific domain discovery..."
local all_domains=$(list_all_domains)
local domain_count=$(echo "$all_domains" | wc -w)
local current=0
for domain in $all_domains; do
[ -z "$domain" ] && continue
((current++))
show_progress $current $domain_count "Processing Plesk domains..."
# Use panel-agnostic functions that call Plesk helpers
local owner=$(get_domain_owner "$domain" || echo "unknown")
local docroot=$(get_domain_docroot "$domain" || echo "")
local logdir=$(get_domain_logdir "$domain" || echo "")
local access_log=$(get_domain_access_log "$domain" || echo "")
# Try to get PHP version if plesk helper exists
local php_version=""
if type plesk_get_php_version >/dev/null 2>&1; then
php_version=$(plesk_get_php_version "$domain" || echo "")
fi
echo "DOMAIN|$domain|$owner|$docroot|$logdir|$access_log|$php_version|plesk" >> "$TEST_SYSREF_DB"
done
finish_progress
}
build_domains_standalone_test() {
print_info "Using standalone domain discovery..."
local all_domains=$(list_all_domains)
local domain_count=$(echo "$all_domains" | wc -w)
local current=0
if [ -z "$all_domains" ]; then
print_warning "No domains found via directory scanning"
return
fi
for domain in $all_domains; do
[ -z "$domain" ] && continue
((current++))
show_progress $current $domain_count "Processing standalone domains..."
local docroot=$(get_domain_docroot "$domain" || echo "")
local owner=$(get_domain_owner "$domain" || echo "unknown")
local logdir=$(get_domain_logdir "$domain" || echo "")
local access_log=$(get_domain_access_log "$domain" || echo "")
echo "DOMAIN|$domain|$owner|$docroot|$logdir|$access_log||standalone" >> "$TEST_SYSREF_DB"
done
finish_progress
}
###############################################################################
# MAIN TEST FUNCTION
###############################################################################
test_reference_database() {
local start_time=$(date +%s)
print_header "Cross-Platform Reference Database Test"
echo ""
# Show detected platform
print_info "Detected Platform: $SYS_CONTROL_PANEL"
print_info "OS: $SYS_OS_TYPE $SYS_OS_VERSION"
print_info "Web Server: $SYS_WEB_SERVER $SYS_WEB_SERVER_VERSION"
print_info "Database: $SYS_DB_TYPE $SYS_DB_VERSION"
print_info "User Home Base: $SYS_USER_HOME_BASE"
print_info "Log Directory: $SYS_LOG_DIR"
echo ""
# Initialize test database
print_info "Building test reference database..."
echo "# Test System Reference Database" > "$TEST_SYSREF_DB"
echo "# Platform: $SYS_CONTROL_PANEL" >> "$TEST_SYSREF_DB"
echo "# Generated: $(date)" >> "$TEST_SYSREF_DB"
echo "" >> "$TEST_SYSREF_DB"
# Test users
echo "[USERS]" >> "$TEST_SYSREF_DB"
local users=($(list_all_users))
print_info "Found ${#users[@]} users"
for user in "${users[@]}"; do
echo "USER|$user" >> "$TEST_SYSREF_DB"
done
echo "" >> "$TEST_SYSREF_DB"
# Test domains - platform-specific
echo "[DOMAINS]" >> "$TEST_SYSREF_DB"
case "$SYS_CONTROL_PANEL" in
cpanel)
build_domains_cpanel_test
;;
plesk)
build_domains_plesk_test
;;
interworx)
print_warning "InterWorx support not yet implemented in test"
build_domains_standalone_test
;;
*)
build_domains_standalone_test
;;
esac
echo "" >> "$TEST_SYSREF_DB"
# Test databases
echo "[DATABASES]" >> "$TEST_SYSREF_DB"
if [ "$SYS_DB_TYPE" != "none" ]; then
local all_dbs=$(mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" || true)
local db_count=$(echo "$all_dbs" | wc -l)
print_info "Found $db_count databases"
for db in $all_dbs; do
local owner=$(get_database_owner "$db" || echo "unknown")
echo "DB|$db|$owner" >> "$TEST_SYSREF_DB"
done
fi
echo "" >> "$TEST_SYSREF_DB"
# Save timestamp
date +%s > "$TEST_SYSREF_TIMESTAMP"
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo ""
print_success "Test database built in ${duration}s"
print_info "Test database location: $TEST_SYSREF_DB"
echo ""
# Show statistics
local user_count=$(grep -c "^USER|" "$TEST_SYSREF_DB" 2>/dev/null || echo 0)
local domain_count=$(grep -c "^DOMAIN|" "$TEST_SYSREF_DB" 2>/dev/null || echo 0)
local db_count=$(grep -c "^DB|" "$TEST_SYSREF_DB" 2>/dev/null || echo 0)
print_header "Test Results"
echo " Users: $user_count"
echo " Domains: $domain_count"
echo " Databases: $db_count"
echo ""
# Show sample domains
if [ "$domain_count" -gt 0 ]; then
print_header "Sample Domain Entries (first 5)"
grep "^DOMAIN|" "$TEST_SYSREF_DB" | head -5 | while IFS='|' read -r type domain owner docroot logdir access_log php platform; do
echo " Domain: $domain"
echo " Owner: $owner"
echo " Docroot: $docroot"
echo " Platform: $platform"
echo ""
done
fi
# Compare with production database if it exists
if [ -f "$TOOLKIT_BASE_DIR/.sysref" ]; then
echo ""
print_header "Comparison with Production Database"
local prod_users=$(grep -c "^USER|" "$TOOLKIT_BASE_DIR/.sysref" 2>/dev/null || echo 0)
local prod_domains=$(grep -c "^DOMAIN|" "$TOOLKIT_BASE_DIR/.sysref" 2>/dev/null || echo 0)
local prod_dbs=$(grep -c "^DB|" "$TOOLKIT_BASE_DIR/.sysref" 2>/dev/null || echo 0)
echo " Production: $prod_users users, $prod_domains domains, $prod_dbs databases"
echo " Test: $user_count users, $domain_count domains, $db_count databases"
echo ""
if [ "$user_count" -eq "$prod_users" ] && [ "$domain_count" -eq "$prod_domains" ]; then
print_success "✅ Counts match! Test successful."
else
print_warning "⚠️ Counts differ - this may be expected for cross-platform changes"
fi
fi
echo ""
print_info "Test database saved to: $TEST_SYSREF_DB"
print_info "You can inspect it with: cat $TEST_SYSREF_DB"
}
###############################################################################
# RUN TEST
###############################################################################
# Clear screen and run
clear
test_reference_database
# Instructions
echo ""
print_header "Next Steps"
echo "1. Review the test database: cat $TEST_SYSREF_DB"
echo "2. If results look good on this cPanel server, test on Plesk:"
echo " - git pull on Plesk server"
echo " - bash test-launcher.sh"
echo " - Verify domains/users/databases are detected"
echo "3. If Plesk test succeeds, we can integrate into main launcher"
echo ""