Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initial Error Screen Code
- local function displayErrorScreen()
- -- Clear the screen and set up colors
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- -- Define the width and height of the screen
- local width, height = term.getSize()
- -- Helper function to center text on the screen
- local function centerText(y, text, textColor)
- local x = math.floor((width - #text) / 2)
- term.setCursorPos(x, y)
- term.setTextColor(textColor)
- term.write(text)
- end
- -- Display the dog ASCII art with red Xes for eyes
- local dogArt = {
- " |\\_/| ",
- " | X X SYSTEM ERROR! ",
- " | <> _ ",
- " | _/\\------____ ((| |))",
- " | `--' | ",
- " _____|_ ___| |___. ",
- "/_/_____/____/_______| "
- }
- local startLine = math.floor((height - #dogArt) / 2) - 2
- -- Display the dog ASCII art with red Xes for eyes in red
- term.setTextColor(colors.red)
- for i, line in ipairs(dogArt) do
- centerText(startLine + i, line, colors.red)
- end
- -- Display error message below the dog ASCII art in white
- term.setTextColor(colors.white)
- centerText(startLine + #dogArt + 2, "Fatal startup failure", colors.white)
- centerText(startLine + #dogArt + 3, "Error code: C633", colors.white)
- -- Move "Press F1 for advanced options." to the bottom in white
- centerText(height - 2, "Press F1 for advanced options.", colors.white)
- end
- -- Repair Code Function
- local function repairBootloader()
- -- Clear the screen and set up colors
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- -- Define the width and height of the screen
- local width, height = term.getSize()
- -- Helper function to center text on the screen
- local function centerText(y, text, textColor)
- local x = math.floor((width - #text) / 2)
- term.setCursorPos(x, y)
- term.setTextColor(textColor)
- term.write(text)
- end
- -- Define the dog ASCII art with white color and @ for eyes
- local dogArt = {
- " |\\_/| ",
- " | @ @ ",
- " | <> _ ",
- " | _/\\------____ ((| |))",
- " | `--' | ",
- " _____|_ ___| |___. ",
- "/_/_____/____/_______| "
- }
- local startLine = math.floor((height - #dogArt) / 2) - 2
- -- Display the dog ASCII art with white color
- term.setTextColor(colors.white)
- for i, line in ipairs(dogArt) do
- centerText(startLine + i, line, colors.white)
- end
- -- Display the "Repairing System Bootloader..." message in white
- centerText(startLine + #dogArt + 2, "Repairing System Bootloader...", colors.white)
- -- Wait for 10 seconds to simulate the repair process
- sleep(10)
- -- Delete existing startup and no-os files
- fs.delete("/startup")
- fs.delete("/no-os")
- -- Copy the recovery files to the root directory
- fs.copy("/recovery/boot/error", "/startup")
- fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
- -- Display the "Repair Completed. Rebooting..." message in white
- centerText(startLine + #dogArt + 4, "Repair Completed. Rebooting...", colors.white)
- -- Wait for 3 seconds before rebooting
- sleep(3)
- -- Reboot the system
- os.reboot()
- end
- -- Recovery Shell Function
- local function recoveryShell()
- -- Clear the screen and set up colors
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- -- Alternative shell from CraftOS shell
- termutils = {}
- termutils.clear = function()
- term.clear()
- term.setCursorPos(1,1)
- end
- termutils.clearColor = function()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- function input()
- term.setTextColor(colors.white)
- local dir = shell.dir().."/"..">"
- write(dir)
- termutils.clearColor()
- command = io.read()
- end
- termutils.clear()
- print("VA11-ILLA EFI Recovery Shell")
- while true do
- input()
- shell.run(command)
- end
- end
- -- Main Logic
- local function main()
- -- Display the error screen initially
- displayErrorScreen()
- -- Wait for F1 key press (simulated as a specific input for simplicity)
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.f1 then
- -- Ask user for recovery option
- term.clear()
- print("Select Recovery Option:")
- print("1. Repair Bootloader")
- print("2. Recover from /recovery")
- print("3. Recover from external source")
- print("4. Run recovery shell")
- local option = io.read()
- if option == "1" then
- repairBootloader()
- elseif option == "2" then
- -- Implement recovery from /recovery
- term.clear()
- print("Recovering from /recovery...")
- fs.delete("/disk/")
- fs.copy("/recovery/", "/disk/")
- print("Recovery from /recovery completed.")
- os.reboot()
- elseif option == "3" then
- -- Implement recovery from external source
- term.clear()
- print("Recovering from external source...")
- fs.delete("/disk/")
- fs.copy("/disk2/", "/disk/")
- print("Recovery from external source completed.")
- os.reboot()
- elseif option == "4" then
- recoveryShell()
- else
- print("Invalid option.")
- end
- end
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement