-- rpm::upgrade-kernel only for backwards compatibility
if confget("RPM::Upgrade-Virtual/b", "false") == "false" and confget("RPM::Upgrade-Kernel/b", "false") == "false" then
return
end
knames = { "hugemem", "bigmem", "enterprise", "smp", "BOOT" }
-- get kernel package name for running kernel (kernel-smp, kernel, etc)
function get_kerneltype()
for i, ktype in ipairs(knames) do
if string.find(posix.uname("%r"), ktype) then
return "kernel-"..ktype
end
end
-- it's either unknown type or normal UP system
return "kernel"
end
-- if grubby is available set default kernel to version
function set_default(version)
vmlinuz = '/boot/vmlinuz-'..version
if posix.access('/sbin/grubby', 'x') and posix.access(vmlinuz, 'f') then
os.execute('/sbin/grubby --set-default='..vmlinuz)
end
end
-- find + mark for install any packages where uname -r is part of pkg name
-- eg external kernel modules
function upgrade_kernel_modules(new_version)
modprefix = confgetlist("Kernel::Module-Prefix")
if not new_version or not modprefix then
return
end
pkgs = pkglist()
for i, pkg in ipairs(pkgs) do
-- oh fun.. loop through all installed packages and see there are
-- any which provide module-prefix, try to install version matching
-- our new kernel
if not pkgisvirtual(pkg) and pkgvercur(pkg) then
ver = pkgvercur(pkg)
for j, prov in ipairs(verprovlist(ver)) do
for x, prefix in ipairs(modprefix) do
if string.sub(prov.name, 1, string.len(prefix)) == prefix then
inst = pkgfind(prov.name.."-"..new_version)
if inst then
markinstall(inst)
else
print("WARNING: "..prov.name.." not available for kernel "..new_version.."!")
end
end
end
end
end
end
end
-- find all virtualized packages, their versions and if they're installed
function find_instonly_pkgs()
pkgs = {}
for i, pkg in ipairs(pkglist()) do
idx = string.find(pkgname(pkg), "#")
ver = pkgvercur(pkg)
if idx and not pkgisvirtual(pkg) then
name = string.sub(pkgname(pkg), 1, idx-1)
if not ver then
ver = pkgvercand(pkg)
end
-- new entry
if not pkgs[name] then
tmp = {}
tmp.pkg = pkg
tmp.ver = ver
tmp.inst = false
pkgs[name] = tmp
end
if pkgvercur(pkg) then
pkgs[name].inst = true
end
-- mark it as latest if newer than what already known
if ver and verstrcmp(verstr(ver), verstr(pkgs[name].ver)) > 0 then
pkgs[name].ver = ver
pkgs[name].pkg = pkg
end
end
end
return pkgs
end
-- mark installed virtualized packages for "upgrade"
function mark_upgrade(name, pkg)
ktype = get_kerneltype()
if pkg.inst then
markinstall(pkg.pkg)
if name == ktype then
confset('Kernel::New-Version', verstr(pkg.ver))
end
end
end
-- find the latest version of given virtual pkg for installation
function mark_install(virtualpkg)
ktype = get_kerneltype()
pkgs = find_instonly_pkgs()
for name in pkgs do
if name == virtualpkg then
selected = pkgs[name].pkg
end
end
if virtualpkg == ktype then
confset('Kernel::New-Version', verstr(pkgs[virtualpkg].ver))
end
end
-- normal install operation
if script_slot == 'Scripts::AptGet::Install::SelectPackage' then
modprefix = confgetlist('Kernel::Module-Prefix')
for i, prefix in ipairs(modprefix) do
if string.find(virtualname, prefix, 1, true) then
moduname = virtualname.."-"..posix.uname("%r")
modpkg = pkgfind(moduname)
if modpkg then
selected = modpkg
else
apterror(_("Couldn't find package "..moduname))
return
end
end
end
mark_install(virtualname)
return
elseif script_slot == 'Scripts::AptGet::Install::PreResolve' then
ktype = get_kerneltype()
if not confexists('Kernel::New-Version') then
for i, pkg in ipairs(pkglist()) do
idx = string.find(pkgname(pkg), "#")
if statinstall(pkg) and idx then
name = string.sub(pkgname(pkg), 1, idx-1)
if ktype == name then
confset('Kernel::New-Version', verstr(pkgvercand(pkg)))
end
end
end
end
if confexists('Kernel::New-Version') then
upgrade_kernel_modules(confget('Kernel::New-Version'))
end
elseif script_slot == 'Scripts::AptGet::Upgrade' or
script_slot == 'Scripts::AptGet::DistUpgrade' then
pkgs = find_instonly_pkgs()
table.foreach(pkgs, mark_upgrade)
upgrade_kernel_modules(confget('Kernel::New-Version'))
elseif script_slot == 'Scripts::PM::Post' then
if confget('Kernel::Set-Default/b', "false") == "true" then
set_default(confget('Kernel::New-Version'))
end
end
-- vim:ts=4