Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to get all files in the /disk/packages/ directory
- function getFiles()
- local files = fs.list("/disk/packages/")
- table.sort(files)
- return files
- end
- -- Function to separate package files and other files
- function separateFiles(files)
- local packageFiles = {}
- local otherFiles = {}
- for _, file in ipairs(files) do
- if string.sub(file, 1, 7) == "package" then
- table.insert(packageFiles, file)
- else
- table.insert(otherFiles, file)
- end
- end
- return packageFiles, otherFiles
- end
- -- Function to check if root access is required
- function requiresRootAccess(filePath)
- local protectedPaths = {"/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/"}
- for _, path in ipairs(protectedPaths) do
- if string.find(filePath, path, 1, true) then
- return true
- end
- end
- return false
- end
- -- Function to prompt for device admin access
- function promptDeviceAdmin()
- term.clear()
- term.setCursorPos(1, 1)
- print("Root access required to modify system files.")
- print("Do you want to run the application as device admin? (yes/no)")
- local response = read()
- return response:lower() == "yes"
- end
- -- Function to run a selected file with root access check
- function runFile(filePath)
- if requiresRootAccess(filePath) and not (fs.exists("/disk/root.txt") or string.sub(filePath, 1, 7) == "package") then
- if not promptDeviceAdmin() then
- term.clear()
- term.setCursorPos(1, 1)
- print("Exiting program. Press Enter to continue.")
- read()
- return
- end
- end
- shell.run(filePath)
- end
- -- Function to display the list of files and handle selection
- function displayFiles(packageFiles, otherFiles)
- term.clear()
- term.setCursorPos(1, 1)
- print("Package Manager files:")
- for i, file in ipairs(packageFiles) do
- print(i .. ". " .. file)
- end
- print("\nOther files:")
- local offset = #packageFiles
- for i, file in ipairs(otherFiles) do
- print((i + offset) .. ". " .. file)
- end
- print("\nSelect a file to run by entering the number:")
- local selection = tonumber(read())
- if selection then
- if selection > 0 and selection <= #packageFiles then
- term.clear()
- term.setCursorPos(1, 1)
- runFile("/disk/packages/" .. packageFiles[selection])
- elseif selection > #packageFiles and selection <= (#packageFiles + #otherFiles) then
- term.clear()
- term.setCursorPos(1, 1)
- runFile("/disk/packages/" .. otherFiles[selection - #packageFiles])
- else
- print("Invalid selection")
- end
- else
- print("Invalid input")
- end
- -- Return to the GUI after the program ends
- term.clear()
- term.setCursorPos(1, 1)
- shell.run("/disk/os/gui")
- end
- -- Main program
- local files = getFiles()
- local packageFiles, otherFiles = separateFiles(files)
- displayFiles(packageFiles, otherFiles)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement