#!/bin/bash
# Revert to LXDE Desktop Environment
# This script helps revert from KDE Plasma back to LXDE

echo "=== Reverting to LXDE Desktop Environment ==="
echo ""

# Check if running as root for some operations
if [ "$EUID" -ne 0 ]; then 
    echo "Some operations require sudo. You may be prompted for your password."
    echo ""
fi

# Method 1: Change default session
echo "Step 1: Setting LXDE as default session..."
echo "You will be prompted to select the session manager."
echo ""
sudo update-alternatives --config x-session-manager

# Method 2: Verify LXDE packages are still installed
echo ""
echo "Step 2: Verifying LXDE packages..."
if dpkg -l | grep -q "lxsession"; then
    echo "✓ LXDE packages are installed"
else
    echo "⚠ LXDE packages not found. Reinstalling..."
    sudo apt-get update
    sudo apt-get install --reinstall lxde
fi

# Method 3: Check available sessions
echo ""
echo "Step 3: Available desktop sessions:"
ls -1 /usr/share/xsessions/ | grep -E "openbox|rpd|lxde" || echo "No LXDE sessions found"

echo ""
echo "=== Revert Complete ==="
echo ""
echo "To use LXDE:"
echo "1. Log out of current session"
echo "2. At login screen, click on session/desktop selector"
echo "3. Select 'Openbox' or 'RPD-X' session"
echo "4. Log in"
echo ""
echo "Or reboot and select LXDE at login:"
echo "  sudo reboot"
