#!/bin/sh # fixapt - force uninstall broken .deb package # Define temporary directory location tmpdir="/dev/shm"; # Check distro ifapt=$(which apt-get 2>/dev/null); if [ -z "$ifapt" ]; then echo "Non-debian distribution"; exit 0; fi # Check for root if [ "$UID" = "0" ]; then ifroot="yes"; else if [ "$USER" = "root" ]; then ifroot="yes"; fi fi if [ "$ifroot" != "yes" ]; then echo "Need to be root"; exit 0; fi # Sanity check ifempty=$(apt-get -s -f install | grep -A 1 REMOVED); if [ -z "$ifempty" ]; then echo "No broken packages"; exit 0; fi # Force remove packages apt-get -y -f install > ${tmpdir}/broken; # Create backup directory if [ -d "/var/lib/dpkg/info" ]; then if [ ! -d "/var/lib/dpkg/broken" ]; then mkdir /var/lib/dpkg/broken; fi; fi; # Important: Delete cached files for i in $(cat ${tmpdir}/broken | grep -A 1 REMOVED | awk NR==2 | sed 's/ //g'); do echo $i; mv /var/lib/dpkg/info/${i}.* /var/lib/dpkg/broken/; dpkg --remove --force-remove-reinstreq ${i}; done; # Check if successful apt-get -f install ifempty=$(apt-get -s -f install | grep -A 1 REMOVED); if [ -z "$ifempty" ]; then echo "Done"; else echo "Error"; fi;