Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- doggy_os_boot_manager.lua
- local function getStartupFiles()
- local startupFiles = {}
- local sides = {"left", "right", "top", "bottom", "front", "back"}
- for _, side in ipairs(sides) do
- if disk.isPresent(side) then
- local path = disk.getMountPath(side)
- local startupPaths = {
- fs.combine(path, "startup"),
- fs.combine(path, "startup.lua")
- }
- for _, startupPath in ipairs(startupPaths) do
- if fs.exists(startupPath) and not fs.isDir(startupPath) then
- table.insert(startupFiles, {
- path = startupPath,
- label = disk.getLabel(side) or side
- })
- end
- end
- end
- end
- return startupFiles
- end
- local function displayHeader()
- term.clear()
- term.setCursorPos(1, 1)
- print("======================================")
- print(" Doggy OS Boot Manager")
- print("======================================")
- end
- local function displayMenu(startupFiles)
- displayHeader()
- print("Select a startup file to run (or press 'q' to reboot):")
- for i, file in ipairs(startupFiles) do
- print(string.format("%d. [%s] %s", i, file.label, file.path))
- end
- print("Enter the number of the file to run:")
- end
- local function promptReboot(message)
- displayHeader()
- print(message)
- print("Press Enter to reboot the system.")
- read()
- os.reboot()
- end
- local function runSelectedFile(startupFiles)
- local choice
- while true do
- displayMenu(startupFiles)
- local input = read()
- if input == "q" then
- os.reboot()
- end
- choice = tonumber(input)
- if choice and startupFiles[choice] then
- break
- else
- term.setCursorPos(1, 19)
- print("Invalid selection. Please try again.")
- sleep(1)
- end
- end
- displayHeader()
- print("Loading Startup Script")
- print("======================================")
- sleep(3)
- local success, errorMessage = pcall(function()
- shell.run(startupFiles[choice].path)
- end)
- if not success then
- promptReboot("Error occurred: " .. errorMessage)
- end
- end
- local function main()
- displayHeader()
- print("Loading...")
- sleep(3)
- local startupFiles = getStartupFiles()
- if #startupFiles == 0 then
- promptReboot("No startup files found on connected disks.")
- else
- runSelectedFile(startupFiles)
- end
- end
- -- Main Program Execution
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement