forked from openSUSE/sdbootutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernelhooks.lua
72 lines (61 loc) · 1.82 KB
/
kernelhooks.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
kernelhooks = { debug = nil } -- package
kernelhooks.found = {}
kernelhooks.legacy = {} -- entries in /boot
kernelhooks.imagename = "vmlinuz" -- FIXME: arch dependent!
kernelhooks.kernelpattern = string.format("^/usr/lib/modules/(.*)/%s", kernelhooks.imagename)
-- beware of crazy lua patterns, - is similar to * and % is escape character
kernelhooks.legacypattern = string.format("^/boot/%s%%-(.+)", kernelhooks.imagename)
-- for testing outside rpm
if posix == nil then
posix = require("posix")
end
function _log(msg)
if kernelhooks.debug then
print(kernelhooks.debug .. ": " .. msg)
end
end
function rootpath(path)
_, _, p = string.find(path, "^/usr(/.*)")
return p
end
function dirname(path)
_, _, d, b = string.find(path, "^(.*)/([^/]*)")
return d
end
function kernelhooks.filter(path)
_, _, kver = string.find(path, kernelhooks.kernelpattern)
if kver then
_log("found kernel " .. kver)
kernelhooks.found[kver] = path
return
end
_, _, kver = string.find(path, kernelhooks.legacypattern)
if kver then
_log("kernel " .. kver .. " in /boot")
kernelhooks.legacy[kver] = 1
return
end
end
function kernelhooks.add()
for kver in pairs(kernelhooks.found) do
if kernelhooks.legacy[kver] then
_log("not adding " .. kver .. " due to legacy /boot location")
else
_log("adding " .. kver)
rpm.execute("/usr/sbin/depmod", "-a", kver)
rpm.execute("/usr/bin/sdbootutil", "add-kernel", kver)
rpm.execute("/usr/bin/sdbootutil", "set-default-snapshot")
end
end
end
function kernelhooks.remove()
for kver in pairs(kernelhooks.found) do
if kernelhooks.legacy[kver] then
_log("not removing " .. kver .. " due to legacy /boot location")
else
_log("removing " .. kver)
rpm.execute("/usr/bin/sdbootutil", "remove-kernel", kver)
rpm.execute("/usr/bin/sdbootutil", "set-default-snapshot")
end
end
end