Advertisement
DOGGYWOOF

DOGDROID recovery

Apr 5th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. -- Function to clear the screen and set cursor position
  2. local function clearScreen()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. end
  6.  
  7. -- Function to display the main menu
  8. function mainMenu()
  9. clearScreen()
  10. print("Main Menu")
  11. if fs.exists("/disk2/recovery.cfg") then
  12. print("Insert Doggy OS device")
  13. print("Detected Device")
  14. local file = fs.open("/disk2/recovery.cfg", "r")
  15. local contents = file.readAll()
  16. file.close()
  17. print(contents)
  18. recoverySubMenu()
  19. else
  20. print("Device not detected. Looking...")
  21. os.sleep(5) -- Adjust sleep time as needed
  22. mainMenu()
  23. end
  24. end
  25.  
  26. -- Function to display the recovery submenu
  27. function recoverySubMenu()
  28. clearScreen()
  29. print("Recovery Submenu")
  30. print("1. Security")
  31. print("2. Operating System")
  32. print("3. Firmware")
  33. print("4. Unmount Device")
  34. print("5. Back to Main Menu")
  35.  
  36. local choice = read()
  37.  
  38. if choice == "1" then
  39. securitySubMenu()
  40. elseif choice == "2" then
  41. operatingSystemSubMenu()
  42. elseif choice == "3" then
  43. firmwareSubMenu()
  44. elseif choice == "4" then
  45. unmountDevice()
  46. elseif choice == "5" then
  47. mainMenu()
  48. else
  49. print("Invalid choice")
  50. recoverySubMenu()
  51. end
  52. end
  53.  
  54. -- Function to display the security submenu
  55. function securitySubMenu()
  56. clearScreen()
  57. print("Security Submenu")
  58. print("1. Reset PIN")
  59. print("2. Set Default PIN")
  60. print("3. Secure Lock")
  61. print("4. Back to Recovery Submenu")
  62. local choice = read()
  63.  
  64. if choice == "1" then
  65. resetPIN()
  66. elseif choice == "2" then
  67. setDefaultPIN()
  68. elseif choice == "3" then
  69. secureLock()
  70. elseif choice == "4" then
  71. recoverySubMenu()
  72. else
  73. print("Invalid choice")
  74. securitySubMenu()
  75. end
  76. end
  77.  
  78. -- Function to reset PIN
  79. function resetPIN()
  80. clearScreen()
  81. print("Enter new PIN:")
  82. local newPIN = read("*")
  83. local file = fs.open("/disk2/security/PIN.config", "w")
  84. file.write(newPIN)
  85. file.close()
  86. print("PIN reset successfully.")
  87. securitySubMenu()
  88. end
  89.  
  90. -- Function to set default PIN
  91. function setDefaultPIN()
  92. clearScreen()
  93. fs.delete("/disk2/security/PIN.config")
  94. print("Default PIN set.")
  95. securitySubMenu()
  96. end
  97.  
  98. -- Function to lock the device
  99. function secureLock()
  100. clearScreen()
  101. local file = fs.open("/disk2/startup", "w")
  102. file.write("Device Locked to OEM")
  103. file.close()
  104. print("Device locked to OEM.")
  105. securitySubMenu()
  106. end
  107.  
  108. -- Function to display the operating system submenu
  109. function operatingSystemSubMenu()
  110. clearScreen()
  111. print("Operating System Submenu")
  112. print("1. Uninstall")
  113. print("2. Reinstall")
  114. print("3. Back to Recovery Submenu")
  115. local choice = read()
  116.  
  117. if choice == "1" then
  118. uninstallOS()
  119. elseif choice == "2" then
  120. reinstallOS()
  121. elseif choice == "3" then
  122. recoverySubMenu()
  123. else
  124. print("Invalid choice")
  125. operatingSystemSubMenu()
  126. end
  127. end
  128.  
  129. -- Function to uninstall the operating system
  130. function uninstallOS()
  131. clearScreen()
  132. fs.delete("/disk2/disk")
  133. fs.delete("/disk2/startup")
  134. fs.delete("/disk2/no-os")
  135. print("Operating system uninstalled.")
  136. operatingSystemSubMenu()
  137. end
  138.  
  139. -- Function to reinstall the operating system
  140. function reinstallOS()
  141. clearScreen()
  142. print("Waiting for /disk3/...")
  143. while not fs.exists("/disk3/") do
  144. os.sleep(1)
  145. end
  146. fs.delete("/disk2/disk")
  147. fs.delete("/disk2/startup")
  148. fs.delete("/disk2/no-os")
  149. fs.copy("/disk3/", "/disk2/")
  150. print("Operating system reinstalled.")
  151. print("Enter device PIN:")
  152. local pin = read("*")
  153. local file = fs.open("/disk2/security/PIN.config", "w")
  154. file.write(pin)
  155. file.close()
  156. print("PIN saved.")
  157. operatingSystemSubMenu()
  158. end
  159.  
  160. -- Function to display the firmware submenu
  161. function firmwareSubMenu()
  162. clearScreen()
  163. print("Firmware Submenu")
  164. print("1. Reinstall Bootloader")
  165. print("2. Install Custom Bootloader")
  166. print("3. Back to Recovery Submenu")
  167. local choice = read()
  168.  
  169. if choice == "1" then
  170. reinstallBootloader()
  171. elseif choice == "2" then
  172. installCustomBootloader()
  173. elseif choice == "3" then
  174. recoverySubMenu()
  175. else
  176. print("Invalid choice")
  177. firmwareSubMenu()
  178. end
  179. end
  180.  
  181. -- Function to reinstall the bootloader
  182. function reinstallBootloader()
  183. clearScreen()
  184. print("Waiting for /disk3/boot/error...")
  185. while not fs.exists("/disk3/boot/error") do
  186. os.sleep(1)
  187. end
  188. fs.delete("/disk2/startup") -- Delete existing startup file
  189. fs.copy("/disk3/boot/error", "/disk2/startup")
  190. fs.copy("/disk3/boot/error", "/disk2/boot/error")
  191. print("Bootloader reinstalled.")
  192. firmwareSubMenu()
  193. end
  194.  
  195. -- Function to install a custom bootloader
  196. function installCustomBootloader()
  197. clearScreen()
  198. fs.delete("/disk2/startup") -- Delete existing startup file
  199. print("Enter the path to the custom bootloader:")
  200. local bootloaderPath = read()
  201. fs.copy(bootloaderPath, "/disk2/startup")
  202. print("Custom bootloader installed.")
  203. firmwareSubMenu()
  204. end
  205.  
  206. -- Function to unmount the device and run the GUI
  207. function unmountDevice()
  208. clearScreen()
  209. fs.delete("/disk2/recovery.cfg")
  210. print("Device unmounted.")
  211. print("Waiting for /disk2/ to disappear...")
  212. while fs.exists("/disk2/") do
  213. os.sleep(1)
  214. end
  215. print("/disk2/ has disappeared.")
  216.  
  217. -- Run the GUI
  218. shell.run("/disk/os/gui")
  219. end
  220.  
  221. -- Start the program
  222. mainMenu()
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement