Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term = term
- local fs = fs
- local colors = colors
- -- Function to check if a directory exists
- local function directoryExists(path)
- return fs.isDir(path)
- end
- -- Function to check if a file exists
- local function fileExists(path)
- return fs.exists(path) and not fs.isDir(path)
- end
- -- Function to list all bootable drives
- local function listBootableDrives()
- local drives = {}
- for _, side in ipairs(rs.getSides()) do
- local path = side.."/disk/bootloader/VA11-ILLA.lua"
- if directoryExists(path) then
- table.insert(drives, side)
- end
- end
- return drives
- end
- -- Function to list installed operating systems on a drive
- local function listInstalledOS(drive)
- local osList = {}
- if directoryExists(drive.."/disk/") then
- local files = fs.list(drive.."/disk/")
- for _, file in ipairs(files) do
- if file:match("%.Boot%d$") then
- table.insert(osList, file)
- end
- end
- end
- return osList
- end
- -- Function to display boot menu
- local function displayBootMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("UEFI Boot Menu")
- print("Select an OS using arrow keys and press Enter to boot.")
- print("Use arrow keys to navigate, press 'q' to exit.")
- print()
- local drives = listBootableDrives()
- for i, drive in ipairs(drives) do
- term.setTextColor(colors.green)
- term.write(drive.."/disk")
- term.setTextColor(colors.white)
- local osList = listInstalledOS(drive)
- for _, os in ipairs(osList) do
- term.write(" "..os)
- if i == selectedDriveIndex and os == selectedOS then
- term.write(" <")
- end
- print()
- end
- end
- end
- -- Function to handle key input
- local function handleInput()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.q then
- return false
- elseif key == keys.enter then
- if selectedDriveIndex and selectedOS then
- local selectedDrive = listBootableDrives()[selectedDriveIndex]
- fs.copy(selectedDrive.."/disk"..selectedOS, selectedDrive)
- return true
- end
- elseif key == keys.up or key == keys.down then
- local drives = listBootableDrives()
- if #drives > 0 then
- local numOS = #listInstalledOS(drives[selectedDriveIndex])
- if key == keys.up then
- selectedOSIndex = (selectedOSIndex - 1) % numOS + 1
- elseif key == keys.down then
- selectedOSIndex = (selectedOSIndex + 1) % numOS + 1
- end
- end
- end
- end
- end
- -- Main function
- local function main()
- while true do
- displayBootMenu()
- if not handleInput() then
- break
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Exiting UEFI Boot Menu")
- end
- -- Start the program
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement