aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lua/test/automenu.lua
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lua/test/automenu.lua')
-rw-r--r--com32/lua/test/automenu.lua38
1 files changed, 24 insertions, 14 deletions
diff --git a/com32/lua/test/automenu.lua b/com32/lua/test/automenu.lua
index 1e66cca1..002fb095 100644
--- a/com32/lua/test/automenu.lua
+++ b/com32/lua/test/automenu.lua
@@ -26,6 +26,17 @@ local function modifiers ()
return (single and " single" or "") .. ({" quiet",""," debug"})[verbosity]
end
+local function boot (kernel_path, initrd_path, cmdline)
+ print ("Loading " .. kernel_path .. " ...")
+ local kernel = sl.loadfile (kernel_path)
+ local initrd
+ if (initrd_path) then
+ print ("Loading " .. initrd_path .. " ...")
+ initrd = sl.initramfs():load (initrd_path)
+ end
+ sl.boot_it (kernel, initrd, cmdline)
+end
+
local function scan (params)
local sep = string.sub (params.dir, -1) == "/" and "" or "/"
if not params.items then params.items = {} end
@@ -35,14 +46,16 @@ local function scan (params)
local from,to,version = string.find (name, "^vmlinuz%-(.*)")
if from then
local initrd = params.dir .. sep .. "initrd.img-" .. version
- local initrd_param = ""
- if lfs.attributes (initrd, "size") then
- initrd_param = "initrd=" .. initrd .. " "
+ if not lfs.attributes (initrd, "size") then
+ initrd = nil
end
table.insert (params.items, {
- show = function () return name end,
+ show = name .. (initrd and " +initrd" or ""),
version = version,
- execute = function () sl.boot_linux (path, initrd_param .. params.append .. modifiers ()) end
+ execute = function ()
+ boot (path, initrd,
+ params.append .. modifiers ())
+ end
})
end
end
@@ -81,21 +94,18 @@ local function kernel_gt (k1, k2)
return version_gt (k1.version, k2.version)
end
-local function print_or_call (x, def)
- local t = type (x)
- if t == "nil" then
- if def then print (def) end
- elseif t == "function" then
- x ()
+local function get (x)
+ if type (x) == "function" then
+ return x ()
else
- print (x)
+ return x
end
end
local function draw (params)
- print_or_call (params.title, "\n=== Boot menu ===")
+ print (get (params.title) or "\n=== Boot menu ===")
for i, item in ipairs (params.items) do
- print ((i == params.default and " > " or " ") .. i .. " " .. item.show ())
+ print ((i == params.default and " > " or " ") .. i .. " " .. get (item.show))
end
print ("\nKernel arguments:\n " .. params.append .. modifiers ())
print ("\nHit a number to select from the menu,\n ENTER to accept default,\n ESC to exit\n or any other key to print menu again")