|
@@ -0,0 +1,76 @@
|
|
|
+-- This script will clean up all kernels older than current version.
|
|
|
+--
|
|
|
+-- This script must be plugged in the following slots:
|
|
|
+--
|
|
|
+-- Scripts::AptGet::Upgrade
|
|
|
+-- Scripts::AptGet::DistUpgrade
|
|
|
+-- Scripts::Synaptic::Upgrade
|
|
|
+-- Scripts::Synaptic::DistUpgrade
|
|
|
+--
|
|
|
+-- Author: Daisuke SUZUKI <daiuske@linux.or.jp>
|
|
|
+
|
|
|
+
|
|
|
+if confget("RPM::Remove-Old-Kernels/b", "true") == "false" then
|
|
|
+ return
|
|
|
+end
|
|
|
+
|
|
|
+-- remove old kernel and kernel-devel
|
|
|
+knames = {'kernel', 'kernel%-pae', 'kernel%-smp', 'kernel%-devel', 'kernel%-pae%-devel', 'kernel%-smp%-devel'}
|
|
|
+
|
|
|
+-- get current running kernel version
|
|
|
+function get_running_kernel_ver()
|
|
|
+ local inp = io.popen("uname -r")
|
|
|
+ local currentver = nil
|
|
|
+ for line in inp.lines(inp) do
|
|
|
+ currentver = string.gsub(line,"pae$","")
|
|
|
+ end
|
|
|
+ if currentver then
|
|
|
+ return currentver
|
|
|
+ else
|
|
|
+ return 0
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- get kernel version of vmlinuz.old
|
|
|
+function get_old_kernel_ver()
|
|
|
+ local inp = io.popen("readlink /boot/vmlinuz.old")
|
|
|
+ local oldver = nil
|
|
|
+ for line in inp.lines(inp) do
|
|
|
+ oldver = string.gsub(string.gsub(line,"pae$",""),"^vmlinuz%-","")
|
|
|
+ end
|
|
|
+ if oldver then
|
|
|
+ return oldver
|
|
|
+ else
|
|
|
+ return 0
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- remove all kernels older than current or vmlinuz.old
|
|
|
+function remove_old_kernels()
|
|
|
+ rkver = get_running_kernel_ver()
|
|
|
+ okver = get_old_kernel_ver()
|
|
|
+ pkgs = pkglist()
|
|
|
+ for i, pkg in ipairs(pkgs) do
|
|
|
+ ver = pkgvercur(pkg)
|
|
|
+ if not pkgisvirtual(pkg) and ver then
|
|
|
+ for j, kname in ipairs(knames) do
|
|
|
+ if string.find(pkgname(pkg), kname..'#') then
|
|
|
+ if ( verstrcmp(verstr(ver), rkver) < 0 and
|
|
|
+ verstrcmp(verstr(ver), okver) < 0 ) then
|
|
|
+ markremove(pkg)
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+--
|
|
|
+if script_slot == "Scripts::AptGet::DistUpgrade" or
|
|
|
+ script_slot == "Scripts::AptGet::Upgrade" or
|
|
|
+ script_slot == "Scripts::Synaptic::DistUpgrade" or
|
|
|
+ script_slot == "Scripts::Synaptic::Upgrade" then
|
|
|
+ remove_old_kernels()
|
|
|
+end
|
|
|
+
|
|
|
+-- vim:ts=4:sw=4:et
|