Advertisement
DOGGYWOOF

Untitled

May 28th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. -- Function to get all files in the /disk/packages/ directory
  2. function getFiles()
  3. local files = fs.list("/disk/packages/")
  4. table.sort(files)
  5. return files
  6. end
  7.  
  8. -- Function to separate package files and other files
  9. function separateFiles(files)
  10. local packageFiles = {}
  11. local otherFiles = {}
  12.  
  13. for _, file in ipairs(files) do
  14. if string.sub(file, 1, 7) == "package" then
  15. table.insert(packageFiles, file)
  16. else
  17. table.insert(otherFiles, file)
  18. end
  19. end
  20.  
  21. return packageFiles, otherFiles
  22. end
  23.  
  24. -- Function to check if root access is required
  25. function requiresRootAccess(filePath)
  26. local protectedPaths = {"/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/"}
  27. for _, path in ipairs(protectedPaths) do
  28. if string.find(filePath, path, 1, true) then
  29. return true
  30. end
  31. end
  32. return false
  33. end
  34.  
  35. -- Function to prompt for device admin access
  36. function promptDeviceAdmin()
  37. term.clear()
  38. term.setCursorPos(1, 1)
  39. print("Root access required to modify system files.")
  40. print("Do you want to run the application as device admin? (yes/no)")
  41. local response = read()
  42. return response:lower() == "yes"
  43. end
  44.  
  45. -- Function to run a selected file with root access check
  46. function runFile(filePath)
  47. if requiresRootAccess(filePath) and not (fs.exists("/disk/root.txt") or string.sub(filePath, 1, 7) == "package") then
  48. if not promptDeviceAdmin() then
  49. term.clear()
  50. term.setCursorPos(1, 1)
  51. print("Exiting program. Press Enter to continue.")
  52. read()
  53. return
  54. end
  55. end
  56. shell.run(filePath)
  57. end
  58.  
  59. -- Function to display the list of files and handle selection
  60. function displayFiles(packageFiles, otherFiles)
  61. term.clear()
  62. term.setCursorPos(1, 1)
  63.  
  64. print("Package Manager files:")
  65. for i, file in ipairs(packageFiles) do
  66. print(i .. ". " .. file)
  67. end
  68.  
  69. print("\nOther files:")
  70. local offset = #packageFiles
  71. for i, file in ipairs(otherFiles) do
  72. print((i + offset) .. ". " .. file)
  73. end
  74.  
  75. print("\nSelect a file to run by entering the number:")
  76. local selection = tonumber(read())
  77.  
  78. if selection then
  79. if selection > 0 and selection <= #packageFiles then
  80. term.clear()
  81. term.setCursorPos(1, 1)
  82. runFile("/disk/packages/" .. packageFiles[selection])
  83. elseif selection > #packageFiles and selection <= (#packageFiles + #otherFiles) then
  84. term.clear()
  85. term.setCursorPos(1, 1)
  86. runFile("/disk/packages/" .. otherFiles[selection - #packageFiles])
  87. else
  88. print("Invalid selection")
  89. end
  90. else
  91. print("Invalid input")
  92. end
  93.  
  94. -- Return to the GUI after the program ends
  95. term.clear()
  96. term.setCursorPos(1, 1)
  97. shell.run("/disk/os/gui")
  98. end
  99.  
  100. -- Main program
  101. local files = getFiles()
  102. local packageFiles, otherFiles = separateFiles(files)
  103. displayFiles(packageFiles, otherFiles)
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement