Advertisement
DOGGYWOOF

Untitled

Dec 18th, 2024 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. -- Doggy OS Recovery
  2.  
  3. local function clearScreen()
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. end
  7.  
  8. local function drawBorder()
  9. term.setCursorPos(1, 1)
  10. term.write(string.rep("=", term.getSize()))
  11. term.setCursorPos(1, select(2, term.getSize()))
  12. term.write(string.rep("=", term.getSize()))
  13. end
  14.  
  15. local function displayMenu(title, options)
  16. clearScreen()
  17. drawBorder()
  18. term.setCursorPos(1, 2)
  19. print(string.rep(" ", math.floor((term.getSize() - #title) / 2)) .. title)
  20. print()
  21. for i, option in ipairs(options) do
  22. print(" " .. i .. ". " .. option)
  23. end
  24. print()
  25. print("Enter your choice:")
  26. end
  27.  
  28. local function backupUsersFolder()
  29. if fs.exists("/disk/users/") then
  30. shell.run("delete /backup_users")
  31. shell.run("copy /disk/users /backup_users")
  32. print("Users folder backed up.")
  33. end
  34. end
  35.  
  36. local function restoreUsersFolder()
  37. if fs.exists("/backup_users/") then
  38. shell.run("delete /disk/users")
  39. shell.run("copy /backup_users /disk/users")
  40. shell.run("delete /backup_users")
  41. print("Users folder restored.")
  42. end
  43. end
  44.  
  45. local function fullSystemRecovery()
  46. clearScreen()
  47. backupUsersFolder()
  48. shell.run("delete /disk")
  49. shell.run("copy /recovery /disk")
  50. restoreUsersFolder()
  51. print("Full System Recovery completed.")
  52. sleep(2)
  53. end
  54.  
  55. local function refreshRecoveryPartition()
  56. clearScreen()
  57. print("Please insert Doggy OS disk!")
  58.  
  59. while not fs.exists("/disk2/") do
  60. sleep(1)
  61. end
  62.  
  63. shell.run("delete /recovery")
  64. shell.run("copy /disk2 /recovery")
  65. print("Recovery partition refreshed.")
  66. sleep(2)
  67. end
  68.  
  69. local function installUpdateFromDisk()
  70. clearScreen()
  71. print("Please insert Doggy OS disk!")
  72.  
  73. while not fs.exists("/disk2/") do
  74. sleep(1)
  75. end
  76.  
  77. backupUsersFolder()
  78. shell.run("delete /disk")
  79. shell.run("copy /disk2 /disk")
  80. restoreUsersFolder()
  81. print("Update installed from disk.")
  82. sleep(2)
  83. end
  84.  
  85. local function overrideBootloader()
  86. clearScreen()
  87. print("Override Bootloader:")
  88. print("Enter the location of the OS kernel:")
  89.  
  90. local kernelLocation = io.read()
  91.  
  92. if fs.exists(kernelLocation) then
  93. shell.run("delete /startup")
  94. shell.run("copy " .. kernelLocation .. " /startup")
  95. print("Bootloader overridden successfully.")
  96. else
  97. print("Error: Specified file not found.")
  98. end
  99.  
  100. sleep(2)
  101. end
  102.  
  103. -- Main loop
  104. while true do
  105. displayMenu("Doggy OS Emergency System Recovery GUI", {"Recovery Options", "Power Options"})
  106.  
  107. local choice = tonumber(io.read())
  108.  
  109. if choice == 1 then
  110. while true do
  111. displayMenu("Recovery Options", {"Full System Recovery", "Refresh Recovery Partition", "Install Update from Disk", "Override Bootloader", "Back"})
  112.  
  113. local recoveryChoice = tonumber(io.read())
  114.  
  115. if recoveryChoice == 1 then
  116. fullSystemRecovery()
  117. elseif recoveryChoice == 2 then
  118. refreshRecoveryPartition()
  119. elseif recoveryChoice == 3 then
  120. installUpdateFromDisk()
  121. elseif recoveryChoice == 4 then
  122. overrideBootloader()
  123. elseif recoveryChoice == 5 then
  124. break
  125. else
  126. print("Invalid choice.")
  127. sleep(2)
  128. end
  129. end
  130. elseif choice == 2 then
  131. displayMenu("Power Options", {"Reboot system", "Shutdown system"})
  132.  
  133. local powerChoice = tonumber(io.read())
  134.  
  135. if powerChoice == 1 then
  136. os.reboot()
  137. elseif powerChoice == 2 then
  138. os.shutdown()
  139. else
  140. print("Invalid choice.")
  141. sleep(2)
  142. end
  143. else
  144. print("Invalid choice. Please try again.")
  145. sleep(2)
  146. end
  147. end
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement