Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS System Update Script with Improved UI and Specific File Deletion for Uninstall and Reset
- -- Function to draw a custom confirmation screen
- local function drawConfirmationScreen(title, message, yesCallback, noCallback)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.yellow)
- print(title)
- term.setTextColor(colors.white)
- -- Draw the confirmation message
- print("\n" .. message)
- print("\n[YES] - Confirm [NO] - Cancel")
- -- Wait for user input
- local response = read()
- if response:lower() == "yes" then
- yesCallback()
- else
- noCallback()
- end
- end
- -- Function to draw the loading screen with progress bar
- local function drawLoadingScreen(progress, total, title, label)
- local barLength = 30
- local filledLength = math.floor((progress / total) * barLength)
- local emptyLength = barLength - filledLength
- local bar = "[" .. string.rep("=", filledLength) .. string.rep(" ", emptyLength) .. "]"
- -- Clear the screen and display the loading screen
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.yellow)
- print(title)
- term.setTextColor(colors.white)
- print(label)
- term.setCursorPos(1, 3)
- print("Progress:")
- term.setCursorPos(1, 4)
- term.clearLine()
- term.write(bar)
- term.setCursorPos(1, 5)
- term.clearLine()
- term.write(label .. " (" .. progress .. "/" .. total .. ")")
- end
- -- Function to download a file from Pastebin
- local function downloadFromPastebin(pastebinURL, savePath)
- local response = http.get(pastebinURL)
- if response then
- local data = response.readAll()
- local file = fs.open(savePath, "w")
- file.write(data)
- file.close()
- return true
- else
- return false
- end
- end
- -- Function to update the system
- local function updateSystem()
- local totalSteps = 4
- local currentStep = 0
- local title = "DOGGY OS SYSTEM UPDATE"
- -- Show confirmation screen
- drawConfirmationScreen("System Update Confirmation",
- "This will delete the following files and update the system:\n/startup\n/reboot\nDo you wish to proceed?",
- function() -- If user clicks YES
- -- Start the update process
- drawLoadingScreen(currentStep, totalSteps, title, "Initializing Update...")
- sleep(1)
- local filesToDelete = {"/startup", "/reboot"}
- -- Delete files during the update process and show progress
- for _, file in ipairs(filesToDelete) do
- if fs.exists(file) then
- fs.delete(file)
- end
- currentStep = currentStep + 1
- drawLoadingScreen(currentStep, totalSteps, title, "Deleting Files...")
- sleep(1)
- end
- -- Download the new startup and reboot files from Pastebin
- local pastebinURL = "https://pastebin.com/raw/9ahPi497"
- if downloadFromPastebin(pastebinURL, "/startup") then
- currentStep = currentStep + 1
- drawLoadingScreen(currentStep, totalSteps, title, "Downloading Startup File...")
- sleep(1)
- else
- print("Failed to download the new startup file.")
- return
- end
- if downloadFromPastebin(pastebinURL, "/reboot") then
- currentStep = currentStep + 1
- drawLoadingScreen(currentStep, totalSteps, title, "Downloading Reboot File...")
- sleep(1)
- else
- print("Failed to download the new reboot file.")
- return
- end
- -- Final step: Reboot the system
- drawLoadingScreen(totalSteps, totalSteps, title, "Update Complete! Rebooting...")
- sleep(2)
- os.reboot()
- end,
- function() -- If user clicks NO
- print("Update canceled.")
- end)
- end
- -- Function to perform a factory reset
- local function factoryReset()
- drawConfirmationScreen("Factory Reset Warning",
- "This will delete the following files:\n/startup\n/reboot\nturtle_gps_data.json\nturtle_settings.json\nDo you wish to proceed?",
- function() -- If user clicks YES
- -- Perform the reset by deleting specific files
- local filesToDelete = {"/startup", "/reboot", "/turtle_gps_data.json", "/turtle_settings.json"}
- for _, file in ipairs(filesToDelete) do
- if fs.exists(file) then
- fs.delete(file)
- end
- end
- -- After reset, run the system update
- print("Factory reset complete. Running system update...")
- updateSystem()
- end,
- function() -- If user clicks NO
- print("Factory reset canceled.")
- end)
- end
- -- Function to uninstall the system
- local function uninstallSystem()
- drawConfirmationScreen("System Uninstall Warning",
- "This will delete the following files:\n/startup\n/reboot\nturtle_gps_data.json\nturtle_settings.json\nDo you wish to proceed?",
- function() -- If user clicks YES
- -- Perform the uninstall by deleting specific files
- local filesToDelete = {"/startup", "/reboot", "/turtle_gps_data.json", "/turtle_settings.json"}
- for _, file in ipairs(filesToDelete) do
- fs.delete(file)
- end
- -- Reboot after uninstallation
- print("System uninstalled. Rebooting...")
- os.reboot()
- end,
- function() -- If user clicks NO
- print("Uninstall canceled.")
- end)
- end
- -- Function to display the main menu with options
- local function displayMainMenu()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.yellow)
- print("DOGGY OS SYSTEM UPDATE MENU")
- term.setTextColor(colors.white)
- -- Display options for Factory Reset and System Uninstall
- print("\n1. System Update")
- print("2. Factory Reset")
- print("3. Uninstall System")
- print("\nChoose an option:")
- local option = tonumber(read())
- if option == 1 then
- updateSystem()
- elseif option == 2 then
- factoryReset()
- elseif option == 3 then
- uninstallSystem()
- else
- print("Invalid option. Please choose again.")
- displayMainMenu()
- end
- end
- -- Run the main menu
- displayMainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement