xref: /freebsd/stand/lua/loader.lua (revision 5f8cfbe1348dac0abce73c344af2eab0ccaae732)
1088b4f5fSWarner Losh--
272e39d71SKyle Evans-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
372e39d71SKyle Evans--
4088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5afad05b2SKyle Evans-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6088b4f5fSWarner Losh-- All rights reserved.
7088b4f5fSWarner Losh--
8088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without
9088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions
10088b4f5fSWarner Losh-- are met:
11088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright
12088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer.
13088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright
14088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer in the
15088b4f5fSWarner Losh--    documentation and/or other materials provided with the distribution.
16088b4f5fSWarner Losh--
17088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20088b4f5fSWarner Losh-- ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27088b4f5fSWarner Losh-- SUCH DAMAGE.
28088b4f5fSWarner Losh--
29088b4f5fSWarner Losh-- $FreeBSD$
30088b4f5fSWarner Losh--
31088b4f5fSWarner Losh
32ee15e552SKyle Evans-- The cli module should be included first here. Some of the functions that it
33ee15e552SKyle Evans-- defines are necessary for the Lua-based loader to operate in general.
34ee15e552SKyle Evans-- Other modules will also need some of the functions it defines to safely
35ee15e552SKyle Evans-- execute loader commands.
36e2df27e3SKyle Evansrequire("cli")
3785efc91aSKyle Evanslocal color = require("color")
389937e979SKyle Evanslocal core = require("core")
39aedd6be5SKyle Evanslocal config = require("config")
409937e979SKyle Evanslocal menu
419937e979SKyle Evansif not core.isMenuSkipped() then
429937e979SKyle Evans	menu = require("menu")
439937e979SKyle Evansend
44aedd6be5SKyle Evanslocal password = require("password")
4548230b85SKyle Evans
465144243aSKyle Evanslocal result = lfs.attributes("/boot/lua/local.lua")
4748230b85SKyle Evans-- Effectively discard any errors; we'll just act if it succeeds.
4848230b85SKyle Evansif result ~= nil then
49e2df27e3SKyle Evans	require("local")
5048230b85SKyle Evansend
51088b4f5fSWarner Losh
52aedd6be5SKyle Evansconfig.load()
53*5f8cfbe1SKyle Evansif core.isUEFIBoot() then
54*5f8cfbe1SKyle Evans	loader.perform("efi-autoresizecons")
55*5f8cfbe1SKyle Evansend
5685efc91aSKyle Evans-- Our console may have been setup for a different color scheme before we get
5785efc91aSKyle Evans-- here, so make sure we set the default.
5885efc91aSKyle Evansif color.isEnabled() then
5985efc91aSKyle Evans	printc(color.default())
6085efc91aSKyle Evansend
61aedd6be5SKyle Evanspassword.check()
629937e979SKyle Evans-- menu might be disabled
639937e979SKyle Evansif menu ~= nil then
64aedd6be5SKyle Evans	menu.run()
659937e979SKyle Evanselse
669937e979SKyle Evans	-- Load kernel/modules before we go
679937e979SKyle Evans	config.loadelf()
689937e979SKyle Evansend
69