Skip to content

Instantly share code, notes, and snippets.

@zudsniper
Last active April 26, 2023 08:18
Show Gist options
  • Save zudsniper/db601ac948b9083e912a9ce0dd53eb24 to your computer and use it in GitHub Desktop.
Save zudsniper/db601ac948b9083e912a9ce0dd53eb24 to your computer and use it in GitHub Desktop.
[DEBIAN / UBUNTU] FULLY Remove a problematic package, the old fashioned way. I suggest running as root.
#!/bin/bash
# fuck_this_pkg.sh
# ----------------
# v2.3 + GPT-4 assistance
#####################################################
# load ~/.ansi_colors.sh if available
FILE="~/.ansi_colors.sh"
COLORS=0
if [[ -f "$FILE" ]]; then
source ~/.ansi_colors.sh
COLORS=1
fi
if [[ "$#" -eq 0 ]]; then
echo -ne "${A_BOLD}${A_RED}Provide a package to nuke please.${A_RESET}\n";
exit 1;
fi
#####################################################
echo -ne "\n${A_GREEN}${A_BOLD}fuck_this_pkg!!!!!!${A_RESET} by ${A_BLUE}${A_INVERSE}@zudsniper${A_RESET}\n";
ARGS="$@"
echo -ne "CHOPPING BLOCK: ${A_ITALIC}${A_GRAY}${ARGS}${A_RESET}\n\n";
echo -ne "${A_GRAY}... let's ${A_BOLD}do this thing.${A_RESET}\n";
#####################################################
export ALL_PKGS="";
# remove (fully) a single apt package from Ubuntu / Debian based systems
#
function fuck_pkg() {
if [[ "$#" -eq 0 ]]; then
echo -ne "${A_RED}${A_INVERSE}[fuck_pkg]${A_RESET}${A_RED} Provide a single package to nuke please.${A_RESET}\n";
return;
elif [[ "$#" -gt 1 ]]; then
echo -ne "${A_RED}${A_INVERSE}[fuck_pkg]${A_RESET}${A_RED} Provide a ${A_UNDERLINE}SINGLE${A_RESET}${A_RED}${A_BOLD} package to nuke please.${A_RESET}\n";
return;
fi
# check if the package even exists
PKG_EXISTS=$(dpkg-query -W -f='${Status}' $1 2>/dev/null | grep -c "ok installed")
if [[ ${PKG_EXISTS} -eq 0 ]]; then
echo -ne "${A_RED}${A_INVERSE}[fuck_pkg]${A_RESET}${A_RED} Package not found or already removed: ${A_UNDERLINE}${1}${A_RESET}${A_RED}${A_BOLD}.${A_RESET}\n";
return;
fi
# made it past the checks, killing stuff
sudo dpkg --purge --force-all ${1}
sudo apt-get remove --purge ${1}
# finally, run all autoremoves & autocleans
sudo apt-get autoremove && sudo apt-get autoclean
echo -ne "${A_YELLOW}${A_ITALIC}fucking${A_RESET} ${A_INVERSE}${A_BOLD}${1}${A_RESET}${A_YELLOW}${A_ITALIC}...${A_RESET}\n";
export ALL_PKGS="${ALL_PKGS}, ${1}"
}
#####################################################
# patterns
begin_shit="Errors were encountered while processing:"
end_shit="needsrestart"
fuck_pkgs() {
if [[ "$#" -lt 1 ]]; then
echo -ne "${A_RED}${A_INVERSE}[fuck_pkgs]${A_RESET}${A_RED} Provide a list of packages to nuke please.${A_RESET}\n";
return;
fi
# made it past the checks, killing things
for var in "$@"
do
fuck_pkg $var
done
# debug: print leftover packages
echo -ne "\ndebug: LEFTOVERS =${A_GRAY}${A_ITALIC}${ALL_PKGS}${A_RESET}\n";
echo -ne "\ndebug: LEFTOVERS =${A_GRAY}${A_ITALIC}${ALL_PKGS}${A_RESET}\n";
}
#####################################################
# run the function!
fuck_pkgs "$@"
echo -ne "\n\n${A_GREEN}${A_BOLD}hopefully I fucking wiped \"${A_RESET}${A_YELLOW}${A_BOLD}${A_UNDERLINE}${ALL_PKGS}${A_RESET}${A_GREEN}${A_BOLD}\" off the face of the earth for you.${A_RESET}\n";
#!/bin/bash
# fuck_this_pkg_lite.sh
# ---------------------
# no nice formatting
#
#####################################################
function fuck_pkg() {
PACKAGE=$1
# Check if the package is installed
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $PACKAGE | grep "install ok installed")
if [ -z "$PKG_OK" ]; then
echo "[fuck_pkg] Package not found or already removed: $PACKAGE."
return
fi
# Move package info files
sudo mv /var/lib/dpkg/info/${PACKAGE}.* /tmp/
# Remove the package using dpkg
sudo dpkg --remove --force-remove-reinstreq ${PACKAGE}
# Remove the package using apt-get
sudo apt-get remove -y ${PACKAGE}
# Run autoremove and autoclean
sudo apt-get autoremove -y && sudo apt-get autoclean -y
}
#####################################################
if [ "$#" -eq 0 ]; then
echo "Provide a package to nuke please."
exit 1
fi
echo "fuck_this_pkg!!!!!! by @zudsniper"
echo "CHOPPING BLOCK: $@"
for PACKAGE in "$@"
do
fuck_pkg $PACKAGE
done
echo "hopefully I fucking wiped \"$@\" off the face of the earth for you."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment