View Single Post
Posts: 540 | Thanked: 387 times | Joined on May 2009
#25
I didn't read the whole thread but this script I wrote for these types of situations and it might work.

Code:
#!/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;
Attached Files
File Type: txt fixapt.txt (1.1 KB, 332 views)
 

The Following 3 Users Say Thank You to linuxeventually For This Useful Post: