#!/bin/bash

# KNEL Dell Server Configuration Initializer
# Applies Dell-specific optimizations and tools

set -euo pipefail

echo "Running Dell server configuration initializer..."

# Only run on Dell physical servers
if [[ $IS_PHYSICAL_HOST -gt 0 ]]; then
    echo "Dell physical hardware detected, applying Dell-specific configurations..."
    
    # CPU performance tuning (from fixcpuperf.sh)
    if command -v cpufreq-set >/dev/null 2>&1; then
        cpufreq-set -r -g performance
        echo "Set CPU performance governor"
    fi
    
    if command -v cpupower >/dev/null 2>&1; then
        cpupower frequency-set --governor performance
        echo "Set CPU frequency governor to performance"
    fi
    
    # Copy Dell-specific scripts if they exist
    mkdir -p /opt/dell-tools
    
    if [[ -f ./scripts/fixeth.sh ]]; then
        cp ./scripts/fixeth.sh /opt/dell-tools/
        chmod +x /opt/dell-tools/fixeth.sh
        echo "Copied Ethernet fixing script"
    fi
    
    if [[ -f ./scripts/omsa.sh ]]; then
        cp ./scripts/omsa.sh /opt/dell-tools/
        chmod +x /opt/dell-tools/omsa.sh
        echo "Copied OMSA setup script"
    fi
    
    # Install Dell OpenManage Server Administrator if available
    if command -v apt >/dev/null 2>&1; then
        # Add Dell repository if available
        # This would need to be implemented when Dell repo access is available
        echo "Dell OMSA installation would go here (requires Dell repo access)"
    fi
    
else
    echo "Not a Dell physical server, skipping Dell-specific configurations"
fi

echo "Dell server configuration initializer completed"