Advertisement
DOGGYWOOF

System repair and install

Sep 17th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. function main()
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. print("===================================")
  7. print(" Doggy OS Installation Media")
  8. print("===================================")
  9. print("OS VERSION: Doggy OS 13.0")
  10. print("UEFI: N3K0 UEFI")
  11. print("BOOTLOADER: VA11-ILLA 12.0")
  12. print("")
  13. print("Choose an option:")
  14. print("I: Install OS")
  15. print("R: Repair OS")
  16. print("C: Cancel")
  17. print("===================================")
  18. local user_input = read()
  19.  
  20. if user_input:lower() == 'i' then
  21. confirmInstall()
  22. elseif user_input:lower() == 'r' then
  23. repairMenu()
  24. elseif user_input:lower() == 'c' then
  25. cancelInstall()
  26. else
  27. shell.run("/disk/startup")
  28. main()
  29. end
  30. end
  31.  
  32. function confirmInstall()
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. print("===================================")
  36. print(" Confirm Install")
  37. print("===================================")
  38. print("Y: Install OS")
  39. print("N: Cancel Install")
  40. print("===================================")
  41. local user_input = read()
  42. if user_input:lower() == 'y' then
  43. runInstallProgram()
  44. elseif user_input:lower() == 'n' then
  45. cancelInstall()
  46. else
  47. main()
  48. end
  49. end
  50.  
  51. function runInstallProgram()
  52. shell.run("/disk/install") -- Replace with actual install program
  53. end
  54.  
  55. function cancelInstall()
  56. term.clear()
  57. term.setCursorPos(1,1)
  58. print("===================================")
  59. print(" Doggy OS Installation Media")
  60. print("===================================")
  61. print("The Installation Was Cancelled!")
  62. print("")
  63. print("Shutting Down...")
  64. sleep(4)
  65. os.shutdown()
  66. end
  67.  
  68. function repairMenu()
  69. term.clear()
  70. term.setCursorPos(1,1)
  71. print("===================================")
  72. print(" Doggy OS Repair Menu")
  73. print("===================================")
  74. print("1: Repair Bootloader")
  75. print("2: Repair System Software")
  76. print("B: Back to Main Menu")
  77. print("===================================")
  78. local user_input = read()
  79.  
  80. if user_input == '1' then
  81. runBootloaderRepair()
  82. elseif user_input == '2' then
  83. runSystemRepair()
  84. elseif user_input:lower() == 'b' then
  85. main()
  86. else
  87. repairMenu()
  88. end
  89. end
  90.  
  91. function runBootloaderRepair()
  92. -- Bootloader repair code
  93. term.clear()
  94. term.setBackgroundColor(colors.black)
  95. term.setTextColor(colors.white)
  96. term.clear()
  97. local width, height = term.getSize()
  98.  
  99. local function centerText(y, text)
  100. local x = math.floor((width - #text) / 2)
  101. term.setCursorPos(x, y)
  102. term.write(text)
  103. end
  104.  
  105. local dogArt = {
  106. " |\\_/| ",
  107. " | @ @ ",
  108. " | <> _ ",
  109. " | _/\\------____ ((| |))",
  110. " | `--' | ",
  111. " _____|_ ___| |___. ",
  112. "/_/_____/____/_______| "
  113. }
  114.  
  115. local startLine = math.floor((height - #dogArt) / 2) - 2
  116. for i, line in ipairs(dogArt) do
  117. centerText(startLine + i, line)
  118. end
  119.  
  120. centerText(startLine + #dogArt + 2, "Repairing System Bootloader...")
  121. sleep(10)
  122.  
  123. fs.delete("/startup")
  124. fs.delete("/no-os")
  125. fs.copy("/recovery/boot/error", "/startup")
  126. fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
  127.  
  128. centerText(startLine + #dogArt + 4, "Repair Completed. Rebooting...")
  129. sleep(3)
  130. os.reboot()
  131. end
  132.  
  133. function runSystemRepair()
  134. -- System software repair code
  135. local diskPath = "/disk/"
  136. local recoveryPath = "/recovery/"
  137. local noOsPath = "/no-os"
  138.  
  139. local function directoryExists(path)
  140. return fs.exists(path) and fs.isDir(path)
  141. end
  142.  
  143. local function copyDirectoryContents(source, destination)
  144. if not directoryExists(source) then return false end
  145. if directoryExists(destination) then fs.delete(destination) end
  146. fs.copy(source, destination)
  147. return true
  148. end
  149.  
  150. local function displayScrollingMessage(message)
  151. term.clear()
  152. term.setCursorPos(1, 1)
  153. print("Doggy OS Automatic Repair on Startup Failure")
  154. print("-------------------------------------------\n")
  155.  
  156. local lines = {}
  157. for line in message:gmatch("[^\r\n]+") do table.insert(lines, line) end
  158.  
  159. local maxLines = 10
  160. local startLine = 1
  161. while startLine <= #lines do
  162. term.clear()
  163. term.setCursorPos(1, 1)
  164. print("Doggy OS Automatic Repair on Startup Failure")
  165. print("-------------------------------------------\n")
  166. for i = startLine, math.min(#lines, startLine + maxLines - 1) do
  167. print(lines[i])
  168. end
  169. if startLine + maxLines <= #lines then
  170. print("\nPress any key to scroll down...")
  171. os.pullEvent("key")
  172. else
  173. print("\nPress any key to continue...")
  174. os.pullEvent("key")
  175. break
  176. end
  177. startLine = startLine + maxLines
  178. end
  179. end
  180.  
  181. local function displayErrorMessage(errorType)
  182. local errorMessage
  183. if errorType == "OSDirectoryMissing" then
  184. errorMessage = "Issue: OS Directory Missing"
  185. elseif errorType == "RestoreFailure" then
  186. errorMessage = "Failed to restore from /recovery/."
  187. elseif errorType == "CreationFailure" then
  188. errorMessage = "Failed to create /disk/ from /recovery/."
  189. else
  190. errorMessage = "Unknown error."
  191. end
  192. displayScrollingMessage(errorMessage)
  193. shell.run(noOsPath)
  194. end
  195.  
  196. if not directoryExists(recoveryPath) then
  197. shell.run(noOsPath)
  198. return
  199. end
  200.  
  201. displayScrollingMessage("Repairing system software...")
  202. if directoryExists(diskPath) then
  203. local success = copyDirectoryContents(recoveryPath, diskPath)
  204. if success then
  205. displayScrollingMessage("Repair successful!")
  206. os.reboot()
  207. else
  208. displayErrorMessage("RestoreFailure")
  209. end
  210. else
  211. local success = copyDirectoryContents(recoveryPath, diskPath)
  212. if success then
  213. displayScrollingMessage("Repair successful!")
  214. os.reboot()
  215. else
  216. displayErrorMessage("CreationFailure")
  217. end
  218. end
  219. end
  220.  
  221. main()
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement