Created
November 6, 2013 07:14
-
-
Save vitaliel/7332183 to your computer and use it in GitHub Desktop.
Remove old linux packages from ubuntu/debian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keep=%w{3.5.0-41 3.5.0-42} | |
versions = Dir['/boot/System.map*'].sort.map do |f| | |
name = File.basename(f) | |
if name =~ /(\d+\.\d+\.\d+-\d+)/ | |
$1 | |
end | |
end | |
pkgs = [] | |
(versions-keep).each do |ver| | |
pkgs << "linux-image-#{ver}-generic" | |
pkgs << "linux-image-extra-#{ver}-generic" | |
pkgs << "linux-headers-#{ver}-generic" | |
end | |
all=`dpkg -l | grep 'linux-'`.split(/\n/).map {|line| line.split(/\s+/, 5)}.select {|el| el[1] =~ /linux-(image|headers)/} | |
#p all | |
installed = all.map {|e| e[1]} | |
missing = pkgs - installed | |
puts 'Missing' | |
p missing | |
pkgs -= missing | |
c = 'sudo apt-get purge ' + pkgs.join(' ') | |
puts c | |
system c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment