mirror of
https://github.com/Alee14/bits-UI.git
synced 2025-01-22 10:41:58 -05:00
New bootloader
This commit is contained in:
parent
fc49ea175a
commit
1fd3cd3305
7 changed files with 229 additions and 114 deletions
|
@ -5,6 +5,7 @@ Feel free to contribute to this project!
|
|||
# Credits
|
||||
The programs/apis I used for bits-UI.
|
||||
|
||||
- CCBoot by AdrUlb
|
||||
- NPaintPro by NitrogenFingers
|
||||
- Ink by oeed
|
||||
- Krist Wallet by 3d6
|
||||
|
|
177
boot/ccboot/boot.lua
Normal file
177
boot/ccboot/boot.lua
Normal file
|
@ -0,0 +1,177 @@
|
|||
if os.ccboot then
|
||||
term.setTextColor(colors.red);
|
||||
print("Insufficient memory.");
|
||||
error();
|
||||
end;
|
||||
|
||||
-- Add ccboot identifier to OS variable
|
||||
os.ccboot = true;
|
||||
os.ccboot_version = "1.0";
|
||||
|
||||
-- Define constants
|
||||
local VERSION = "1.0";
|
||||
local AUTHOR_INFO = "Written by Adrian Ulbrich"
|
||||
local INFO_TEXT = { "Use the up and down arrow keys to select", "which entry is highlighted.", "Press enter to boot the selected OS." };
|
||||
local TIMEOUT_TEXT = { "The highlighted entry will be executed", "automatically in {TIMEOUT} seconds." };
|
||||
local CONFIG_PATH = "boot/ccboot/ccboot.cfg";
|
||||
local DEFAULT_SELECTED = 1;
|
||||
local DEFAULT_TIMEOUT = -1;
|
||||
|
||||
-- Define local variables
|
||||
local selected = nil;
|
||||
local timeout = nil;
|
||||
local entryNames = {};
|
||||
local entryPaths = {};
|
||||
local configFile;
|
||||
local timeoutTimer = nil;
|
||||
|
||||
-- Always pull raw events
|
||||
local pullEvent = os.pullEvent;
|
||||
os.pullEvent = os.pullEventRaw;
|
||||
|
||||
-- Get terminal dimensions
|
||||
local w, h = term.getSize();
|
||||
|
||||
-- Define functions
|
||||
function string.startsWith(str, text)
|
||||
return string.sub(str, 1, string.len(text)) == text;
|
||||
end;
|
||||
|
||||
function fatalError(text)
|
||||
term.setTextColor(colors.red);
|
||||
print(text);
|
||||
term.setTextColor(colors.white);
|
||||
print("press any key to reboot.");
|
||||
os.pullEvent("key");
|
||||
os.reboot();
|
||||
end;
|
||||
|
||||
function printTimeoutText()
|
||||
for i, v in pairs(TIMEOUT_TEXT) do
|
||||
term.setCursorPos(6, h - 3 + i);
|
||||
write(string.gsub(v, "{TIMEOUT}", timeout));
|
||||
end;
|
||||
end;
|
||||
|
||||
function removeTimeoutText()
|
||||
term.setTextColor(colors.black);
|
||||
printTimeoutText();
|
||||
term.setTextColor(colors.white);
|
||||
end
|
||||
|
||||
function bootOS(index)
|
||||
local n = 1;
|
||||
for i, v in pairs(entryPaths) do
|
||||
if n == index then
|
||||
term.clear();
|
||||
term.setCursorPos(1, 1);
|
||||
os.pullEvent = pullEvent;
|
||||
shell.run(v);
|
||||
os.shutdown();
|
||||
end
|
||||
n = n + 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
-- Clear the screen
|
||||
term.clear();
|
||||
term.setCursorPos(1, 1);
|
||||
|
||||
-- Check if the config file exists
|
||||
if not fs.exists(CONFIG_PATH) then
|
||||
fatalError("fatal error: ccboot config file could not be found (\"" .. CONFIG_PATH .. "\").");
|
||||
end;
|
||||
|
||||
-- Read the config file
|
||||
configFile = io.open(CONFIG_PATH, "r");
|
||||
if configFile == nil then
|
||||
fatalError("fatal error: ccboot config file could not be opened for reading (\"" .. CONFIG_PATH .. "\").");
|
||||
end;
|
||||
|
||||
for line in configFile:lines() do
|
||||
if string.startsWith(line, "selected ") then
|
||||
selected = tonumber(string.sub(line, #"selected " + 1));
|
||||
elseif string.startsWith(line, "timeout ") then
|
||||
timeout = tonumber(string.sub(line, #"timeout " + 1));
|
||||
elseif string.startsWith(line, "entry ") then
|
||||
local entry = string.sub(line, #"entry " + 1);
|
||||
local splitPos = string.find(entry, ";");
|
||||
local name = string.sub(entry, 1, splitPos - 1);
|
||||
local path = string.sub(entry, splitPos + 1);
|
||||
table.insert(entryNames, name);
|
||||
table.insert(entryPaths, path);
|
||||
end;
|
||||
end;
|
||||
|
||||
if selected == nil then selected = DEFAULT_SELECTED end;
|
||||
if timeout == nil then timeout = DEFAULT_TIMEOUT end;
|
||||
|
||||
io.close(configFile);
|
||||
|
||||
local nameString = "CCboot version " .. VERSION;
|
||||
|
||||
-- Print the name at the top
|
||||
term.setCursorPos((w - #nameString) / 2, 2);
|
||||
write(nameString);
|
||||
term.setCursorPos((w - #AUTHOR_INFO) / 2, 3);
|
||||
write(AUTHOR_INFO);
|
||||
|
||||
for i, v in pairs(INFO_TEXT) do
|
||||
term.setCursorPos(6, h - 6 + i);
|
||||
write(v);
|
||||
end;
|
||||
|
||||
if timeout > -1 then
|
||||
timeoutTimer = os.startTimer(1);
|
||||
printTimeoutText();
|
||||
end;
|
||||
|
||||
-- Print the entries and handle keyboard input
|
||||
while true do
|
||||
local printIndex = 1;
|
||||
for i, v in pairs(entryNames) do
|
||||
if printIndex == selected then
|
||||
term.setTextColor(colors.black);
|
||||
term.setBackgroundColor(colors.white);
|
||||
end;
|
||||
term.setCursorPos(3, 5 + printIndex - 1);
|
||||
for i=0,w - 6 do write(' ') end
|
||||
term.setCursorPos(3, 5 + printIndex - 1);
|
||||
print(v);
|
||||
if printIndex == selected then
|
||||
term.setTextColor(colors.white);
|
||||
term.setBackgroundColor(colors.black);
|
||||
end;
|
||||
printIndex = printIndex + 1;
|
||||
end
|
||||
|
||||
local event, val = os.pullEvent();
|
||||
if event == "key" then
|
||||
if val == keys.up then
|
||||
selected = selected - 1;
|
||||
os.cancelTimer(timeoutTimer);
|
||||
removeTimeoutText();
|
||||
elseif val == keys.down then
|
||||
selected = selected + 1;
|
||||
os.cancelTimer(timeoutTimer);
|
||||
removeTimeoutText();
|
||||
elseif val == keys.enter then
|
||||
bootOS(selected);
|
||||
end;
|
||||
|
||||
if selected < 1 then
|
||||
selected = 1;
|
||||
elseif selected >= printIndex then
|
||||
selected = selected - 1;
|
||||
end;
|
||||
|
||||
elseif event == "timer" and val == timeoutTimer then
|
||||
timeout = timeout - 1;
|
||||
printTimeoutText();
|
||||
|
||||
if timeout == -1 then
|
||||
bootOS(selected);
|
||||
end;
|
||||
timeoutTimer = os.startTimer(1);
|
||||
end;
|
||||
end;
|
8
boot/ccboot/ccboot.cfg
Normal file
8
boot/ccboot/ccboot.cfg
Normal file
|
@ -0,0 +1,8 @@
|
|||
selected 1
|
||||
timeout 5
|
||||
|
||||
entry bits-UI;system/boot.lua
|
||||
entry bits-UI Update;system/update.lua
|
||||
entry bits-UI Recovery;system/recovery/main.lua
|
||||
entry CraftOS Regular;rom/programs/shell.lua
|
||||
entry CraftOS (MBS);boot/mbs.lua
|
5
boot/mbs.lua
Normal file
5
boot/mbs.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
assert(loadfile("/.mbs/bin/mbs.lua", _ENV))('startup')
|
||||
term.setTextColor(16)
|
||||
print(os.version() .. " (+MBS)")
|
||||
term.setCursorPos(1,2)
|
||||
term.setTextColor(1)
|
120
startup.lua
120
startup.lua
|
@ -1,116 +1,10 @@
|
|||
--[[
|
||||
bits-UI Boot Loader (BUBL): A boot loader for bits-UI
|
||||
Copyright (C) 2019 Alee14
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
]]--
|
||||
local boot = "/system/boot.lua"
|
||||
local bublcfg = "/boot/bubl.cfg"
|
||||
local bVersion = "0.2"
|
||||
local devMode = false
|
||||
|
||||
function bootloader()
|
||||
term.setCursorPos(1,1)
|
||||
print("Welcome to the BUBL boot loader!\n")
|
||||
term.setCursorPos(1,2)
|
||||
if fs.exists("/.git") then
|
||||
print("Version ".. bVersion .. "-DEV")
|
||||
else
|
||||
print("Version ".. bVersion)
|
||||
end
|
||||
term.setCursorPos(1,4)
|
||||
print("1. Boot bits-UI\n")
|
||||
term.setCursorPos(1,5)
|
||||
print("2. Update bits-UI\n")
|
||||
term.setCursorPos(1,6)
|
||||
print("3. Recovery Mode\n")
|
||||
term.setCursorPos(1,7)
|
||||
print("4. Boot CraftOS with MBS\n")
|
||||
term.setCursorPos(1,8)
|
||||
print("5. Shutdown\n")
|
||||
term.setCursorPos(1,10)
|
||||
term.write("> ")
|
||||
end
|
||||
|
||||
function clear()
|
||||
if fs.exists("/boot/ccboot/boot.lua") then
|
||||
shell.run("boot/ccboot/boot.lua");
|
||||
else
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
term.setTextColor(colors.white)
|
||||
term.setTextColor(colors.red)
|
||||
print("CCBoot doesn't exist halting...")
|
||||
sleep(2)
|
||||
os.shutdown()
|
||||
end
|
||||
|
||||
function bootloaderInput()
|
||||
local input = read()
|
||||
|
||||
if input == "1" then
|
||||
clear()
|
||||
print("Loading bits-UI...")
|
||||
sleep(1)
|
||||
clear()
|
||||
if fs.exists(boot) then
|
||||
shell.run("/system/boot.lua")
|
||||
else
|
||||
clear()
|
||||
term.setTextColor(colors.red)
|
||||
print("[ERROR] System has been halted.")
|
||||
term.setCursorPos(1,2)
|
||||
print("Details: Cannot find boot.lua")
|
||||
sleep(2)
|
||||
os.shutdown()
|
||||
end
|
||||
elseif input == "2" then
|
||||
clear()
|
||||
if devMode == true then
|
||||
print("Developer mode is set to true!\n Which means that you cannot update, you must use github to update.")
|
||||
sleep(2)
|
||||
clear()
|
||||
bootloader()
|
||||
bootloaderInput()
|
||||
else
|
||||
print("Running the updater...")
|
||||
sleep(1)
|
||||
shell.run("pastebin", "run", "7XY80hfG")
|
||||
end
|
||||
elseif input == "3" then
|
||||
clear()
|
||||
print("Running Recovery Mode...")
|
||||
sleep(1)
|
||||
shell.run("/system/recovery/main.lua")
|
||||
elseif input == "4" then
|
||||
clear()
|
||||
sleep(1)
|
||||
assert(loadfile("/.mbs/bin/mbs.lua", _ENV))('startup')
|
||||
term.setTextColor(16)
|
||||
print(os.version() .. " (+MBS)")
|
||||
term.setCursorPos(1,2)
|
||||
term.setTextColor(1)
|
||||
elseif input == "5" then
|
||||
os.shutdown();
|
||||
else
|
||||
print("[ERROR] Invalid number.")
|
||||
sleep(1)
|
||||
clear()
|
||||
bootloader()
|
||||
bootloaderInput()
|
||||
end
|
||||
|
||||
end
|
||||
clear()
|
||||
print("Welcome to BUBL!")
|
||||
sleep(1)
|
||||
if fs.exists("/.git") then
|
||||
devMode = true
|
||||
else
|
||||
devMode = false
|
||||
end
|
||||
clear()
|
||||
bootloader()
|
||||
bootloaderInput()
|
||||
|
|
|
@ -4,4 +4,4 @@ Please note that this project is in very early development and there might not b
|
|||
|
||||
Oh yeah! Feel free to contribute to this project by the following link!
|
||||
|
||||
Source Code: https://github.com/Alee14/bits-UI
|
||||
Source Code: https://github.com/aleeproductions/bits-UI
|
||||
|
|
30
system/update.lua
Normal file
30
system/update.lua
Normal file
|
@ -0,0 +1,30 @@
|
|||
--[[
|
||||
bits-UI Update: A boot loader for bits-UI
|
||||
Copyright (C) 2019 Alee14
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
]]--
|
||||
local devMode = false
|
||||
if fs.exists("/.git") then
|
||||
devMode = true
|
||||
else
|
||||
devMode = false
|
||||
end
|
||||
if devMode == true then
|
||||
print("Developer mode is set to true!\nWhich means that you cannot update, you must use github to update.")
|
||||
sleep(2)
|
||||
os.reboot()
|
||||
else
|
||||
print("Running the updater...")
|
||||
sleep(1)
|
||||
shell.run("pastebin", "run", "7XY80hfG")
|
||||
end
|
Loading…
Reference in a new issue