Advertisement
DOGGYWOOF

Doggy OS Turtle System Update

Dec 31st, 2024 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. -- Doggy OS System Update Script with Improved UI and Specific File Deletion for Uninstall and Reset
  2.  
  3. -- Function to draw a custom confirmation screen
  4. local function drawConfirmationScreen(title, message, yesCallback, noCallback)
  5. term.clear()
  6. term.setCursorPos(1, 1)
  7. term.setTextColor(colors.yellow)
  8. print(title)
  9. term.setTextColor(colors.white)
  10.  
  11. -- Draw the confirmation message
  12. print("\n" .. message)
  13. print("\n[YES] - Confirm [NO] - Cancel")
  14.  
  15. -- Wait for user input
  16. local response = read()
  17. if response:lower() == "yes" then
  18. yesCallback()
  19. else
  20. noCallback()
  21. end
  22. end
  23.  
  24. -- Function to draw the loading screen with progress bar
  25. local function drawLoadingScreen(progress, total, title, label)
  26. local barLength = 30
  27. local filledLength = math.floor((progress / total) * barLength)
  28. local emptyLength = barLength - filledLength
  29. local bar = "[" .. string.rep("=", filledLength) .. string.rep(" ", emptyLength) .. "]"
  30.  
  31. -- Clear the screen and display the loading screen
  32. term.clear()
  33. term.setCursorPos(1, 1)
  34. term.setTextColor(colors.yellow)
  35. print(title)
  36. term.setTextColor(colors.white)
  37. print(label)
  38. term.setCursorPos(1, 3)
  39. print("Progress:")
  40. term.setCursorPos(1, 4)
  41. term.clearLine()
  42. term.write(bar)
  43. term.setCursorPos(1, 5)
  44. term.clearLine()
  45. term.write(label .. " (" .. progress .. "/" .. total .. ")")
  46. end
  47.  
  48. -- Function to download a file from Pastebin
  49. local function downloadFromPastebin(pastebinURL, savePath)
  50. local response = http.get(pastebinURL)
  51. if response then
  52. local data = response.readAll()
  53. local file = fs.open(savePath, "w")
  54. file.write(data)
  55. file.close()
  56. return true
  57. else
  58. return false
  59. end
  60. end
  61.  
  62. -- Function to update the system
  63. local function updateSystem()
  64. local totalSteps = 4
  65. local currentStep = 0
  66. local title = "DOGGY OS SYSTEM UPDATE"
  67.  
  68. -- Show confirmation screen
  69. drawConfirmationScreen("System Update Confirmation",
  70. "This will delete the following files and update the system:\n/startup\n/reboot\nDo you wish to proceed?",
  71. function() -- If user clicks YES
  72. -- Start the update process
  73. drawLoadingScreen(currentStep, totalSteps, title, "Initializing Update...")
  74. sleep(1)
  75.  
  76. local filesToDelete = {"/startup", "/reboot"}
  77.  
  78. -- Delete files during the update process and show progress
  79. for _, file in ipairs(filesToDelete) do
  80. if fs.exists(file) then
  81. fs.delete(file)
  82. end
  83. currentStep = currentStep + 1
  84. drawLoadingScreen(currentStep, totalSteps, title, "Deleting Files...")
  85. sleep(1)
  86. end
  87.  
  88. -- Download the new startup and reboot files from Pastebin
  89. local pastebinURL = "https://pastebin.com/raw/9ahPi497"
  90. if downloadFromPastebin(pastebinURL, "/startup") then
  91. currentStep = currentStep + 1
  92. drawLoadingScreen(currentStep, totalSteps, title, "Downloading Startup File...")
  93. sleep(1)
  94. else
  95. print("Failed to download the new startup file.")
  96. return
  97. end
  98.  
  99. if downloadFromPastebin(pastebinURL, "/reboot") then
  100. currentStep = currentStep + 1
  101. drawLoadingScreen(currentStep, totalSteps, title, "Downloading Reboot File...")
  102. sleep(1)
  103. else
  104. print("Failed to download the new reboot file.")
  105. return
  106. end
  107.  
  108. -- Final step: Reboot the system
  109. drawLoadingScreen(totalSteps, totalSteps, title, "Update Complete! Rebooting...")
  110. sleep(2)
  111. os.reboot()
  112. end,
  113. function() -- If user clicks NO
  114. print("Update canceled.")
  115. end)
  116. end
  117.  
  118. -- Function to perform a factory reset
  119. local function factoryReset()
  120. drawConfirmationScreen("Factory Reset Warning",
  121. "This will delete the following files:\n/startup\n/reboot\nturtle_gps_data.json\nturtle_settings.json\nDo you wish to proceed?",
  122. function() -- If user clicks YES
  123. -- Perform the reset by deleting specific files
  124. local filesToDelete = {"/startup", "/reboot", "/turtle_gps_data.json", "/turtle_settings.json"}
  125. for _, file in ipairs(filesToDelete) do
  126. if fs.exists(file) then
  127. fs.delete(file)
  128. end
  129. end
  130.  
  131. -- After reset, run the system update
  132. print("Factory reset complete. Running system update...")
  133. updateSystem()
  134. end,
  135. function() -- If user clicks NO
  136. print("Factory reset canceled.")
  137. end)
  138. end
  139.  
  140. -- Function to uninstall the system
  141. local function uninstallSystem()
  142. drawConfirmationScreen("System Uninstall Warning",
  143. "This will delete the following files:\n/startup\n/reboot\nturtle_gps_data.json\nturtle_settings.json\nDo you wish to proceed?",
  144. function() -- If user clicks YES
  145. -- Perform the uninstall by deleting specific files
  146. local filesToDelete = {"/startup", "/reboot", "/turtle_gps_data.json", "/turtle_settings.json"}
  147. for _, file in ipairs(filesToDelete) do
  148. fs.delete(file)
  149. end
  150.  
  151. -- Reboot after uninstallation
  152. print("System uninstalled. Rebooting...")
  153. os.reboot()
  154. end,
  155. function() -- If user clicks NO
  156. print("Uninstall canceled.")
  157. end)
  158. end
  159.  
  160. -- Function to display the main menu with options
  161. local function displayMainMenu()
  162. term.clear()
  163. term.setCursorPos(1, 1)
  164. term.setTextColor(colors.yellow)
  165. print("DOGGY OS SYSTEM UPDATE MENU")
  166. term.setTextColor(colors.white)
  167.  
  168. -- Display options for Factory Reset and System Uninstall
  169. print("\n1. System Update")
  170. print("2. Factory Reset")
  171. print("3. Uninstall System")
  172. print("\nChoose an option:")
  173.  
  174. local option = tonumber(read())
  175.  
  176. if option == 1 then
  177. updateSystem()
  178. elseif option == 2 then
  179. factoryReset()
  180. elseif option == 3 then
  181. uninstallSystem()
  182. else
  183. print("Invalid option. Please choose again.")
  184. displayMainMenu()
  185. end
  186. end
  187.  
  188. -- Run the main menu
  189. displayMainMenu()
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement