Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to set text color
- function setTextColor(color)
- term.setTextColor(color)
- end
- -- Function to reset text color to white
- function resetTextColor()
- setTextColor(colors.white)
- end
- -- Function to clear the screen and display a title
- function clearScreen(title)
- term.clear()
- term.setCursorPos(1, 1)
- setTextColor(colors.yellow)
- print("=== " .. title .. " ===")
- resetTextColor()
- print()
- end
- -- Function to check if a disk is connected
- function checkDisk()
- if fs.exists("/disk") or fs.exists("/disk2/disk") then
- print("Disk detected.")
- return true
- else
- print("No disk detected.")
- return false
- end
- end
- -- Function to show the main recovery menu
- function recoveryMenu()
- clearScreen("Dogdroid System Recovery")
- print("1. Bootloader: Show bootloader menu")
- print("2. Recovery: Show recovery menu")
- print("3. Unmount: Delete Recovery.sys file and unmount the disk")
- local choice = read()
- if choice == "1" then
- bootloaderMenu()
- elseif choice == "2" then
- recoveryActions()
- elseif choice == "3" then
- unmountDisk()
- else
- print("Invalid option.")
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- end
- -- Function for bootloader menu
- function bootloaderMenu()
- clearScreen("Bootloader Menu")
- print("1. Unlock")
- print("2. Lock")
- local choice = read()
- if choice == "1" then
- unlockBootloader()
- elseif choice == "2" then
- lockBootloader()
- else
- print("Invalid option.")
- os.sleep(2) -- Wait before returning to the menu
- bootloaderMenu()
- end
- end
- -- Function to unlock bootloader
- function unlockBootloader()
- local filePath = "/disk/BL-unlocked"
- local file = fs.open(filePath, "w")
- file.write("D0GGY1234OS5678TOKEN")
- file.close()
- print("Bootloader unlocked.")
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- -- Function to lock bootloader
- function lockBootloader()
- local filePath = "/disk/BL-unlocked"
- if fs.exists(filePath) then
- fs.delete(filePath)
- print("Bootloader locked.")
- else
- print("Bootloader is already locked.")
- end
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- -- Function for recovery actions
- function recoveryActions()
- clearScreen("Recovery Menu")
- print("1. Repair")
- print("2. Backup")
- print("3. Uninstall")
- local choice = read()
- if choice == "1" then
- repairDisk()
- elseif choice == "2" then
- backupDisk()
- elseif choice == "3" then
- uninstallDisk()
- else
- print("Invalid option.")
- os.sleep(2) -- Wait before returning to the menu
- recoveryActions()
- end
- end
- -- Function to repair the disk
- function repairDisk()
- local diskPath = fs.exists("/disk/disk") and "/disk/disk" or "/disk2/disk"
- if fs.exists(diskPath) then
- fs.delete(diskPath)
- fs.copy("/DGYDROID/", diskPath)
- print("Disk repaired.")
- else
- print("No disk to repair.")
- end
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- -- Function to backup the disk
- function backupDisk()
- local diskPath = fs.exists("/disk/disk") and "/disk/disk" or "/disk2/disk"
- if fs.exists(diskPath) then
- local backupDir = "/DGYDROID-backup" .. math.random(10000, 99999)
- fs.copy(diskPath, backupDir)
- print("Backup created at " .. backupDir)
- else
- print("No disk to backup.")
- end
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- -- Function to uninstall the disk
- function uninstallDisk()
- local diskPath = fs.exists("/disk/disk") and "/disk/disk" or "/disk2/disk"
- if fs.exists(diskPath) then
- fs.delete(diskPath .. "/*")
- print("All files deleted from the disk.")
- else
- print("No disk to uninstall.")
- end
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- -- Function to unmount the disk
- function unmountDisk()
- local recoveryFilePath = "/disk/Recovery.sys"
- if fs.exists(recoveryFilePath) then
- fs.delete(recoveryFilePath)
- print("Recovery.sys deleted. Device unmounted.")
- else
- print("No Recovery.sys file found.")
- end
- os.sleep(2) -- Wait before returning to the menu
- recoveryMenu()
- end
- -- Main execution flow
- if checkDisk() then
- if fs.exists("/disk/Recovery.sys") or fs.exists("/disk2/disk/Recovery.sys") then
- recoveryMenu()
- else
- print("No Recovery.sys file found on the disk.")
- end
- else
- print("Please connect a disk.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement