Advertisement
DOGGYWOOF

Untitled

Dec 14th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.95 KB | None | 0 0
  1. -- Helper function to display ASCII art and message
  2. local function displayMessage(message)
  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. -- Define the dog ASCII art with white color and @ for eyes
  21. local dogArt = {
  22. " |\\_/| ",
  23. " | @ @ ",
  24. " | <> _ ",
  25. " | _/\\------____ ((| |))",
  26. " | --' | ",
  27. " _____|_ ___| |___. ",
  28. "/_/_____/____/_______| "
  29. }
  30.  
  31. local startLine = math.floor((height - #dogArt) / 2) - 2
  32.  
  33. -- Display the dog ASCII art with white color
  34. term.setTextColor(colors.white)
  35. for i, line in ipairs(dogArt) do
  36. centerText(startLine + i, line, colors.white)
  37. end
  38.  
  39. -- Display the provided message below the ASCII art
  40. centerText(startLine + #dogArt + 2, message, colors.white)
  41. end
  42.  
  43. -- Initial Error Screen Code
  44. local function displayErrorScreen()
  45. -- Clear the screen and set up colors
  46. term.clear()
  47. term.setBackgroundColor(colors.black)
  48. term.setTextColor(colors.white)
  49. term.clear()
  50.  
  51. -- Define the width and height of the screen
  52. local width, height = term.getSize()
  53.  
  54. -- Helper function to center text on the screen
  55. local function centerText(y, text, textColor)
  56. local x = math.floor((width - #text) / 2)
  57. term.setCursorPos(x, y)
  58. term.setTextColor(textColor)
  59. term.write(text)
  60. end
  61.  
  62. -- Display the dog ASCII art with red Xes for eyes
  63. local dogArt = {
  64. " |\\_/| ",
  65. " | X X SYSTEM ERROR! ",
  66. " | <> _ ",
  67. " | _/\\------____ ((| |))",
  68. " | --' | ",
  69. " _____|_ ___| |___. ",
  70. "/_/_____/____/_______| "
  71. }
  72.  
  73. local startLine = math.floor((height - #dogArt) / 2) - 2
  74.  
  75. -- Display the dog ASCII art with red Xes for eyes in red
  76. term.setTextColor(colors.red)
  77. for i, line in ipairs(dogArt) do
  78. centerText(startLine + i, line, colors.red)
  79. end
  80.  
  81. -- Display error message below the dog ASCII art in white
  82. term.setTextColor(colors.white)
  83. centerText(startLine + #dogArt + 2, "Fatal startup failure", colors.white)
  84. centerText(startLine + #dogArt + 3, "Error code: C633", colors.white)
  85.  
  86. -- Move "Press F1 for advanced options." to the bottom in white
  87. centerText(height - 2, "Press F1 for advanced options.", colors.white)
  88. end
  89.  
  90. -- Recovery Menu UI
  91. local function displayRecoveryMenu()
  92. -- Clear the screen and set up colors
  93. term.clear()
  94. term.setBackgroundColor(colors.black)
  95. term.setTextColor(colors.white)
  96. term.clear()
  97.  
  98. -- Define the width and height of the screen
  99. local width, height = term.getSize()
  100.  
  101. -- Helper function to center text on the screen
  102. local function centerText(y, text, textColor)
  103. local x = math.floor((width - #text) / 2)
  104. term.setCursorPos(x, y)
  105. term.setTextColor(textColor)
  106. term.write(text)
  107. end
  108.  
  109. -- Display a menu header
  110. local header = "System Recovery on boot failure"
  111. local options = {
  112. "1. Repair Bootloader",
  113. "2. Recover from /recovery",
  114. "3. Recover from external source",
  115. "4. Run recovery shell",
  116. "5. Exit"
  117. }
  118.  
  119. local startLine = math.floor((height - #options - 4) / 2)
  120.  
  121. -- Display the header
  122. term.setTextColor(colors.cyan)
  123. centerText(startLine, header, colors.cyan)
  124. term.setTextColor(colors.white)
  125. for i, option in ipairs(options) do
  126. centerText(startLine + i + 1, option, colors.white)
  127. end
  128. end
  129.  
  130. -- Request recovery key from file
  131. local function getRecoveryKey()
  132. local filePath = "/disk/security/recoveryKEY.txt"
  133. if fs.exists(filePath) then
  134. local file = fs.open(filePath, "r")
  135. local recoveryKey = file.readAll()
  136. file.close()
  137. return recoveryKey
  138. else
  139. displayMessage("Recovery key not found!")
  140. return nil
  141. end
  142. end
  143.  
  144. -- Validate entered recovery key
  145. local function validateRecoveryKey()
  146. local recoveryKey = getRecoveryKey()
  147. if not recoveryKey then
  148. return false
  149. end
  150.  
  151. term.clear()
  152. term.setBackgroundColor(colors.black)
  153. term.setTextColor(colors.white)
  154. term.setCursorPos(1, 1)
  155. term.write("Enter recovery key: ")
  156. local userKey = read()
  157.  
  158. if userKey == recoveryKey then
  159. return true
  160. else
  161. displayMessage("Invalid recovery key!")
  162. return false
  163. end
  164. end
  165.  
  166. -- Repair Code Function
  167. local function repairBootloader()
  168. displayMessage("Repairing System Bootloader...")
  169.  
  170. -- Wait for 10 seconds to simulate the repair process
  171. sleep(10)
  172.  
  173. -- Delete existing startup and no-os files
  174. fs.delete("/startup")
  175. fs.delete("/no-os")
  176.  
  177. -- Copy the recovery files to the root directory
  178. fs.copy("/recovery/boot/error", "/startup")
  179. fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
  180.  
  181. -- Display the "Repair Completed. Rebooting..." message in white
  182. displayMessage("Repair Completed. Rebooting...")
  183.  
  184. -- Wait for 3 seconds before rebooting
  185. sleep(3)
  186.  
  187. -- Reboot the system
  188. os.reboot()
  189. end
  190.  
  191. -- Recovery from /recovery Function
  192. local function recoverFromRecovery()
  193. displayMessage("Repairing File System")
  194.  
  195. -- Wait for 10 seconds to simulate the recovery process
  196. sleep(10)
  197.  
  198. -- Delete existing disk directory and copy files from /recovery
  199. fs.delete("/disk/")
  200. fs.copy("/recovery/", "/disk/")
  201.  
  202. -- Display the "Recovery Completed. Rebooting..." message in white
  203. displayMessage("Recovery Completed. Rebooting...")
  204.  
  205. -- Wait for 3 seconds before rebooting
  206. sleep(3)
  207.  
  208. -- Reboot the system
  209. os.reboot()
  210. end
  211.  
  212. -- Recovery from External Source Function
  213. local function recoverFromExternalSource()
  214. -- Clear the screen and set up colors
  215. term.clear()
  216. term.setBackgroundColor(colors.black)
  217. term.setTextColor(colors.white)
  218. term.clear()
  219.  
  220. -- Define the width and height of the screen
  221. local width, height = term.getSize()
  222.  
  223. -- Helper function to center text on the screen
  224. local function centerText(y, text, textColor)
  225. local x = math.floor((width - #text) / 2)
  226. term.setCursorPos(x, y)
  227. term.setTextColor(textColor)
  228. term.write(text)
  229. end
  230.  
  231. -- Define the dog ASCII art with white color and @ for eyes
  232. local dogArt = {
  233. " |\\_/| ",
  234. " | @ @ ",
  235. " | <> _ ",
  236. " | _/\\------____ ((| |))",
  237. " | --' | ",
  238. " _____|_ ___| |___. ",
  239. "/_/_____/____/_______| "
  240. }
  241.  
  242. local startLine = math.floor((height - #dogArt) / 2) - 2
  243.  
  244. -- Display the dog ASCII art with white color
  245. term.setTextColor(colors.white)
  246. for i, line in ipairs(dogArt) do
  247. centerText(startLine + i, line, colors.white)
  248. end
  249.  
  250. -- Display the "Installing System Update from /disk2/" message in white
  251. centerText(startLine + #dogArt + 2, "Installing System Update from /disk2/", colors.white)
  252.  
  253. -- Wait for 10 seconds to simulate the update process
  254. sleep(10)
  255.  
  256. -- Check if /disk2 exists before copying
  257. if fs.exists("/disk2/") then
  258. fs.delete("/disk/")
  259. fs.copy("/disk2/", "/disk/")
  260. -- Display the "Update Completed. Rebooting..." message in white
  261. centerText(startLine + #dogArt + 4, "Update Completed. Rebooting...", colors.white)
  262. else
  263. -- Display an error message if /disk2 does not exist
  264. centerText(startLine + #dogArt + 4, "Error: /disk2 does not exist.", colors.red)
  265. end
  266.  
  267. -- Wait for 3 seconds before rebooting
  268. sleep(3)
  269.  
  270. -- Reboot the system
  271. os.reboot()
  272. end
  273.  
  274. -- Recovery Shell Function
  275. local function recoveryShell()
  276. -- Clear the screen and set up colors
  277. term.clear()
  278. term.setBackgroundColor(colors.black)
  279. term.setTextColor(colors.white)
  280. term.clear()
  281.  
  282. -- Alternative shell from CraftOS shell
  283. termutils = {}
  284.  
  285. termutils.clear = function()
  286. term.clear()
  287. term.setCursorPos(1,1)
  288. end
  289.  
  290. termutils.clearColor = function()
  291. term.setTextColor(colors.white)
  292. term.setBackgroundColor(colors.black)
  293. end
  294.  
  295. function input()
  296. term.setTextColor(colors.white)
  297. local dir = shell.dir().."/"..">"
  298. write(dir)
  299. termutils.clearColor()
  300. command = io.read()
  301. end
  302.  
  303. termutils.clear()
  304. print("VA11-ILLA EFI Recovery Shell")
  305. while true do
  306. input()
  307. shell.run(command)
  308. end
  309. end
  310.  
  311. -- Main Menu Logic
  312. displayErrorScreen()
  313.  
  314. while true do
  315. local event, key = os.pullEvent("key")
  316.  
  317. if key == keys.f1 then
  318. -- Ask for recovery key first
  319. if validateRecoveryKey() then
  320. displayRecoveryMenu()
  321.  
  322. while true do
  323. event, key = os.pullEvent("key")
  324. if key == keys.one then
  325. repairBootloader()
  326. elseif key == keys.two then
  327. recoverFromRecovery()
  328. elseif key == keys.three then
  329. recoverFromExternalSource()
  330. elseif key == keys.f4 then
  331. recoveryShell()
  332. elseif key == keys.f5 then
  333. return -- Exit the menu
  334. end
  335. end
  336. end
  337. end
  338. end
  339.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement