Advertisement
DOGGYWOOF

Doggy OS Boot Manager

May 23rd, 2024 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. -- doggy_os_boot_manager.lua
  2.  
  3. local function getStartupFiles()
  4. local startupFiles = {}
  5. local sides = {"left", "right", "top", "bottom", "front", "back"}
  6.  
  7. for _, side in ipairs(sides) do
  8. if disk.isPresent(side) then
  9. local path = disk.getMountPath(side)
  10. local startupPaths = {
  11. fs.combine(path, "startup"),
  12. fs.combine(path, "startup.lua")
  13. }
  14.  
  15. for _, startupPath in ipairs(startupPaths) do
  16. if fs.exists(startupPath) and not fs.isDir(startupPath) then
  17. table.insert(startupFiles, {
  18. path = startupPath,
  19. label = disk.getLabel(side) or side
  20. })
  21. end
  22. end
  23. end
  24. end
  25.  
  26. return startupFiles
  27. end
  28.  
  29. local function displayHeader()
  30. term.clear()
  31. term.setCursorPos(1, 1)
  32. print("======================================")
  33. print(" Doggy OS Boot Manager")
  34. print("======================================")
  35. end
  36.  
  37. local function displayMenu(startupFiles)
  38. displayHeader()
  39. print("Select a startup file to run (or press 'q' to reboot):")
  40.  
  41. for i, file in ipairs(startupFiles) do
  42. print(string.format("%d. [%s] %s", i, file.label, file.path))
  43. end
  44.  
  45. print("Enter the number of the file to run:")
  46. end
  47.  
  48. local function promptReboot(message)
  49. displayHeader()
  50. print(message)
  51. print("Press Enter to reboot the system.")
  52. read()
  53. os.reboot()
  54. end
  55.  
  56. local function runSelectedFile(startupFiles)
  57. local choice
  58.  
  59. while true do
  60. displayMenu(startupFiles)
  61. local input = read()
  62.  
  63. if input == "q" then
  64. os.reboot()
  65. end
  66.  
  67. choice = tonumber(input)
  68.  
  69. if choice and startupFiles[choice] then
  70. break
  71. else
  72. term.setCursorPos(1, 19)
  73. print("Invalid selection. Please try again.")
  74. sleep(1)
  75. end
  76. end
  77.  
  78. displayHeader()
  79. print("Loading Startup Script")
  80. print("======================================")
  81. sleep(3)
  82.  
  83. local success, errorMessage = pcall(function()
  84. shell.run(startupFiles[choice].path)
  85. end)
  86.  
  87. if not success then
  88. promptReboot("Error occurred: " .. errorMessage)
  89. end
  90. end
  91.  
  92. local function main()
  93. displayHeader()
  94. print("Loading...")
  95. sleep(3)
  96.  
  97. local startupFiles = getStartupFiles()
  98.  
  99. if #startupFiles == 0 then
  100. promptReboot("No startup files found on connected disks.")
  101. else
  102. runSelectedFile(startupFiles)
  103. end
  104. end
  105.  
  106. -- Main Program Execution
  107. main()
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement