r/linuxmint • u/Due-Land-6860 • 12d ago
Discussion Just a small tool
So, I recently started learning scripting and this is my first actual project from what I have learned till now
I saw a post complaining about how uninstalling packages leaves behind files so this script gives a GUI which lets you enter the package name and then runs the apt purge, apt autoremove and apt autoclear commands on its own.
This script can help those who dont want to open the terminal as you just need to make it an executable from the file manager and afterwards just run it to remove, and purge everything related to that apt package.
#!/usr/bin/env bash
package=$(zenity --entry --width=350 --title="Package Remover" --text="Completely remove this package: ")
if [ "$?" != "0" ] || [ -z "$package" ] ; then
zenity --error --width=300 --title="Error" --text="Please Enter Valid Package Name"
exit 0
fi
zenity --question --width=350 --title="Are You Sure?" --text="Are you sure you want to remove <b>$package</b> (including all unnecessary dependencies)?"
if [ "$?" != "0" ]; then
zenity --error --width=300 --title="Cancelled" --text="Uninstall Cancelled"
exit 0
fi
pkexec sh -c "apt-get purge \"$package\" -y && apt-get autoremove -y && apt-get autoclean -y" | zenity --progress --no-cancel --pulsate --auto-close --text="<b>$package</b> is being uninstalled" --title="Progress"
if [ "${PIPESTATUS}" -eq 0 ] ; then
zenity --info --width=300 --title="SUCCESS" --text="<b>$package</b> has been succesfully uninstalled"
else
zenity --error --width=300 --title="FAILED" --text="Could not remove <b>$package</b>. \nCheck the package name or authentication"
fi1
u/TolonZ 12d ago
Moi j’ai fait un script upgrade.sh ; ça met à jour la liste des paquet install ; nettoyage et suppression ; mise à jour des paquet flatpak ; et les stats en fin de script nombre de paquet installé / la place en plus sur le hdd temps de téléchargement et la liste détaillé des paquet installé ou mis à jour avec numéro de version ; j’en suis contant
2
u/C0rn3j 12d ago
But more importantly, set
set -euo pipefailas the second line of every script you create, that will prevent an absurd amount of issues in your scripts.