Advertisement
DOGGYWOOF

Boot-Failure

Aug 25th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. -- Initial Error Screen Code
  2. local function displayErrorScreen()
  3. -- Clear the screen and set up colors
  4. term.clear()
  5. term.setBackgroundColor(colors.black)
  6. term.setTextColor(colors.white)
  7. term.clear()
  8.  
  9. -- Define the width and height of the screen
  10. local width, height = term.getSize()
  11.  
  12. -- Helper function to center text on the screen
  13. local function centerText(y, text, textColor)
  14. local x = math.floor((width - #text) / 2)
  15. term.setCursorPos(x, y)
  16. term.setTextColor(textColor)
  17. term.write(text)
  18. end
  19.  
  20. -- Display the dog ASCII art with red Xes for eyes
  21. local dogArt = {
  22. " |\\_/| ",
  23. " | X X SYSTEM ERROR! ",
  24. " | <> _ ",
  25. " | _/\\------____ ((| |))",
  26. " | `--' | ",
  27. " _____|_ ___| |___. ",
  28. "/_/_____/____/_______| "
  29. }
  30.  
  31. local startLine = math.floor((height - #dogArt) / 2) - 2
  32.  
  33. -- Display the dog ASCII art with red Xes for eyes in red
  34. term.setTextColor(colors.red)
  35. for i, line in ipairs(dogArt) do
  36. centerText(startLine + i, line, colors.red)
  37. end
  38.  
  39. -- Display error message below the dog ASCII art in white
  40. term.setTextColor(colors.white)
  41. centerText(startLine + #dogArt + 2, "Fatal startup failure", colors.white)
  42. centerText(startLine + #dogArt + 3, "Error code: C633", colors.white)
  43.  
  44. -- Move "Press F1 for advanced options." to the bottom in white
  45. centerText(height - 2, "Press F1 for advanced options.", colors.white)
  46. end
  47.  
  48. -- Repair Code Function
  49. local function repairBootloader()
  50. -- Clear the screen and set up colors
  51. term.clear()
  52. term.setBackgroundColor(colors.black)
  53. term.setTextColor(colors.white)
  54. term.clear()
  55.  
  56. -- Define the width and height of the screen
  57. local width, height = term.getSize()
  58.  
  59. -- Helper function to center text on the screen
  60. local function centerText(y, text, textColor)
  61. local x = math.floor((width - #text) / 2)
  62. term.setCursorPos(x, y)
  63. term.setTextColor(textColor)
  64. term.write(text)
  65. end
  66.  
  67. -- Define the dog ASCII art with white color and @ for eyes
  68. local dogArt = {
  69. " |\\_/| ",
  70. " | @ @ ",
  71. " | <> _ ",
  72. " | _/\\------____ ((| |))",
  73. " | `--' | ",
  74. " _____|_ ___| |___. ",
  75. "/_/_____/____/_______| "
  76. }
  77.  
  78. local startLine = math.floor((height - #dogArt) / 2) - 2
  79.  
  80. -- Display the dog ASCII art with white color
  81. term.setTextColor(colors.white)
  82. for i, line in ipairs(dogArt) do
  83. centerText(startLine + i, line, colors.white)
  84. end
  85.  
  86. -- Display the "Repairing System Bootloader..." message in white
  87. centerText(startLine + #dogArt + 2, "Repairing System Bootloader...", colors.white)
  88.  
  89. -- Wait for 10 seconds to simulate the repair process
  90. sleep(10)
  91.  
  92. -- Delete existing startup and no-os files
  93. fs.delete("/startup")
  94. fs.delete("/no-os")
  95.  
  96. -- Copy the recovery files to the root directory
  97. fs.copy("/recovery/boot/error", "/startup")
  98. fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
  99.  
  100. -- Display the "Repair Completed. Rebooting..." message in white
  101. centerText(startLine + #dogArt + 4, "Repair Completed. Rebooting...", colors.white)
  102.  
  103. -- Wait for 3 seconds before rebooting
  104. sleep(3)
  105.  
  106. -- Reboot the system
  107. os.reboot()
  108. end
  109.  
  110. -- Recovery Shell Function
  111. local function recoveryShell()
  112. -- Clear the screen and set up colors
  113. term.clear()
  114. term.setBackgroundColor(colors.black)
  115. term.setTextColor(colors.white)
  116. term.clear()
  117.  
  118. -- Alternative shell from CraftOS shell
  119. termutils = {}
  120.  
  121. termutils.clear = function()
  122. term.clear()
  123. term.setCursorPos(1,1)
  124. end
  125.  
  126. termutils.clearColor = function()
  127. term.setTextColor(colors.white)
  128. term.setBackgroundColor(colors.black)
  129. end
  130.  
  131. function input()
  132. term.setTextColor(colors.white)
  133. local dir = shell.dir().."/"..">"
  134. write(dir)
  135. termutils.clearColor()
  136. command = io.read()
  137. end
  138.  
  139. termutils.clear()
  140. print("VA11-ILLA EFI Recovery Shell")
  141. while true do
  142. input()
  143. shell.run(command)
  144. end
  145. end
  146.  
  147. -- Main Logic
  148. local function main()
  149. -- Display the error screen initially
  150. displayErrorScreen()
  151.  
  152. -- Wait for F1 key press (simulated as a specific input for simplicity)
  153. while true do
  154. local event, key = os.pullEvent("key")
  155. if key == keys.f1 then
  156. -- Ask user for recovery option
  157. term.clear()
  158. print("Select Recovery Option:")
  159. print("1. Repair Bootloader")
  160. print("2. Recover from /recovery")
  161. print("3. Recover from external source")
  162. print("4. Run recovery shell")
  163. local option = io.read()
  164.  
  165. if option == "1" then
  166. repairBootloader()
  167. elseif option == "2" then
  168. -- Implement recovery from /recovery
  169. term.clear()
  170. print("Recovering from /recovery...")
  171. fs.delete("/disk/")
  172. fs.copy("/recovery/", "/disk/")
  173. print("Recovery from /recovery completed.")
  174. os.reboot()
  175. elseif option == "3" then
  176. -- Implement recovery from external source
  177. term.clear()
  178. print("Recovering from external source...")
  179. fs.delete("/disk/")
  180. fs.copy("/disk2/", "/disk/")
  181. print("Recovery from external source completed.")
  182. os.reboot()
  183. elseif option == "4" then
  184. recoveryShell()
  185. else
  186. print("Invalid option.")
  187. end
  188. end
  189. end
  190. end
  191.  
  192. -- Run the main function
  193. main()
  194.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement