Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- function main()
- term.clear()
- term.setCursorPos(1,1)
- print("===================================")
- print(" Doggy OS Installation Media")
- print("===================================")
- print("OS VERSION: Doggy OS 13.0")
- print("UEFI: N3K0 UEFI")
- print("BOOTLOADER: VA11-ILLA 12.0")
- print("")
- print("Choose an option:")
- print("I: Install OS")
- print("R: Repair OS")
- print("C: Cancel")
- print("===================================")
- local user_input = read()
- if user_input:lower() == 'i' then
- confirmInstall()
- elseif user_input:lower() == 'r' then
- repairMenu()
- elseif user_input:lower() == 'c' then
- cancelInstall()
- else
- shell.run("/disk/startup")
- main()
- end
- end
- function confirmInstall()
- term.clear()
- term.setCursorPos(1,1)
- print("===================================")
- print(" Confirm Install")
- print("===================================")
- print("Y: Install OS")
- print("N: Cancel Install")
- print("===================================")
- local user_input = read()
- if user_input:lower() == 'y' then
- runInstallProgram()
- elseif user_input:lower() == 'n' then
- cancelInstall()
- else
- main()
- end
- end
- function runInstallProgram()
- shell.run("/disk/install") -- Replace with actual install program
- end
- function cancelInstall()
- term.clear()
- term.setCursorPos(1,1)
- print("===================================")
- print(" Doggy OS Installation Media")
- print("===================================")
- print("The Installation Was Cancelled!")
- print("")
- print("Shutting Down...")
- sleep(4)
- os.shutdown()
- end
- function repairMenu()
- term.clear()
- term.setCursorPos(1,1)
- print("===================================")
- print(" Doggy OS Repair Menu")
- print("===================================")
- print("1: Repair Bootloader")
- print("2: Repair System Software")
- print("B: Back to Main Menu")
- print("===================================")
- local user_input = read()
- if user_input == '1' then
- runBootloaderRepair()
- elseif user_input == '2' then
- runSystemRepair()
- elseif user_input:lower() == 'b' then
- main()
- else
- repairMenu()
- end
- end
- function runBootloaderRepair()
- -- Bootloader repair code
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- local width, height = term.getSize()
- local function centerText(y, text)
- local x = math.floor((width - #text) / 2)
- term.setCursorPos(x, y)
- term.write(text)
- end
- local dogArt = {
- " |\\_/| ",
- " | @ @ ",
- " | <> _ ",
- " | _/\\------____ ((| |))",
- " | `--' | ",
- " _____|_ ___| |___. ",
- "/_/_____/____/_______| "
- }
- local startLine = math.floor((height - #dogArt) / 2) - 2
- for i, line in ipairs(dogArt) do
- centerText(startLine + i, line)
- end
- centerText(startLine + #dogArt + 2, "Repairing System Bootloader...")
- sleep(10)
- fs.delete("/startup")
- fs.delete("/no-os")
- fs.copy("/recovery/boot/error", "/startup")
- fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
- centerText(startLine + #dogArt + 4, "Repair Completed. Rebooting...")
- sleep(3)
- os.reboot()
- end
- function runSystemRepair()
- -- System software repair code
- local diskPath = "/disk/"
- local recoveryPath = "/recovery/"
- local noOsPath = "/no-os"
- local function directoryExists(path)
- return fs.exists(path) and fs.isDir(path)
- end
- local function copyDirectoryContents(source, destination)
- if not directoryExists(source) then return false end
- if directoryExists(destination) then fs.delete(destination) end
- fs.copy(source, destination)
- return true
- end
- local function displayScrollingMessage(message)
- term.clear()
- term.setCursorPos(1, 1)
- print("Doggy OS Automatic Repair on Startup Failure")
- print("-------------------------------------------\n")
- local lines = {}
- for line in message:gmatch("[^\r\n]+") do table.insert(lines, line) end
- local maxLines = 10
- local startLine = 1
- while startLine <= #lines do
- term.clear()
- term.setCursorPos(1, 1)
- print("Doggy OS Automatic Repair on Startup Failure")
- print("-------------------------------------------\n")
- for i = startLine, math.min(#lines, startLine + maxLines - 1) do
- print(lines[i])
- end
- if startLine + maxLines <= #lines then
- print("\nPress any key to scroll down...")
- os.pullEvent("key")
- else
- print("\nPress any key to continue...")
- os.pullEvent("key")
- break
- end
- startLine = startLine + maxLines
- end
- end
- local function displayErrorMessage(errorType)
- local errorMessage
- if errorType == "OSDirectoryMissing" then
- errorMessage = "Issue: OS Directory Missing"
- elseif errorType == "RestoreFailure" then
- errorMessage = "Failed to restore from /recovery/."
- elseif errorType == "CreationFailure" then
- errorMessage = "Failed to create /disk/ from /recovery/."
- else
- errorMessage = "Unknown error."
- end
- displayScrollingMessage(errorMessage)
- shell.run(noOsPath)
- end
- if not directoryExists(recoveryPath) then
- shell.run(noOsPath)
- return
- end
- displayScrollingMessage("Repairing system software...")
- if directoryExists(diskPath) then
- local success = copyDirectoryContents(recoveryPath, diskPath)
- if success then
- displayScrollingMessage("Repair successful!")
- os.reboot()
- else
- displayErrorMessage("RestoreFailure")
- end
- else
- local success = copyDirectoryContents(recoveryPath, diskPath)
- if success then
- displayScrollingMessage("Repair successful!")
- os.reboot()
- else
- displayErrorMessage("CreationFailure")
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement