Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to clear the screen and set cursor position
- local function clearScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Function to display the main menu
- function mainMenu()
- clearScreen()
- print("Main Menu")
- if fs.exists("/disk2/recovery.cfg") then
- print("Insert Doggy OS device")
- print("Detected Device")
- local file = fs.open("/disk2/recovery.cfg", "r")
- local contents = file.readAll()
- file.close()
- print(contents)
- recoverySubMenu()
- else
- print("Device not detected. Looking...")
- os.sleep(5) -- Adjust sleep time as needed
- mainMenu()
- end
- end
- -- Function to display the recovery submenu
- function recoverySubMenu()
- clearScreen()
- print("Recovery Submenu")
- print("1. Security")
- print("2. Operating System")
- print("3. Firmware")
- print("4. Unmount Device")
- print("5. Back to Main Menu")
- local choice = read()
- if choice == "1" then
- securitySubMenu()
- elseif choice == "2" then
- operatingSystemSubMenu()
- elseif choice == "3" then
- firmwareSubMenu()
- elseif choice == "4" then
- unmountDevice()
- elseif choice == "5" then
- mainMenu()
- else
- print("Invalid choice")
- recoverySubMenu()
- end
- end
- -- Function to display the security submenu
- function securitySubMenu()
- clearScreen()
- print("Security Submenu")
- print("1. Reset PIN")
- print("2. Set Default PIN")
- print("3. Secure Lock")
- print("4. Back to Recovery Submenu")
- local choice = read()
- if choice == "1" then
- resetPIN()
- elseif choice == "2" then
- setDefaultPIN()
- elseif choice == "3" then
- secureLock()
- elseif choice == "4" then
- recoverySubMenu()
- else
- print("Invalid choice")
- securitySubMenu()
- end
- end
- -- Function to reset PIN
- function resetPIN()
- clearScreen()
- print("Enter new PIN:")
- local newPIN = read("*")
- local file = fs.open("/disk2/security/PIN.config", "w")
- file.write(newPIN)
- file.close()
- print("PIN reset successfully.")
- securitySubMenu()
- end
- -- Function to set default PIN
- function setDefaultPIN()
- clearScreen()
- fs.delete("/disk2/security/PIN.config")
- print("Default PIN set.")
- securitySubMenu()
- end
- -- Function to lock the device
- function secureLock()
- clearScreen()
- local file = fs.open("/disk2/startup", "w")
- file.write("Device Locked to OEM")
- file.close()
- print("Device locked to OEM.")
- securitySubMenu()
- end
- -- Function to display the operating system submenu
- function operatingSystemSubMenu()
- clearScreen()
- print("Operating System Submenu")
- print("1. Uninstall")
- print("2. Reinstall")
- print("3. Back to Recovery Submenu")
- local choice = read()
- if choice == "1" then
- uninstallOS()
- elseif choice == "2" then
- reinstallOS()
- elseif choice == "3" then
- recoverySubMenu()
- else
- print("Invalid choice")
- operatingSystemSubMenu()
- end
- end
- -- Function to uninstall the operating system
- function uninstallOS()
- clearScreen()
- fs.delete("/disk2/disk")
- fs.delete("/disk2/startup")
- fs.delete("/disk2/no-os")
- print("Operating system uninstalled.")
- operatingSystemSubMenu()
- end
- -- Function to reinstall the operating system
- function reinstallOS()
- clearScreen()
- print("Waiting for /disk3/...")
- while not fs.exists("/disk3/") do
- os.sleep(1)
- end
- fs.delete("/disk2/disk")
- fs.delete("/disk2/startup")
- fs.delete("/disk2/no-os")
- fs.copy("/disk3/", "/disk2/")
- print("Operating system reinstalled.")
- print("Enter device PIN:")
- local pin = read("*")
- local file = fs.open("/disk2/security/PIN.config", "w")
- file.write(pin)
- file.close()
- print("PIN saved.")
- operatingSystemSubMenu()
- end
- -- Function to display the firmware submenu
- function firmwareSubMenu()
- clearScreen()
- print("Firmware Submenu")
- print("1. Reinstall Bootloader")
- print("2. Install Custom Bootloader")
- print("3. Back to Recovery Submenu")
- local choice = read()
- if choice == "1" then
- reinstallBootloader()
- elseif choice == "2" then
- installCustomBootloader()
- elseif choice == "3" then
- recoverySubMenu()
- else
- print("Invalid choice")
- firmwareSubMenu()
- end
- end
- -- Function to reinstall the bootloader
- function reinstallBootloader()
- clearScreen()
- print("Waiting for /disk3/boot/error...")
- while not fs.exists("/disk3/boot/error") do
- os.sleep(1)
- end
- fs.delete("/disk2/startup") -- Delete existing startup file
- fs.copy("/disk3/boot/error", "/disk2/startup")
- fs.copy("/disk3/boot/error", "/disk2/boot/error")
- print("Bootloader reinstalled.")
- firmwareSubMenu()
- end
- -- Function to install a custom bootloader
- function installCustomBootloader()
- clearScreen()
- fs.delete("/disk2/startup") -- Delete existing startup file
- print("Enter the path to the custom bootloader:")
- local bootloaderPath = read()
- fs.copy(bootloaderPath, "/disk2/startup")
- print("Custom bootloader installed.")
- firmwareSubMenu()
- end
- -- Function to unmount the device and run the GUI
- function unmountDevice()
- clearScreen()
- fs.delete("/disk2/recovery.cfg")
- print("Device unmounted.")
- print("Waiting for /disk2/ to disappear...")
- while fs.exists("/disk2/") do
- os.sleep(1)
- end
- print("/disk2/ has disappeared.")
- -- Run the GUI
- shell.run("/disk/os/gui")
- end
- -- Start the program
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement