aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--boot/ccboot/boot.lua177
-rw-r--r--boot/ccboot/ccboot.cfg8
-rw-r--r--boot/mbs.lua5
-rw-r--r--startup.lua120
-rw-r--r--system/skel/README.txt2
-rw-r--r--system/update.lua30
7 files changed, 229 insertions, 114 deletions
diff --git a/README.md b/README.md
index ba508fd..a06827a 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/boot/ccboot/boot.lua b/boot/ccboot/boot.lua
new file mode 100644
index 0000000..f094de0
--- /dev/null
+++ b/boot/ccboot/boot.lua
@@ -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;
diff --git a/boot/ccboot/ccboot.cfg b/boot/ccboot/ccboot.cfg
new file mode 100644
index 0000000..3c7cbd4
--- /dev/null
+++ b/boot/ccboot/ccboot.cfg
@@ -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 \ No newline at end of file
diff --git a/boot/mbs.lua b/boot/mbs.lua
new file mode 100644
index 0000000..a80ee70
--- /dev/null
+++ b/boot/mbs.lua
@@ -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) \ No newline at end of file
diff --git a/startup.lua b/startup.lua
index 1d520a4..f0dd84d 100644
--- a/startup.lua
+++ b/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)
-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
+ term.setTextColor(colors.red)
+ print("CCBoot doesn't exist halting...")
+ sleep(2)
+ os.shutdown()
end
-clear()
-bootloader()
-bootloaderInput()
diff --git a/system/skel/README.txt b/system/skel/README.txt
index ef149d6..e7c2cf4 100644
--- a/system/skel/README.txt
+++ b/system/skel/README.txt
@@ -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 \ No newline at end of file
+Source Code: https://github.com/aleeproductions/bits-UI
diff --git a/system/update.lua b/system/update.lua
new file mode 100644
index 0000000..7239f9a
--- /dev/null
+++ b/system/update.lua
@@ -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 \ No newline at end of file