#!/bin/bash# Script to remove Akonadi/PIM bloat, unused media tools, office suites, and clear caches on Fedora KDE.# Exit immediately if a command fails, an unset variable is referenced, or a pipe breaksset-euopipefail
# -----------------------------------------------------------------------------# Configuration# -----------------------------------------------------------------------------LOGDIR="/var/log/packageupdateslogs"LOGFILE="${LOGDIR}/debloat_fedora.log"# Ensure the log directory exists with safe permissionsmkdir-p"$LOGDIR"chmod755"$LOGDIR"# Identify OS release dynamicallyFEDORA_VERSION=$(./etc/os-release2>/dev/null&&echo"${VERSION_ID:-}")# Logger Functionlog_message(){localTIMESTAMP
TIMESTAMP=$(date"+%Y-%m-%d %H:%M:%S")echo"[$TIMESTAMP] $1"|tee-a"$LOGFILE"}# -----------------------------------------------------------------------------# Privilege Check# -----------------------------------------------------------------------------if[[$EUID-ne0]];thenecho"[ERROR] This cleanup script must be run as root or via sudo.">&2exit1filog_message"=== Starting Fedora $FEDORA_VERSION KDE Plasma Debloat & Cleanup ==="# Remove only the packages that are actually installed. Asking dnf to remove a# package that isn't installed can make it exit with an error, which would stop# this script part-way (set -e). Patterns like 'openoffice*' are matched by rpm.remove_installed(){locallabel="$1"shiftlocalpresent=()pkg
forpkgin"$@";dowhileIFS=read-rname;do[[-n"$name"]]&&present+=("$name")done<<(rpm-qa--qf'%{NAME}\n'"$pkg"2>/dev/null|sort-u)doneif[[${#present[@]}-eq0]];thenlog_message"${label}: nothing to remove."return0filog_message"${label}: removing ${present[*]}"dnfremove-y"${present[@]}"2>&1|tee-a"$LOGFILE"}# -----------------------------------------------------------------------------# 1. Remove KDE PIM (Personal Information Management) & Akonadi# -----------------------------------------------------------------------------remove_installed"KDE PIM stack and Akonadi"\akonadi\akonadi-server\kmail\korganizer\kaddressbook\kontact\knotes\akregator\kdepim-runtime
# -----------------------------------------------------------------------------# 2. Remove Redundant Utilities, Media Players, Games & Extra Apps# -----------------------------------------------------------------------------remove_installed"Extra desktop apps"\dragonplayer\elisa-player\kmahjongg\kmines\ksudoku\kpat\konversation\kmag\kmousetool\kwrite\krdc\krfb\mediawriter\ktorrent\falkon\konqueror\kamoso\skanlite\skanpage\neochat\tokodon\kget
# -----------------------------------------------------------------------------# 3. Remove Office Suites (LibreOffice / OpenOffice)# -----------------------------------------------------------------------------remove_installed"Office suites"\'libreoffice*'\'openoffice*'# -----------------------------------------------------------------------------# 4. Clean DNF Packages, Orphans, and System Caches# -----------------------------------------------------------------------------log_message"Removing orphaned dependencies..."dnfautoremove-y2>&1|tee-a"$LOGFILE"log_message"Cleaning DNF metadata and package cache..."dnfcleanall2>&1|tee-a"$LOGFILE"log_message"Trimming systemd journal logs (retaining last 7 days)..."journalctl--vacuum-time=7d2>&1|tee-a"$LOGFILE"# -----------------------------------------------------------------------------# 5. Flatpak Cleanup# -----------------------------------------------------------------------------ifcommand-vflatpak>/dev/null2>&1;thenlog_message"Removing unused Flatpak runtimes and applications..."flatpakuninstall--unused-y2>&1|tee-a"$LOGFILE"log_message"Repairing Flatpak installations..."flatpakrepair2>&1|tee-a"$LOGFILE"||log_message"flatpak repair reported problems; continuing."elselog_message"Flatpak not installed. Skipping Flatpak cleanup."fi# -----------------------------------------------------------------------------# 6. User-Level Cache Cleanup (KDE Sycoca and Thumbnail Cache)# -----------------------------------------------------------------------------log_message"Cleaning KDE system configuration cache and thumbnails for all users..."# Iterate through all regular user directories in /homeforuser_dirin/home/*;doif[[-d"$user_dir"]];thenrm-rf"${user_dir}/.cache/ksycoca"*2>/dev/null||truerm-rf"${user_dir}/.cache/thumbnails"*2>/dev/null||truefidone# Clean root cache as wellrm-rf/root/.cache/ksycoca*2>/dev/null||truerm-rf/root/.cache/thumbnails*2>/dev/null||true# -----------------------------------------------------------------------------# Completion# -----------------------------------------------------------------------------log_message"=== Debloat and cleanup completed successfully at $(date)! ==="echo-e"\n[DONE] System debloated successfully! Rebooting is recommended."