Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- VA11-ILLA Bootloader
- local function clearScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function rebootDevice()
- os.reboot()
- end
- local function recoverSystem()
- shell.run("/disk/boot/Recovery.lua")
- end
- local function bootOptions()
- clearScreen()
- print("Select disk to boot from:")
- local disks = peripheral.find("drive")
- if disks then
- for i, disk in ipairs(disks) do
- print(i .. ". " .. disk)
- end
- local choice = read()
- if tonumber(choice) and disks[tonumber(choice)] then
- shell.run("/disk/" .. disks[tonumber(choice)] .. "/startup.lua")
- else
- print("Invalid choice!")
- end
- else
- print("No disks found.")
- end
- end
- local function setPassword()
- clearScreen()
- if not fs.exists("/firmware") then
- fs.makeDir("/firmware")
- end
- print("Enter new admin password:")
- local password = read("*")
- local file = fs.open("/firmware/password.cfg", "w")
- file.write(password)
- file.close()
- print("Password set.")
- end
- local function removePassword()
- if fs.exists("/firmware/password.cfg") then
- fs.delete("/firmware/password.cfg")
- print("Password removed.")
- else
- print("No password set.")
- end
- end
- local function securityMenu()
- while true do
- clearScreen()
- print("Security Menu:")
- print("1. Lock with admin password")
- print("2. Remove Lock")
- print("3. Back to main menu")
- local choice = read()
- if choice == "1" then
- setPassword()
- elseif choice == "2" then
- removePassword()
- elseif choice == "3" then
- break
- else
- print("Invalid choice! Press any key to continue...")
- os.pullEvent("key")
- end
- end
- end
- local function checkPassword()
- if fs.exists("/firmware/password.cfg") then
- clearScreen()
- print("Enter admin password:")
- local password = read("*")
- local file = fs.open("/firmware/password.cfg", "r")
- local savedPassword = file.readAll()
- file.close()
- if password == savedPassword then
- return true
- else
- print("Invalid password!")
- sleep(2)
- return false
- end
- end
- return true
- end
- local function mainMenu()
- while true do
- clearScreen()
- print("VA11-ILLA Bootloader:")
- print("1. Boot Doggy OS")
- print("2. Recover system")
- print("3. Boot options")
- print("4. Security")
- print("5. Exit")
- local choice = read()
- if choice == "1" then
- rebootDevice()
- elseif choice == "2" then
- recoverSystem()
- elseif choice == "3" then
- bootOptions()
- elseif choice == "4" then
- securityMenu()
- elseif choice == "5" then
- break
- else
- print("Invalid choice! Press any key to continue...")
- os.pullEvent("key")
- end
- end
- end
- -- Start Bootloader
- if checkPassword() then
- mainMenu()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement