- Fixed missing setup_tmpfs() function that was causing silent failures - Added comprehensive system scanning for browsers, IDEs, gaming caches - Implemented detailed optimization information display for transparency - Added German locale compatibility for 'free' command (Speicher: vs Mem:) - Fixed division by zero errors in RAM calculations - Created tmpfs-info.sh helper script for detailed status reporting - Enhanced scanning to work on already-optimized systems - Added comprehensive optimization breakdowns with purpose explanations
178 lines
4.4 KiB
Bash
Executable File
178 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Hardware Detection Module
|
|
# Part of Linux System Tuning Suite
|
|
|
|
detect_hardware() {
|
|
local output_file="${1:-/dev/stdout}"
|
|
|
|
# Detect RAM
|
|
local ram_total_gb=$(free -g | awk '/^Mem:/{print $2}')
|
|
local ram_total_mb=$(free -m | awk '/^Mem:/{print $2}')
|
|
local ram_available_gb=$(free -g | awk '/^Mem:/{print $7}')
|
|
|
|
# Detect CPU
|
|
local cpu_cores=$(nproc)
|
|
local cpu_threads=$(lscpu | grep "^CPU(s):" | awk '{print $2}')
|
|
local cpu_model=$(lscpu | grep "Model name:" | sed 's/Model name:[[:space:]]*//')
|
|
local cpu_arch=$(uname -m)
|
|
local cpu_freq=$(lscpu | grep "CPU MHz:" | awk '{print $3}' | head -1)
|
|
|
|
# Detect storage
|
|
local ssd_count=0
|
|
local hdd_count=0
|
|
local nvme_count=0
|
|
|
|
while IFS= read -r line; do
|
|
if [[ "$line" =~ nvme ]]; then
|
|
((nvme_count++))
|
|
elif [[ "$line" =~ "0$" ]]; then
|
|
((ssd_count++))
|
|
elif [[ "$line" =~ "1$" ]]; then
|
|
((hdd_count++))
|
|
fi
|
|
done < <(lsblk -d -o name,rota 2>/dev/null | tail -n +2)
|
|
|
|
# Detect GPU
|
|
local gpu_info=""
|
|
if command -v lspci >/dev/null 2>&1; then
|
|
gpu_info=$(lspci | grep -i "vga\|3d\|display" | head -1)
|
|
fi
|
|
|
|
# Generate hardware profile
|
|
cat > "$output_file" << EOF
|
|
{
|
|
"ram": {
|
|
"total_gb": $ram_total_gb,
|
|
"total_mb": $ram_total_mb,
|
|
"available_gb": $ram_available_gb,
|
|
"classification": "$(classify_ram_size $ram_total_gb)"
|
|
},
|
|
"cpu": {
|
|
"cores": $cpu_cores,
|
|
"threads": $cpu_threads,
|
|
"model": "$cpu_model",
|
|
"architecture": "$cpu_arch",
|
|
"frequency_mhz": ${cpu_freq:-0},
|
|
"classification": "$(classify_cpu_performance $cpu_cores)"
|
|
},
|
|
"storage": {
|
|
"nvme_drives": $nvme_count,
|
|
"ssd_drives": $ssd_count,
|
|
"hdd_drives": $hdd_count,
|
|
"primary_type": "$(determine_primary_storage_type $nvme_count $ssd_count $hdd_count)"
|
|
},
|
|
"gpu": "$gpu_info",
|
|
"optimization_profile": "$(determine_optimization_profile $ram_total_gb $cpu_cores $nvme_count $ssd_count)"
|
|
}
|
|
EOF
|
|
}
|
|
|
|
classify_ram_size() {
|
|
local ram_gb=$1
|
|
|
|
if [[ $ram_gb -ge 32 ]]; then
|
|
echo "very_high"
|
|
elif [[ $ram_gb -ge 16 ]]; then
|
|
echo "high"
|
|
elif [[ $ram_gb -ge 8 ]]; then
|
|
echo "medium"
|
|
elif [[ $ram_gb -ge 4 ]]; then
|
|
echo "low"
|
|
else
|
|
echo "very_low"
|
|
fi
|
|
}
|
|
|
|
classify_cpu_performance() {
|
|
local cores=$1
|
|
|
|
if [[ $cores -ge 16 ]]; then
|
|
echo "very_high"
|
|
elif [[ $cores -ge 8 ]]; then
|
|
echo "high"
|
|
elif [[ $cores -ge 4 ]]; then
|
|
echo "medium"
|
|
elif [[ $cores -ge 2 ]]; then
|
|
echo "low"
|
|
else
|
|
echo "very_low"
|
|
fi
|
|
}
|
|
|
|
determine_primary_storage_type() {
|
|
local nvme=$1
|
|
local ssd=$2
|
|
local hdd=$3
|
|
|
|
if [[ $nvme -gt 0 ]]; then
|
|
echo "nvme"
|
|
elif [[ $ssd -gt 0 ]]; then
|
|
echo "ssd"
|
|
elif [[ $hdd -gt 0 ]]; then
|
|
echo "hdd"
|
|
else
|
|
echo "unknown"
|
|
fi
|
|
}
|
|
|
|
determine_optimization_profile() {
|
|
local ram_gb=$1
|
|
local cores=$2
|
|
local nvme=$3
|
|
local ssd=$4
|
|
|
|
# High-end system
|
|
if [[ $ram_gb -ge 16 && $cores -ge 8 && ($nvme -gt 0 || $ssd -gt 0) ]]; then
|
|
echo "aggressive"
|
|
# Mid-range system
|
|
elif [[ $ram_gb -ge 8 && $cores -ge 4 ]]; then
|
|
echo "moderate"
|
|
# Low-end system
|
|
elif [[ $ram_gb -ge 4 ]]; then
|
|
echo "conservative"
|
|
# Very low-end system
|
|
else
|
|
echo "minimal"
|
|
fi
|
|
}
|
|
|
|
# Function to get recommended zram size based on RAM
|
|
get_recommended_zram_size() {
|
|
local ram_gb=$(free -g | awk '/^Mem:/{print $2}')
|
|
|
|
if [[ $ram_gb -ge 32 ]]; then
|
|
echo "16G"
|
|
elif [[ $ram_gb -ge 16 ]]; then
|
|
echo "12G"
|
|
elif [[ $ram_gb -ge 8 ]]; then
|
|
echo "6G"
|
|
elif [[ $ram_gb -ge 4 ]]; then
|
|
echo "4G"
|
|
else
|
|
echo "2G"
|
|
fi
|
|
}
|
|
|
|
# Function to get recommended tmpfs sizes
|
|
get_recommended_tmpfs_sizes() {
|
|
local ram_gb=$(free -g | awk '/^Mem:/{print $2}')
|
|
local profile="$1"
|
|
|
|
case "$profile" in
|
|
"aggressive")
|
|
echo "browser:4G,ide:2G,packages:3G,thumbnails:512M"
|
|
;;
|
|
"moderate")
|
|
echo "browser:2G,ide:1G,packages:2G,thumbnails:256M"
|
|
;;
|
|
"conservative")
|
|
echo "browser:1G,ide:512M,packages:1G,thumbnails:128M"
|
|
;;
|
|
"minimal")
|
|
echo "browser:512M,packages:512M"
|
|
;;
|
|
*)
|
|
echo "browser:1G,packages:1G"
|
|
;;
|
|
esac
|
|
} |