Advertisement
DOGGYWOOF

Untitled

Jan 11th, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. -- Doggy OS Boot Manager for CC Tweaked
  2.  
  3. -- List of allowed disk IDs (you can populate this with the IDs of the allowed disks)
  4. local allowedDisks = {
  5. "/disk2", -- Example: disk2 is allowed by default
  6. "/disk3", -- Example: disk3 is allowed by default
  7. }
  8.  
  9. local function findStartupFiles()
  10. local disks = {}
  11. local diskPaths = {"/disk2", "/disk3"} -- Include only /disk2/ and /disk3/
  12.  
  13. -- Search for startup files in specified disk paths
  14. for _, diskPath in ipairs(diskPaths) do
  15. local paths = {
  16. diskPath .. "/startup",
  17. diskPath .. "/startup.lua",
  18. }
  19. for _, path in ipairs(paths) do
  20. if fs.exists(path) then
  21. table.insert(disks, {path = path, displayName = path, id = diskPath})
  22. break
  23. end
  24. end
  25. end
  26.  
  27. -- Check /disk/ for /boot/error only (default entry, no secure boot check)
  28. if fs.exists("/disk/boot/error") then
  29. table.insert(disks, {path = "/disk/boot/error", displayName = "Doggy OS", id = "/disk"})
  30. end
  31.  
  32. -- Add built-in recovery option (default entry, no secure boot check)
  33. if fs.exists("/disk/boot/Recovery.lua") then
  34. table.insert(disks, {path = "/disk/boot/Recovery.lua", displayName = "Doggy OS Recovery Environment", id = "/disk"})
  35. end
  36.  
  37. return disks
  38. end
  39.  
  40. local function isDiskAllowed(diskID)
  41. -- For external disks, check if the disk is allowed by secure boot
  42. local secureBootFile = diskID .. "/.secureboot/" .. diskID:sub(6) .. ".allowed"
  43. if fs.exists(secureBootFile) then
  44. return true
  45. end
  46. return false
  47. end
  48.  
  49. local function drawMenu(disks, selected, bootingMessage)
  50. local width, height = term.getSize()
  51. local menuWidth, menuHeight = 40, 10 + #disks
  52. local startX = math.floor((width - menuWidth) / 2)
  53. local startY = math.floor((height - menuHeight) / 2)
  54.  
  55. term.setBackgroundColor(colors.black)
  56. term.clear()
  57.  
  58. -- Draw centered window background
  59. term.setBackgroundColor(colors.gray)
  60. for y = 0, menuHeight do
  61. term.setCursorPos(startX, startY + y)
  62. term.write(string.rep(" ", menuWidth))
  63. end
  64.  
  65. -- Draw Header
  66. term.setCursorPos(startX + 1, startY + 1)
  67. term.setTextColor(colors.blue)
  68. term.write(" ***** Doggy OS Boot Manager ***** ")
  69.  
  70. -- Draw Instructions
  71. term.setCursorPos(startX + 1, startY + 3)
  72. term.setTextColor(colors.lightGray)
  73. term.write("Select a boot device")
  74.  
  75. term.setCursorPos(startX + 1, startY + 4)
  76. term.write(string.rep("=", menuWidth - 2))
  77.  
  78. -- Draw boot options
  79. for i, disk in ipairs(disks) do
  80. term.setCursorPos(startX + 2, startY + 5 + i)
  81. if i == selected then
  82. term.setTextColor(colors.white)
  83. term.setBackgroundColor(colors.blue)
  84. else
  85. term.setTextColor(colors.lightGray)
  86. term.setBackgroundColor(colors.gray)
  87. end
  88. term.write(" [" .. i .. "] " .. disk.displayName .. string.rep(" ", menuWidth - 8 - #disk.displayName))
  89. end
  90.  
  91. -- Draw Footer
  92. term.setCursorPos(startX + 1, startY + 6 + #disks)
  93. term.setTextColor(colors.lightGray)
  94. term.setBackgroundColor(colors.gray)
  95. term.write(string.rep("=", menuWidth - 2))
  96.  
  97. -- Display booting message if available
  98. if bootingMessage then
  99. term.setCursorPos(startX + 2, startY + 7 + #disks)
  100. term.setTextColor(colors.cyan)
  101. term.write(bootingMessage)
  102. end
  103.  
  104. -- Reset colors
  105. term.setTextColor(colors.white)
  106. term.setBackgroundColor(colors.black)
  107. end
  108.  
  109. local function main()
  110. local disks
  111. while true do
  112. disks = findStartupFiles()
  113. if #disks > 0 then
  114. break
  115. end
  116. -- No boot files found, keep searching
  117. term.clear()
  118. term.setCursorPos(1, 1)
  119. term.setTextColor(colors.red)
  120. term.setBackgroundColor(colors.black)
  121. term.write("No boot files found. Searching...")
  122. sleep(1)
  123. end
  124.  
  125. local selected = 1
  126. drawMenu(disks, selected, nil)
  127.  
  128. while true do
  129. local event, key = os.pullEvent("key")
  130. if key == keys.up then
  131. selected = (selected - 2) % #disks + 1
  132. elseif key == keys.down then
  133. selected = selected % #disks + 1
  134. elseif key == keys.enter then
  135. -- Check if the disk is allowed to boot
  136. local selectedDisk = disks[selected]
  137. if selectedDisk.id == "/disk" or isDiskAllowed(selectedDisk.id) then
  138. -- Update the GUI to show booting message
  139. drawMenu(disks, selected, "Booting from " .. selectedDisk.path .. "...")
  140. sleep(1) -- Wait for a second to display the booting message
  141.  
  142. -- Set text color to white and background color to black before booting
  143. term.setTextColor(colors.white)
  144. term.setBackgroundColor(colors.black)
  145.  
  146. -- Boot the selected OS
  147. shell.run(selectedDisk.path)
  148. break
  149. else
  150. -- Show error message if the disk is not allowed
  151. drawMenu(disks, selected, "Error: Disk ID not allowed!")
  152. sleep(2) -- Display the error for 2 seconds
  153. drawMenu(disks, selected, nil) -- Refresh the menu
  154. end
  155. end
  156. drawMenu(disks, selected, nil) -- Refresh the menu without booting message
  157. end
  158. end
  159.  
  160. main()
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement