Skip to content

Instantly share code, notes, and snippets.

@stucka
Last active March 7, 2020 15:45
Show Gist options
  • Save stucka/0ced1cc71e1a5c374a18874471636d69 to your computer and use it in GitHub Desktop.
Save stucka/0ced1cc71e1a5c374a18874471636d69 to your computer and use it in GitHub Desktop.
Fix corrupted packages on Ubuntu (tested on Xubuntu 16.04) (works great with https://gist.github.com/stucka/09cbd34c8bfec0c37dd8a122362ef9c1)
#!/bin/bash
echo "Attempting to install debsums package"
apt-get install --reinstall -y debsums
echo "."
echo "."
echo "."
echo "Running debsums to look for bad files. This will take a while."
debsums -cs 2>&1 >badfiles.txt
echo "."
echo "."
echo "."
rm badfiles2.txt
sync
echo "Running dpkg to look for the packages that have the bad files. This will also take a while."
while read bf; do
dpkg --search $bf | awk '{ print $1 }' | sed 's/.$//' >>badfiles2.txt
done <badfiles.txt
echo "."
echo "."
echo "."
echo "Quick housekeeping."
rm fixbadpackages.sh
sync
echo -n "apt-get install --reinstall " >fixbadpackages.sh
cat badfiles2.txt | sort | uniq | tr '\n' ' ' >>fixbadpackages.sh
# rm badfiles.txt badfiles2.txt
chmod a+x fixbadpackages.sh
echo "."
echo "."
echo "."
echo "Run ./fixbadpackages.sh if you trust it. Read it first, will ya?"
echo "After it is done, you may wish to run it again and see what's still messed up."
echo "This program isn't built to deal with missing files."
echo "."
echo "And after that, if everything seems great for DAYS, ..."
echo "... consider running apt-get autoremove; apt-get clean; apt-get update; apt-get upgrade"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment