Skip to content

Instantly share code, notes, and snippets.

@hron84
Last active October 19, 2015 09:29
Show Gist options
  • Save hron84/2a083cb64618f33b81b6 to your computer and use it in GitHub Desktop.
Save hron84/2a083cb64618f33b81b6 to your computer and use it in GitHub Desktop.
#!/bin/bash
PKGFILE=/tmp/kernelpurge.$$
true > $PKGFILE
dpkg --get-selections | awk '$2 !~ /^install/ { next } $1 ~ /^linux-image-[0-9]/ { print $1 }' | head -n -1 | fgrep -v "$(uname -r)" >> $PKGFILE
dpkg --get-selections | awk '$2 !~ /^install/ { next } $1 ~ /^linux-image-extra-[0-9]/ { print $1 }' | head -n -1 | fgrep -v "$(uname -r)" | tac >> $PKGFILE
dpkg --get-selections | awk '$2 !~ /^install/ { next } $1 ~ /^linux-headers-[0-9]/ { print $1 }' | head -n -1 | fgrep -v "$(uname -r)" | tac >> $PKGFILE
lines=$(cat $PKGFILE | wc -l)
if [ $lines -eq 0 ] ; then
exit 0
fi
dpkg -P $(cat $PKGFILE) | tee /var/log/kernelpurge-$(date +%F).log
apt-get -f -o Dpkg::Options::=--force-confold install || exit 1
rm -f $PKGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment