Advertisement
DOGGYWOOF

Untitled

Oct 10th, 2024 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 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. -- Recovery Menu UI
  44. local function displayRecoveryMenu()
  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 a menu header
  63. local header = "System Recovery on boot failure"
  64. local options = {
  65. "1. Repair Bootloader",
  66. "2. Recover from /recovery",
  67. "3. Recover from external source",
  68. "4. Run recovery shell",
  69. "5. Exit"
  70. }
  71.  
  72. local startLine = math.floor((height - #options - 4) / 2)
  73.  
  74. -- Display the header
  75. term.setTextColor(colors.cyan)
  76. centerText(startLine, header, colors.cyan)
  77. term.setTextColor(colors.white)
  78. for i, option in ipairs(options) do
  79. centerText(startLine + i + 1, option, colors.white)
  80. end
  81. end
  82.  
  83. -- Repair Code Function
  84. local function repairBootloader()
  85. displayMessage("Repairing System Bootloader...")
  86.  
  87. -- Wait for 10 seconds to simulate the repair process
  88. sleep(10)
  89.  
  90. -- Delete existing startup and no-os files
  91. fs.delete("/startup")
  92. fs.delete("/no-os")
  93.  
  94. -- Copy the recovery files to the root directory
  95. fs.copy("/recovery/boot/error", "/startup")
  96. fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
  97.  
  98. -- Display the "Repair Completed. Rebooting..." message in white
  99. displayMessage("Repair Completed. Rebooting...")
  100.  
  101. -- Wait for 3 seconds before rebooting
  102. sleep(3)
  103.  
  104. -- Reboot the system
  105. os.reboot()
  106. end
  107.  
  108. -- Recovery from /recovery Function
  109. local function recoverFromRecovery()
  110. displayMessage("Repairing File System")
  111.  
  112. -- Wait for 10 seconds to simulate the recovery process
  113. sleep(10)
  114.  
  115. -- Delete existing disk directory and copy files from /recovery
  116. fs.delete("/disk/")
  117. fs.copy("/recovery/", "/disk/")
  118.  
  119. -- Display the "Recovery Completed. Rebooting..." message in white
  120. displayMessage("Recovery Completed. Rebooting...")
  121.  
  122. -- Wait for 3 seconds before rebooting
  123. sleep(3)
  124.  
  125. -- Reboot the system
  126. os.reboot()
  127. end
  128.  
  129. -- Recovery from External Source Function
  130. local function recoverFromExternalSource()
  131. -- Clear the screen and set up colors
  132. term.clear()
  133. term.setBackgroundColor(colors.black)
  134. term.setTextColor(colors.white)
  135. term.clear()
  136.  
  137. -- Define the width and height of the screen
  138. local width, height = term.getSize()
  139.  
  140. -- Helper function to center text on the screen
  141. local function centerText(y, text, textColor)
  142. local x = math.floor((width - #text) / 2)
  143. term.setCursorPos(x, y)
  144. term.setTextColor(textColor)
  145. term.write(text)
  146. end
  147.  
  148. -- Define the dog ASCII art with white color and @ for eyes
  149. local dogArt = {
  150. " |\\_/| ",
  151. " | @ @ ",
  152. " | <> _ ",
  153. " | _/\\------____ ((| |))",
  154. " | `--' | ",
  155. " _____|_ ___| |___. ",
  156. "/_/_____/____/_______| "
  157. }
  158.  
  159. local startLine = math.floor((height - #dogArt) / 2) - 2
  160.  
  161. -- Display the dog ASCII art with white color
  162. term.setTextColor(colors.white)
  163. for i, line in ipairs(dogArt) do
  164. centerText(startLine + i, line, colors.white)
  165. end
  166.  
  167. -- Display the "Installing System Update from /disk2/" message in white
  168. centerText(startLine + #dogArt + 2, "Installing System Update from /disk2/", colors.white)
  169.  
  170. -- Wait for 10 seconds to simulate the update process
  171. sleep(10)
  172.  
  173. -- Check if /disk2 exists before copying
  174. if fs.exists("/disk2/") then
  175. fs.delete("/disk/")
  176. fs.copy("/disk2/", "/disk/")
  177. -- Display the "Update Completed. Rebooting..." message in white
  178. centerText(startLine + #dogArt + 4, "Update Completed. Rebooting...", colors.white)
  179. else
  180. -- Display an error message if /disk2 does not exist
  181. centerText(startLine + #dogArt + 4, "Error: /disk2 does not exist.", colors.red)
  182. end
  183.  
  184. -- Wait for 3 seconds before rebooting
  185. sleep(3)
  186.  
  187. -- Reboot the system
  188. os.reboot()
  189. end
  190.  
  191. -- Recovery Shell Function
  192. local function recoveryShell()
  193. -- Clear the screen and set up colors
  194. term.clear()
  195. term.setBackgroundColor(colors.black)
  196. term.setTextColor(colors.white)
  197. term.clear()
  198.  
  199. -- Alternative shell from CraftOS shell
  200. termutils = {}
  201.  
  202. termutils.clear = function()
  203. term.clear()
  204. term.setCursorPos(1,1)
  205. end
  206.  
  207. termutils.clearColor = function()
  208. term.setTextColor(colors.white)
  209. term.setBackgroundColor(colors.black)
  210. end
  211.  
  212. function input()
  213. term.setTextColor(colors.white)
  214. local dir = shell.dir().."/"..">"
  215. write(dir)
  216. termutils.clearColor()
  217. command = io.read()
  218. end
  219.  
  220. termutils.clear()
  221. print("VA11-ILLA EFI Recovery Shell")
  222. while true do
  223. input()
  224. shell.run(command)
  225. end
  226. end
  227.  
  228. -- Main Menu Logic
  229. displayRecoveryMenu()
  230.  
  231. while true do
  232. local event, key = os.pullEvent("key")
  233.  
  234. if key == keys.one then
  235. repairBootloader()
  236. elseif key == keys.two then
  237. recoverFromRecovery()
  238. elseif key == keys.three then
  239. recoverFromExternalSource()
  240. elseif key == keys.four then
  241. recoveryShell()
  242. elseif key == keys.five then
  243. term.clear()
  244. term.setCursorPos(1,1)
  245. print("Doggy OS is restarting...")
  246. sleep(2)
  247. os.reboot()
  248. end
  249. end
  250.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement