#!/bin/bash # Author : Eshan Roy # Author URL : https://eshanized.github.io/ set -e # Exit immediately if a command exits with a non-zero status # Function to display error message and exit error_handler() { echo -e "\n๐Ÿšจ An error occurred during the uninstallation process." echo "Error on line $1. Please check your system and try again." exit 1 } # Trap errors and call error_handler trap 'error_handler $LINENO' ERR # Ensure the script is run as root if [ "$EUID" -ne 0 ]; then echo "โŒ Please run this script as root or with sudo." exit 1 fi # Check if a package name is provided if [ -z "$1" ]; then echo "โŒ No package specified." echo "Usage: $0 " exit 1 fi PACKAGE=$1 # Confirm with the user read -p "Are you sure you want to uninstall $PACKAGE and remove its cache? [y/N]: " CONFIRM if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then echo "โŒ Operation cancelled." exit 0 fi # Uninstall the package and its dependencies echo "๐Ÿ“ฆ Uninstalling $PACKAGE..." sudo pacman -Rns $PACKAGE --noconfirm || { echo "โŒ Failed to uninstall $PACKAGE."; exit 1; } # Remove the package's cache echo "๐Ÿ—‘๏ธ Removing cache for $PACKAGE..." sudo pacman -Sc --noconfirm || echo "โ— Cache removal skipped." # Clean up orphaned packages echo "๐Ÿงน Cleaning up orphaned packages..." sudo pacman -Rns $(pacman -Qtdq) --noconfirm || echo "No orphaned packages to remove." echo -e "\nโœ… Package $PACKAGE successfully uninstalled!" exit 0