## Paste this as a text file named 'maintenance'
## Then make exectuable
chmod +x maintenance
## Then run it
sh ./maintenance
#!/bin/bash
echo "Checking for root"
sudo true
sudo echo "OK got root"
echo "You will see no output for up to 5 minutes. Please wait"
echo " Removing the /var/lib/dpkg directory"
sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup
echo " Reverting to the previous package states"
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available
echo " Removing the cached lists of packages"
sudo rm -rf /var/lib/dpkg/updates/*
sudo rm -rf /var/lib/apt/lists
echo " Remake directories that apt will not remake itsself"
sudo mkdir /var/lib/apt/lists
sudo mkdir /var/lib/apt/lists/partial
echo " Removing cached .deb files in case any are corrupted"
sudo apt-get clean
echo " Updating the list of available package versions"
sudo apt-get update >/dev/null
echo " Removing dpkg's list of available packages"
sudo dpkg --clear-avail
echo " Finishing configuring any packages which have yet to be configured."
sudo dpkg --configure -a
echo " Installing any missing dependencies"
sudo apt-get install -fy >/dev/null
#sudo -k
echo "Done!"
echo