2018-02-12 15:32:00 +00:00
|
|
|
--
|
2018-02-23 02:51:35 +00:00
|
|
|
-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
--
|
2018-02-12 15:32:00 +00:00
|
|
|
-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
|
2019-09-26 16:19:22 +00:00
|
|
|
-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
|
2018-02-12 15:32:00 +00:00
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- Redistribution and use in source and binary forms, with or without
|
|
|
|
-- modification, are permitted provided that the following conditions
|
|
|
|
-- are met:
|
|
|
|
-- 1. Redistributions of source code must retain the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer.
|
|
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer in the
|
|
|
|
-- documentation and/or other materials provided with the distribution.
|
|
|
|
--
|
|
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
-- SUCH DAMAGE.
|
|
|
|
--
|
|
|
|
-- $FreeBSD$
|
|
|
|
--
|
|
|
|
|
2018-10-11 17:16:39 +00:00
|
|
|
local cli = require("cli")
|
2018-02-21 01:10:03 +00:00
|
|
|
local core = require("core")
|
|
|
|
local color = require("color")
|
|
|
|
local config = require("config")
|
|
|
|
local screen = require("screen")
|
|
|
|
local drawer = require("drawer")
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local menu = {}
|
2018-02-19 17:54:22 +00:00
|
|
|
|
2018-02-25 17:02:50 +00:00
|
|
|
local drawn_menu
|
2018-03-01 02:04:26 +00:00
|
|
|
local return_menu_entry = {
|
|
|
|
entry_type = core.MENU_RETURN,
|
|
|
|
name = "Back to main menu" .. color.highlight(" [Backspace]"),
|
|
|
|
}
|
2018-02-25 05:00:54 +00:00
|
|
|
|
2018-02-26 04:08:54 +00:00
|
|
|
local function OnOff(str, value)
|
|
|
|
if value then
|
2018-03-21 15:09:47 +00:00
|
|
|
return str .. color.escapefg(color.GREEN) .. "On" ..
|
2019-09-22 17:39:20 +00:00
|
|
|
color.resetfg()
|
2018-02-20 14:36:28 +00:00
|
|
|
else
|
2018-03-21 15:09:47 +00:00
|
|
|
return str .. color.escapefg(color.RED) .. "off" ..
|
2019-09-22 17:39:20 +00:00
|
|
|
color.resetfg()
|
2018-02-20 14:36:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-23 04:03:07 +00:00
|
|
|
local function bootenvSet(env)
|
2018-02-21 16:50:41 +00:00
|
|
|
loader.setenv("vfs.root.mountfrom", env)
|
|
|
|
loader.setenv("currdev", env .. ":")
|
|
|
|
config.reload()
|
|
|
|
end
|
|
|
|
|
2018-02-20 14:45:58 +00:00
|
|
|
-- Module exports
|
2018-02-20 03:40:16 +00:00
|
|
|
menu.handlers = {
|
|
|
|
-- Menu handlers take the current menu and selected entry as parameters,
|
|
|
|
-- and should return a boolean indicating whether execution should
|
|
|
|
-- continue or not. The return value may be omitted if this entry should
|
|
|
|
-- have no bearing on whether we continue or not, indicating that we
|
|
|
|
-- should just continue after execution.
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_ENTRY] = function(_, entry)
|
2018-02-20 03:40:16 +00:00
|
|
|
-- run function
|
2018-02-21 01:10:03 +00:00
|
|
|
entry.func()
|
2018-02-20 03:40:16 +00:00
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
|
2018-02-20 03:40:16 +00:00
|
|
|
-- carousel (rotating) functionality
|
2018-02-21 01:10:03 +00:00
|
|
|
local carid = entry.carousel_id
|
|
|
|
local caridx = config.getCarouselIndex(carid)
|
2018-02-21 05:04:58 +00:00
|
|
|
local choices = entry.items
|
|
|
|
if type(choices) == "function" then
|
|
|
|
choices = choices()
|
|
|
|
end
|
2018-02-21 01:35:19 +00:00
|
|
|
if #choices > 0 then
|
2018-02-21 01:10:03 +00:00
|
|
|
caridx = (caridx % #choices) + 1
|
|
|
|
config.setCarouselIndex(carid, caridx)
|
|
|
|
entry.func(caridx, choices[caridx], choices)
|
2018-02-20 03:40:16 +00:00
|
|
|
end
|
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_SUBMENU] = function(_, entry)
|
2018-02-25 04:11:08 +00:00
|
|
|
menu.process(entry.submenu)
|
2018-02-20 03:40:16 +00:00
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_RETURN] = function(_, entry)
|
2018-02-20 03:40:16 +00:00
|
|
|
-- allow entry to have a function/side effect
|
2018-02-21 01:35:19 +00:00
|
|
|
if entry.func ~= nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
entry.func()
|
2018-02-20 03:40:16 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
return false
|
2018-02-20 03:40:16 +00:00
|
|
|
end,
|
2018-02-21 01:10:03 +00:00
|
|
|
}
|
2018-02-19 15:49:27 +00:00
|
|
|
-- loader menu tree is rooted at menu.welcome
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 16:50:41 +00:00
|
|
|
menu.boot_environments = {
|
|
|
|
entries = {
|
|
|
|
-- return to welcome menu
|
2018-03-01 02:04:26 +00:00
|
|
|
return_menu_entry,
|
2018-02-21 16:50:41 +00:00
|
|
|
{
|
|
|
|
entry_type = core.MENU_CAROUSEL_ENTRY,
|
|
|
|
carousel_id = "be_active",
|
|
|
|
items = core.bootenvList,
|
|
|
|
name = function(idx, choice, all_choices)
|
|
|
|
if #all_choices == 0 then
|
|
|
|
return "Active: "
|
|
|
|
end
|
|
|
|
|
|
|
|
local is_default = (idx == 1)
|
|
|
|
local bootenv_name = ""
|
|
|
|
local name_color
|
|
|
|
if is_default then
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.GREEN)
|
2018-02-21 16:50:41 +00:00
|
|
|
else
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.BLUE)
|
2018-02-21 16:50:41 +00:00
|
|
|
end
|
|
|
|
bootenv_name = bootenv_name .. name_color ..
|
2018-03-21 15:09:47 +00:00
|
|
|
choice .. color.resetfg()
|
2018-02-21 16:50:41 +00:00
|
|
|
return color.highlight("A").."ctive: " ..
|
|
|
|
bootenv_name .. " (" .. idx .. " of " ..
|
|
|
|
#all_choices .. ")"
|
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
func = function(_, choice, _)
|
2018-02-21 16:50:41 +00:00
|
|
|
bootenvSet(choice)
|
|
|
|
end,
|
|
|
|
alias = {"a", "A"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2020-08-18 19:48:04 +00:00
|
|
|
visible = function()
|
|
|
|
return core.isRewinded() == false
|
|
|
|
end,
|
2018-02-21 16:50:41 +00:00
|
|
|
name = function()
|
|
|
|
return color.highlight("b") .. "ootfs: " ..
|
|
|
|
core.bootenvDefault()
|
|
|
|
end,
|
|
|
|
func = function()
|
|
|
|
-- Reset active boot environment to the default
|
|
|
|
config.setCarouselIndex("be_active", 1)
|
|
|
|
bootenvSet(core.bootenvDefault())
|
|
|
|
end,
|
|
|
|
alias = {"b", "B"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-12 15:32:00 +00:00
|
|
|
menu.boot_options = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entries = {
|
|
|
|
-- return to welcome menu
|
2018-03-01 02:04:26 +00:00
|
|
|
return_menu_entry,
|
2018-02-19 16:25:43 +00:00
|
|
|
-- load defaults
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Load System " .. color.highlight("D") ..
|
|
|
|
"efaults",
|
|
|
|
func = core.setDefaults,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"d", "D"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Boot Options:",
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- acpi
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-20 19:21:34 +00:00
|
|
|
visible = core.isSystem386,
|
2018-02-19 16:25:43 +00:00
|
|
|
name = function()
|
2018-02-19 16:42:06 +00:00
|
|
|
return OnOff(color.highlight("A") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"CPI :", core.acpi)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setACPI,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"a", "A"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- safe mode
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
|
|
|
return OnOff("Safe " .. color.highlight("M") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"ode :", core.sm)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setSafeMode,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"m", "M"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- single user
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
2018-02-19 16:42:06 +00:00
|
|
|
return OnOff(color.highlight("S") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"ingle user:", core.su)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setSingleUser,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"s", "S"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- verbose boot
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
2018-02-19 16:42:06 +00:00
|
|
|
return OnOff(color.highlight("V") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"erbose :", core.verbose)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setVerbose,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"v", "V"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2018-02-12 15:32:00 +00:00
|
|
|
},
|
2018-02-21 01:10:03 +00:00
|
|
|
}
|
2018-02-12 15:32:00 +00:00
|
|
|
|
|
|
|
menu.welcome = {
|
2018-02-19 16:36:29 +00:00
|
|
|
entries = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
local menu_entries = menu.welcome.all_entries
|
2020-04-22 17:04:31 +00:00
|
|
|
local multi_user = menu_entries.multi_user
|
|
|
|
local single_user = menu_entries.single_user
|
|
|
|
local boot_entry_1, boot_entry_2
|
2018-02-21 01:35:19 +00:00
|
|
|
if core.isSingleUserBoot() then
|
2020-04-22 17:04:31 +00:00
|
|
|
-- Swap the first two menu items on single user boot.
|
|
|
|
-- We'll cache the alternate entries for performance.
|
|
|
|
local alts = menu_entries.alts
|
|
|
|
if alts == nil then
|
|
|
|
single_user = core.deepCopyTable(single_user)
|
|
|
|
multi_user = core.deepCopyTable(multi_user)
|
|
|
|
single_user.name = single_user.alternate_name
|
|
|
|
multi_user.name = multi_user.alternate_name
|
|
|
|
menu_entries.alts = {
|
|
|
|
single_user = single_user,
|
|
|
|
multi_user = multi_user,
|
|
|
|
}
|
|
|
|
else
|
2020-10-01 14:20:36 +00:00
|
|
|
single_user = alts.single_user
|
2020-04-22 17:04:31 +00:00
|
|
|
multi_user = alts.multi_user
|
2018-02-19 22:29:16 +00:00
|
|
|
end
|
2020-04-22 17:04:31 +00:00
|
|
|
boot_entry_1, boot_entry_2 = single_user, multi_user
|
|
|
|
else
|
|
|
|
boot_entry_1, boot_entry_2 = multi_user, single_user
|
2018-02-19 16:36:29 +00:00
|
|
|
end
|
2020-04-22 17:04:31 +00:00
|
|
|
return {
|
|
|
|
boot_entry_1,
|
|
|
|
boot_entry_2,
|
|
|
|
menu_entries.prompt,
|
|
|
|
menu_entries.reboot,
|
2020-09-28 16:19:21 +00:00
|
|
|
menu_entries.console,
|
2020-04-22 17:04:31 +00:00
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
|
|
|
name = "Options:",
|
|
|
|
},
|
|
|
|
menu_entries.kernel_options,
|
|
|
|
menu_entries.boot_options,
|
2020-08-18 19:48:04 +00:00
|
|
|
menu_entries.zpool_checkpoints,
|
2020-04-22 17:04:31 +00:00
|
|
|
menu_entries.boot_envs,
|
|
|
|
menu_entries.chainload,
|
2021-03-31 00:35:29 +00:00
|
|
|
menu_entries.vendor,
|
2020-04-22 17:04:31 +00:00
|
|
|
}
|
2018-02-19 16:36:29 +00:00
|
|
|
end,
|
|
|
|
all_entries = {
|
2020-04-22 17:04:31 +00:00
|
|
|
multi_user = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = color.highlight("B") .. "oot Multi user " ..
|
|
|
|
color.highlight("[Enter]"),
|
2018-02-19 17:40:19 +00:00
|
|
|
-- Not a standard menu entry function!
|
2018-02-21 04:48:37 +00:00
|
|
|
alternate_name = color.highlight("B") ..
|
|
|
|
"oot Multi user",
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
core.setSingleUser(false)
|
|
|
|
core.boot()
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"b", "B"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
single_user = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Boot " .. color.highlight("S") .. "ingle user",
|
2018-02-19 17:40:19 +00:00
|
|
|
-- Not a standard menu entry function!
|
2018-02-21 04:48:37 +00:00
|
|
|
alternate_name = "Boot " .. color.highlight("S") ..
|
|
|
|
"ingle user " .. color.highlight("[Enter]"),
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
core.setSingleUser(true)
|
|
|
|
core.boot()
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"s", "S"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2020-09-28 16:19:21 +00:00
|
|
|
console = {
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
|
|
|
return color.highlight("C") .. "ons: " .. core.getConsoleName()
|
|
|
|
end,
|
|
|
|
func = function()
|
|
|
|
core.nextConsoleChoice()
|
|
|
|
end,
|
|
|
|
alias = {"c", "C"},
|
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
prompt = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entry_type = core.MENU_RETURN,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = color.highlight("Esc") .. "ape to loader prompt",
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.setenv("autoboot_delay", "NO")
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {core.KEYSTR_ESCAPE},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
reboot = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = color.highlight("R") .. "eboot",
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.perform("reboot")
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"r", "R"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
kernel_options = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entry_type = core.MENU_CAROUSEL_ENTRY,
|
|
|
|
carousel_id = "kernel",
|
|
|
|
items = core.kernelList,
|
|
|
|
name = function(idx, choice, all_choices)
|
2018-02-21 01:35:19 +00:00
|
|
|
if #all_choices == 0 then
|
2018-02-21 01:10:03 +00:00
|
|
|
return "Kernel: "
|
2018-02-19 16:25:43 +00:00
|
|
|
end
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local is_default = (idx == 1)
|
|
|
|
local kernel_name = ""
|
|
|
|
local name_color
|
2018-02-21 01:35:19 +00:00
|
|
|
if is_default then
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.GREEN)
|
2018-02-21 01:10:03 +00:00
|
|
|
kernel_name = "default/"
|
2018-02-19 16:25:43 +00:00
|
|
|
else
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.BLUE)
|
2018-02-19 16:25:43 +00:00
|
|
|
end
|
2018-02-19 16:42:06 +00:00
|
|
|
kernel_name = kernel_name .. name_color ..
|
2018-03-21 15:09:47 +00:00
|
|
|
choice .. color.resetfg()
|
2018-02-19 17:51:33 +00:00
|
|
|
return color.highlight("K") .. "ernel: " ..
|
2018-02-19 16:42:06 +00:00
|
|
|
kernel_name .. " (" .. idx .. " of " ..
|
2018-02-21 01:10:03 +00:00
|
|
|
#all_choices .. ")"
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
func = function(_, choice, _)
|
2018-10-24 02:02:37 +00:00
|
|
|
if loader.getenv("kernelname") ~= nil then
|
|
|
|
loader.perform("unload")
|
|
|
|
end
|
2018-02-24 20:21:21 +00:00
|
|
|
config.selectKernel(choice)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"k", "K"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
boot_options = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entry_type = core.MENU_SUBMENU,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Boot " .. color.highlight("O") .. "ptions",
|
2018-02-21 04:23:13 +00:00
|
|
|
submenu = menu.boot_options,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"o", "O"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2020-08-18 19:48:04 +00:00
|
|
|
zpool_checkpoints = {
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
2020-10-01 14:20:36 +00:00
|
|
|
local rewind = "No"
|
2020-08-18 19:48:04 +00:00
|
|
|
if core.isRewinded() then
|
|
|
|
rewind = "Yes"
|
|
|
|
end
|
|
|
|
return "Rewind ZFS " .. color.highlight("C") ..
|
|
|
|
"heckpoint: " .. rewind
|
|
|
|
end,
|
|
|
|
func = function()
|
|
|
|
core.changeRewindCheckpoint()
|
|
|
|
if core.isRewinded() then
|
|
|
|
bootenvSet(
|
|
|
|
core.bootenvDefaultRewinded())
|
|
|
|
else
|
|
|
|
bootenvSet(core.bootenvDefault())
|
|
|
|
end
|
|
|
|
config.setCarouselIndex("be_active", 1)
|
|
|
|
end,
|
|
|
|
visible = function()
|
|
|
|
return core.isZFSBoot() and
|
|
|
|
core.isCheckpointed()
|
|
|
|
end,
|
|
|
|
alias = {"c", "C"},
|
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
boot_envs = {
|
2018-02-21 16:50:41 +00:00
|
|
|
entry_type = core.MENU_SUBMENU,
|
|
|
|
visible = function()
|
|
|
|
return core.isZFSBoot() and
|
|
|
|
#core.bootenvList() > 1
|
|
|
|
end,
|
|
|
|
name = "Boot " .. color.highlight("E") .. "nvironments",
|
|
|
|
submenu = menu.boot_environments,
|
|
|
|
alias = {"e", "E"},
|
|
|
|
},
|
2020-04-22 17:04:31 +00:00
|
|
|
chainload = {
|
2018-11-05 16:20:07 +00:00
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
|
|
|
return 'Chain' .. color.highlight("L") ..
|
|
|
|
"oad " .. loader.getenv('chain_disk')
|
|
|
|
end,
|
|
|
|
func = function()
|
|
|
|
loader.perform("chain " ..
|
|
|
|
loader.getenv('chain_disk'))
|
|
|
|
end,
|
|
|
|
visible = function()
|
|
|
|
return loader.getenv('chain_disk') ~= nil
|
|
|
|
end,
|
|
|
|
alias = {"l", "L"},
|
|
|
|
},
|
2021-03-31 00:35:29 +00:00
|
|
|
vendor = {
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2021-04-01 04:34:50 +00:00
|
|
|
visible = function()
|
|
|
|
return false
|
|
|
|
end
|
2021-03-31 00:35:29 +00:00
|
|
|
},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2018-02-21 01:10:03 +00:00
|
|
|
}
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 03:37:46 +00:00
|
|
|
menu.default = menu.welcome
|
2018-02-25 04:44:45 +00:00
|
|
|
-- current_alias_table will be used to keep our alias table consistent across
|
|
|
|
-- screen redraws, instead of relying on whatever triggered the redraw to update
|
|
|
|
-- the local alias_table in menu.process.
|
|
|
|
menu.current_alias_table = {}
|
2018-02-21 03:37:46 +00:00
|
|
|
|
2018-02-26 03:46:17 +00:00
|
|
|
function menu.draw(menudef)
|
2018-02-25 17:02:50 +00:00
|
|
|
-- Clear the screen, reset the cursor, then draw
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.clear()
|
2018-02-26 03:46:17 +00:00
|
|
|
menu.current_alias_table = drawer.drawscreen(menudef)
|
|
|
|
drawn_menu = menudef
|
2018-03-02 17:07:08 +00:00
|
|
|
screen.defcursor()
|
2018-02-25 04:44:45 +00:00
|
|
|
end
|
|
|
|
|
2018-02-25 05:00:54 +00:00
|
|
|
-- 'keypress' allows the caller to indicate that a key has been pressed that we
|
|
|
|
-- should process as our initial input.
|
2018-02-26 03:46:17 +00:00
|
|
|
function menu.process(menudef, keypress)
|
|
|
|
assert(menudef ~= nil)
|
2018-02-25 04:44:45 +00:00
|
|
|
|
2018-02-26 03:46:17 +00:00
|
|
|
if drawn_menu ~= menudef then
|
|
|
|
menu.draw(menudef)
|
2018-02-21 17:33:01 +00:00
|
|
|
end
|
2018-02-25 05:00:54 +00:00
|
|
|
|
2018-02-25 04:11:08 +00:00
|
|
|
while true do
|
2018-02-25 05:00:54 +00:00
|
|
|
local key = keypress or io.getchar()
|
|
|
|
keypress = nil
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-15 18:16:16 +00:00
|
|
|
-- Special key behaviors
|
2018-02-21 01:35:19 +00:00
|
|
|
if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and
|
2018-02-26 03:46:17 +00:00
|
|
|
menudef ~= menu.default then
|
2018-02-21 01:10:03 +00:00
|
|
|
break
|
2018-02-21 01:35:19 +00:00
|
|
|
elseif key == core.KEY_ENTER then
|
2018-02-21 01:10:03 +00:00
|
|
|
core.boot()
|
2018-10-24 03:14:10 +00:00
|
|
|
-- Should not return. If it does, escape menu handling
|
|
|
|
-- and drop to loader prompt.
|
|
|
|
return false
|
2018-02-14 20:18:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
key = string.char(key)
|
2018-02-12 15:32:00 +00:00
|
|
|
-- check to see if key is an alias
|
2018-02-21 01:10:03 +00:00
|
|
|
local sel_entry = nil
|
2018-02-25 04:44:45 +00:00
|
|
|
for k, v in pairs(menu.current_alias_table) do
|
2018-02-21 01:35:19 +00:00
|
|
|
if key == k then
|
2018-02-21 01:10:03 +00:00
|
|
|
sel_entry = v
|
2018-02-25 04:44:45 +00:00
|
|
|
break
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if we have an alias do the assigned action:
|
2018-02-21 01:35:19 +00:00
|
|
|
if sel_entry ~= nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
local handler = menu.handlers[sel_entry.entry_type]
|
2018-02-26 03:46:17 +00:00
|
|
|
assert(handler ~= nil)
|
|
|
|
-- The handler's return value indicates if we
|
|
|
|
-- need to exit this menu. An omitted or true
|
|
|
|
-- return value means to continue.
|
|
|
|
if handler(menudef, sel_entry) == false then
|
|
|
|
return
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-25 04:44:45 +00:00
|
|
|
-- If we got an alias key the screen is out of date...
|
|
|
|
-- redraw it.
|
2018-02-26 03:46:17 +00:00
|
|
|
menu.draw(menudef)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
end
|
2018-02-25 04:11:08 +00:00
|
|
|
end
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-25 04:11:08 +00:00
|
|
|
function menu.run()
|
2018-10-24 03:14:10 +00:00
|
|
|
local autoboot_key
|
2018-10-05 17:07:10 +00:00
|
|
|
local delay = loader.getenv("autoboot_delay")
|
|
|
|
|
|
|
|
if delay ~= nil and delay:lower() == "no" then
|
|
|
|
delay = nil
|
|
|
|
else
|
|
|
|
delay = tonumber(delay) or 10
|
|
|
|
end
|
|
|
|
|
|
|
|
if delay == -1 then
|
|
|
|
core.boot()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-02-25 17:02:50 +00:00
|
|
|
menu.draw(menu.default)
|
2018-10-05 17:07:10 +00:00
|
|
|
|
2018-10-24 03:14:10 +00:00
|
|
|
if delay ~= nil then
|
|
|
|
autoboot_key = menu.autoboot(delay)
|
|
|
|
|
|
|
|
-- autoboot_key should return the key pressed. It will only
|
|
|
|
-- return nil if we hit the timeout and executed the timeout
|
|
|
|
-- command. Bail out.
|
|
|
|
if autoboot_key == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2018-02-25 05:00:54 +00:00
|
|
|
|
|
|
|
menu.process(menu.default, autoboot_key)
|
2018-02-25 17:02:50 +00:00
|
|
|
drawn_menu = nil
|
2018-02-25 04:11:08 +00:00
|
|
|
|
|
|
|
screen.defcursor()
|
|
|
|
print("Exiting menu!")
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
2018-10-05 17:07:10 +00:00
|
|
|
function menu.autoboot(delay)
|
2018-03-03 18:13:14 +00:00
|
|
|
local x = loader.getenv("loader_menu_timeout_x") or 4
|
|
|
|
local y = loader.getenv("loader_menu_timeout_y") or 23
|
2018-10-05 17:07:10 +00:00
|
|
|
local endtime = loader.time() + delay
|
2018-02-21 01:10:03 +00:00
|
|
|
local time
|
2018-03-09 18:45:13 +00:00
|
|
|
local last
|
2018-02-12 15:32:00 +00:00
|
|
|
repeat
|
2018-02-21 01:10:03 +00:00
|
|
|
time = endtime - loader.time()
|
2018-03-09 18:45:13 +00:00
|
|
|
if last == nil or last ~= time then
|
|
|
|
last = time
|
|
|
|
screen.setcursor(x, y)
|
|
|
|
print("Autoboot in " .. time ..
|
|
|
|
" seconds, hit [Enter] to boot" ..
|
|
|
|
" or any other key to stop ")
|
|
|
|
screen.defcursor()
|
|
|
|
end
|
2018-02-21 01:35:19 +00:00
|
|
|
if io.ischar() then
|
2018-02-21 01:10:03 +00:00
|
|
|
local ch = io.getchar()
|
2018-02-21 01:35:19 +00:00
|
|
|
if ch == core.KEY_ENTER then
|
2018-02-21 01:10:03 +00:00
|
|
|
break
|
2018-02-12 15:32:00 +00:00
|
|
|
else
|
|
|
|
-- erase autoboot msg
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.setcursor(0, y)
|
2018-02-22 20:10:23 +00:00
|
|
|
print(string.rep(" ", 80))
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.defcursor()
|
2018-02-21 14:37:49 +00:00
|
|
|
return ch
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.delay(50000)
|
|
|
|
until time <= 0
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-03-03 17:18:40 +00:00
|
|
|
local cmd = loader.getenv("menu_timeout_command") or "boot"
|
2018-03-07 18:31:01 +00:00
|
|
|
cli_execute_unparsed(cmd)
|
2018-10-24 03:14:10 +00:00
|
|
|
return nil
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
2018-10-11 17:16:39 +00:00
|
|
|
-- CLI commands
|
2019-03-26 02:35:58 +00:00
|
|
|
function cli.menu()
|
2018-10-11 17:16:39 +00:00
|
|
|
menu.run()
|
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
return menu
|