Files
linux_system_tuning/test-overlay-detection.sh
mindesbunister 548dc1d0d3 Remove overlay filesystem functionality and add detection/removal capability
- Remove unused overlay filesystem configuration and references
- Remove overlayfs sections from all profile JSON files
- Remove OVERLAY_ENABLED/OVERLAY_PROTECT_CONFIGS from config
- Update documentation to focus on tmpfs optimization
- Add overlay detection and removal functionality for cleanup
- Add remove_overlays() function with safe unmounting
- Add overlay status reporting in final optimization summary
- Add test-overlay-detection.sh for testing detection logic
- Simplify codebase by removing complex unused features
- Focus on proven desktop optimizations (tmpfs, zram, kernel)
2025-09-23 12:35:45 +02:00

114 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Test script to verify overlay detection and removal functionality
# This script creates a temporary overlay mount and tests detection
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log() {
echo -e "${BLUE}[TEST]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
echo "🔍 Testing Overlay Detection Functionality"
echo "=========================================="
echo ""
# Check if running as root (needed for mount operations)
if [[ $EUID -eq 0 ]]; then
warn "Running as root - will test actual mount/unmount operations"
CAN_MOUNT=true
else
log "Running as non-root - will test detection logic only"
CAN_MOUNT=false
fi
# Test 1: Check current overlay mounts
log "Test 1: Checking for existing overlay mounts..."
overlay_count=$(mount -t overlay 2>/dev/null | wc -l)
if [[ $overlay_count -eq 0 ]]; then
success "No existing overlay mounts found (expected for desktop systems)"
else
warn "Found $overlay_count existing overlay mounts:"
mount -t overlay | awk '{print " " $3}'
fi
echo ""
# Test 2: Test detection function (simulated)
log "Test 2: Testing overlay detection logic..."
cat << 'EOF'
# This is what the detection code does:
overlay_count=$(mount -t overlay | wc -l)
if [[ $overlay_count -gt 0 ]]; then
echo "Found $overlay_count overlay mounts"
mount -t overlay | awk '{print " " $3 " (overlay)"}'
else
echo "No overlay mounts found"
fi
EOF
echo ""
log "Running detection logic:"
if [[ $overlay_count -gt 0 ]]; then
echo " ⚠️ Found $overlay_count overlay mounts (would suggest removal)"
mount -t overlay | head -3 | awk '{print " " $3 " (overlay)"}'
else
echo " ✅ No overlay mounts found (good - not needed for desktop)"
fi
echo ""
# Test 3: Test temporary overlay creation (if root)
if [[ $CAN_MOUNT == true ]]; then
log "Test 3: Creating temporary overlay for testing..."
# Create temporary directories
mkdir -p /tmp/overlay-test/{lower,upper,work,merged}
echo "test content" > /tmp/overlay-test/lower/testfile.txt
# Create overlay mount
if mount -t overlay overlay -o lowerdir=/tmp/overlay-test/lower,upperdir=/tmp/overlay-test/upper,workdir=/tmp/overlay-test/work /tmp/overlay-test/merged 2>/dev/null; then
success "Created test overlay mount at /tmp/overlay-test/merged"
# Test detection again
new_overlay_count=$(mount -t overlay | wc -l)
log "Detection now shows: $new_overlay_count overlay mounts"
# Clean up
log "Cleaning up test overlay..."
umount /tmp/overlay-test/merged 2>/dev/null || true
rm -rf /tmp/overlay-test
success "Test overlay cleaned up"
else
error "Failed to create test overlay (this is normal on some systems)"
rm -rf /tmp/overlay-test
fi
else
log "Test 3: Skipped (requires root privileges)"
fi
echo ""
success "Overlay detection test completed!"
echo ""
log "Summary:"
echo " • Overlay detection logic works correctly"
echo " • Current system has $overlay_count overlay mounts"
echo " • Desktop systems typically don't need overlay filesystems"
echo " • The optimizer will offer to remove any found overlays"