Advertisement
DOGGYWOOF

Doggy OS Pocket external recovery

Oct 1st, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. -- Function to set text color
  2. function setTextColor(color)
  3. term.setTextColor(color)
  4. end
  5.  
  6. -- Function to reset text color to white
  7. function resetTextColor()
  8. setTextColor(colors.white)
  9. end
  10.  
  11. -- Function to clear the screen and display a title
  12. function clearScreen(title)
  13. term.clear()
  14. term.setCursorPos(1, 1)
  15. setTextColor(colors.yellow)
  16. print("=== " .. title .. " ===")
  17. resetTextColor()
  18. print()
  19. end
  20.  
  21. -- Function to check if a disk is connected
  22. function checkDisk()
  23. if fs.exists("/disk") or fs.exists("/disk2/disk") then
  24. print("Disk detected.")
  25. return true
  26. else
  27. print("No disk detected.")
  28. return false
  29. end
  30. end
  31.  
  32. -- Function to show the main recovery menu
  33. function recoveryMenu()
  34. clearScreen("Dogdroid System Recovery")
  35. print("1. Bootloader: Show bootloader menu")
  36. print("2. Recovery: Show recovery menu")
  37. print("3. Unmount: Delete Recovery.sys file and unmount the disk")
  38.  
  39. local choice = read()
  40.  
  41. if choice == "1" then
  42. bootloaderMenu()
  43. elseif choice == "2" then
  44. recoveryActions()
  45. elseif choice == "3" then
  46. unmountDisk()
  47. else
  48. print("Invalid option.")
  49. os.sleep(2) -- Wait before returning to the menu
  50. recoveryMenu()
  51. end
  52. end
  53.  
  54. -- Function for bootloader menu
  55. function bootloaderMenu()
  56. clearScreen("Bootloader Menu")
  57. print("1. Unlock")
  58. print("2. Lock")
  59.  
  60. local choice = read()
  61.  
  62. if choice == "1" then
  63. unlockBootloader()
  64. elseif choice == "2" then
  65. lockBootloader()
  66. else
  67. print("Invalid option.")
  68. os.sleep(2) -- Wait before returning to the menu
  69. bootloaderMenu()
  70. end
  71. end
  72.  
  73. -- Function to unlock bootloader
  74. function unlockBootloader()
  75. local filePath = "/disk/BL-unlocked"
  76. local file = fs.open(filePath, "w")
  77. file.write("D0GGY1234OS5678TOKEN")
  78. file.close()
  79. print("Bootloader unlocked.")
  80. os.sleep(2) -- Wait before returning to the menu
  81. recoveryMenu()
  82. end
  83.  
  84. -- Function to lock bootloader
  85. function lockBootloader()
  86. local filePath = "/disk/BL-unlocked"
  87. if fs.exists(filePath) then
  88. fs.delete(filePath)
  89. print("Bootloader locked.")
  90. else
  91. print("Bootloader is already locked.")
  92. end
  93. os.sleep(2) -- Wait before returning to the menu
  94. recoveryMenu()
  95. end
  96.  
  97. -- Function for recovery actions
  98. function recoveryActions()
  99. clearScreen("Recovery Menu")
  100. print("1. Repair")
  101. print("2. Backup")
  102. print("3. Uninstall")
  103.  
  104. local choice = read()
  105.  
  106. if choice == "1" then
  107. repairDisk()
  108. elseif choice == "2" then
  109. backupDisk()
  110. elseif choice == "3" then
  111. uninstallDisk()
  112. else
  113. print("Invalid option.")
  114. os.sleep(2) -- Wait before returning to the menu
  115. recoveryActions()
  116. end
  117. end
  118.  
  119. -- Function to repair the disk
  120. function repairDisk()
  121. local diskPath = fs.exists("/disk/disk") and "/disk/disk" or "/disk2/disk"
  122. if fs.exists(diskPath) then
  123. fs.delete(diskPath)
  124. fs.copy("/DGYDROID/", diskPath)
  125. print("Disk repaired.")
  126. else
  127. print("No disk to repair.")
  128. end
  129. os.sleep(2) -- Wait before returning to the menu
  130. recoveryMenu()
  131. end
  132.  
  133. -- Function to backup the disk
  134. function backupDisk()
  135. local diskPath = fs.exists("/disk/disk") and "/disk/disk" or "/disk2/disk"
  136. if fs.exists(diskPath) then
  137. local backupDir = "/DGYDROID-backup" .. math.random(10000, 99999)
  138. fs.copy(diskPath, backupDir)
  139. print("Backup created at " .. backupDir)
  140. else
  141. print("No disk to backup.")
  142. end
  143. os.sleep(2) -- Wait before returning to the menu
  144. recoveryMenu()
  145. end
  146.  
  147. -- Function to uninstall the disk
  148. function uninstallDisk()
  149. local diskPath = fs.exists("/disk/disk") and "/disk/disk" or "/disk2/disk"
  150. if fs.exists(diskPath) then
  151. fs.delete(diskPath .. "/*")
  152. print("All files deleted from the disk.")
  153. else
  154. print("No disk to uninstall.")
  155. end
  156. os.sleep(2) -- Wait before returning to the menu
  157. recoveryMenu()
  158. end
  159.  
  160. -- Function to unmount the disk
  161. function unmountDisk()
  162. local recoveryFilePath = "/disk/Recovery.sys"
  163. if fs.exists(recoveryFilePath) then
  164. fs.delete(recoveryFilePath)
  165. print("Recovery.sys deleted. Device unmounted.")
  166. else
  167. print("No Recovery.sys file found.")
  168. end
  169. os.sleep(2) -- Wait before returning to the menu
  170. recoveryMenu()
  171. end
  172.  
  173. -- Main execution flow
  174. if checkDisk() then
  175. if fs.exists("/disk/Recovery.sys") or fs.exists("/disk2/disk/Recovery.sys") then
  176. recoveryMenu()
  177. else
  178. print("No Recovery.sys file found on the disk.")
  179. end
  180. else
  181. print("Please connect a disk.")
  182. end
  183.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement