pelican 0.1.0
This commit is contained in:
parent
109e0d1cf3
commit
bdbb400807
1 changed files with 106 additions and 0 deletions
106
boot.lua
Normal file
106
boot.lua
Normal file
|
@ -0,0 +1,106 @@
|
|||
-- Initialise global variables related to booting.
|
||||
_G._KERNEL_ROOT = "/"
|
||||
_G._KERNEL_LOCS = {}
|
||||
_G._BOOT_DEFAULT = nil
|
||||
_G._PELICAN_DEBUG = false
|
||||
_G._PELICAN_VERSION = "0.1.0"
|
||||
_G._PELICAN_CONFIG_LOCATION = ""
|
||||
|
||||
print("Pelican " .. _G._PELICAN_VERSION)
|
||||
print("Searching for Pelican configuration.")
|
||||
local directories = {}
|
||||
directories[1] = "/"
|
||||
local x = 2
|
||||
local s = 1
|
||||
local v = true
|
||||
while v and _G._PELICAN_CONFIG_LOCATION == "" do
|
||||
local files = fs.list(directories[s])
|
||||
for i = 1, #files do
|
||||
if fs.isDir(fs.combine(directories[s], files[i])) then
|
||||
table.insert(directories, x, directories[s] .. files[i])
|
||||
x = x + 1
|
||||
elseif fs.getName(fs.combine(directories[s], files[i])) == "pelican.conf.lua" then
|
||||
_G._PELICAN_CONFIG_LOCATION = fs.combine(directories[s], files[i])
|
||||
end
|
||||
end
|
||||
table.remove(directories, s)
|
||||
s = s + 1
|
||||
if directories[s] == nil then
|
||||
v = false
|
||||
end
|
||||
end
|
||||
|
||||
if _G._PELICAN_CONFIG_LOCATION ~= "" then
|
||||
print("Found config at " .. _G._PELICAN_CONFIG_LOCATION .. ".")
|
||||
dofile(_G._PELICAN_CONFIG_LOCATION)
|
||||
print("Config applied!")
|
||||
else
|
||||
print("No config found.")
|
||||
if not _G._PELICAN_DEBUG then
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
end
|
||||
end
|
||||
|
||||
if #_G._KERNEL_LOCS ~= 0 and _G._BOOT_DEFAULT == nil then
|
||||
print("")
|
||||
if not _G._PELICAN_DEBUG then
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
end
|
||||
print("These kernels are available to boot to: ")
|
||||
for i = 1, #_G._KERNEL_LOCS do
|
||||
print(i.. ". " .. _G._KERNEL_LOCS[i])
|
||||
end
|
||||
print("To boot one of these kernels, type boot followed by the index number.")
|
||||
print("Just type boot to boot kernel #1.")
|
||||
print("")
|
||||
end
|
||||
|
||||
local boot = false
|
||||
|
||||
if _G._BOOT_DEFAULT ~= nil and _G._KERNEL_LOCS[_G._BOOT_DEFAULT] ~= nil then
|
||||
boot = _G._KERNEL_LOCS[_G._BOOT_DEFAULT]
|
||||
end
|
||||
|
||||
if not boot then
|
||||
print("No default kernel set. Dropping to shell.")
|
||||
|
||||
while not boot do
|
||||
write("> ")
|
||||
local cmd = read()
|
||||
if cmd == "restart" or cmd == "reboot" then
|
||||
os.reboot()
|
||||
elseif cmd:find("^boot") and cmd ~= "boot" then
|
||||
cmd = cmd:gsub("boot ", "")
|
||||
if _G._KERNEL_LOCS[tonumber(cmd)] then
|
||||
boot = _G._KERNEL_LOCS[tonumber(cmd)]
|
||||
elseif fs.exists(cmd) then
|
||||
boot = cmd
|
||||
else
|
||||
print("Please enter a valid kernel index number or kernel path.")
|
||||
end
|
||||
elseif cmd == "boot" then
|
||||
if _G._KERNEL_LOCS[1] then
|
||||
boot = _G._KERNEL_LOCS[1]
|
||||
else
|
||||
print("Please enter a kernel path.")
|
||||
end
|
||||
elseif cmd == "shutdown" or cmd == "poweroff" or cmd == "halt" then
|
||||
os.shutdown()
|
||||
elseif cmd == "help" then
|
||||
print("shutdown - halts execution")
|
||||
print("boot - executes a kernel")
|
||||
print("restart - restarts computer")
|
||||
print("help - prints help information")
|
||||
print("version - prints version information")
|
||||
elseif cmd == "version" then
|
||||
print("Pelican boot loader version " .. _G._PELICAN_VERSION)
|
||||
print("This software is licensed under the GNU General Public License.")
|
||||
print("More information about this software can be found online at:")
|
||||
print("https://git.colean.cc/canaryos/pelican")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
dofile(boot)
|
Loading…
Reference in a new issue