Advertisement
DOGGYWOOF

Untitled

Oct 22nd, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. -- Package Manager for CC Tweaked
  2. local packages = {}
  3. local logFile = "/disk/packages/log.txt"
  4.  
  5. -- Load packages from Pastebin (replace with actual URLs)
  6. local function loadPackages()
  7. -- Simulated package loading from Pastebin
  8. packages = {
  9. ["example1"] = {version = "1.0", description = "Example package 1"},
  10. ["example2"] = {version = "2.1", description = "Example package 2"},
  11. }
  12. end
  13.  
  14. -- Log actions
  15. local function logAction(action)
  16. local file = fs.open(logFile, "a")
  17. file.writeLine(os.date("%Y-%m-%d %H:%M:%S") .. " - " .. action)
  18. file.close()
  19. end
  20.  
  21. -- Install package
  22. local function installPackage(packageName)
  23. if not packages[packageName] then
  24. print("Package not found.")
  25. return
  26. end
  27.  
  28. print("Installing " .. packageName .. "...")
  29. for i = 1, 100, math.random(5, 15) do
  30. sleep(0.1)
  31. term.setCursorPos(1, 3)
  32. term.clearLine()
  33. term.write("Installing " .. packageName .. ": " .. i .. "%")
  34. end
  35. print("\n" .. packageName .. " installed successfully.")
  36. logAction("Installed package: " .. packageName)
  37. end
  38.  
  39. -- Remove package
  40. local function removePackage(packageName)
  41. if not packages[packageName] then
  42. print("Package not found.")
  43. return
  44. end
  45.  
  46. print("Removing " .. packageName .. "...")
  47. for i = 1, 100, math.random(5, 15) do
  48. sleep(0.1)
  49. term.setCursorPos(1, 3)
  50. term.clearLine()
  51. term.write("Removing " .. packageName .. ": " .. i .. "%")
  52. end
  53. print("\n" .. packageName .. " removed successfully.")
  54. logAction("Removed package: " .. packageName)
  55. end
  56.  
  57. -- List installed packages
  58. local function listPackages()
  59. print("Installed Packages:")
  60. for name, info in pairs(packages) do
  61. print(" - " .. name .. " (v" .. info.version .. "): " .. info.description)
  62. end
  63. end
  64.  
  65. -- Update packages (deletes and reinstalls)
  66. local function updatePackages()
  67. print("Updating packages...")
  68. for packageName in pairs(packages) do
  69. removePackage(packageName)
  70. installPackage(packageName)
  71. end
  72. logAction("Updated all packages.")
  73. end
  74.  
  75. -- Search for a package
  76. local function searchPackage(packageName)
  77. print("Searching for packages matching '" .. packageName .. "'...")
  78. for name, info in pairs(packages) do
  79. if string.find(name, packageName) then
  80. print(" - " .. name .. " (v" .. info.version .. "): " .. info.description)
  81. end
  82. end
  83. end
  84.  
  85. -- Display help
  86. local function displayHelp()
  87. print("Commands:")
  88. print(" install <package> - Install a package.")
  89. print(" remove <package> - Remove a package.")
  90. print(" update - Update all packages.")
  91. print(" list - List installed packages.")
  92. print(" search <query> - Search for packages.")
  93. print(" help - Show this help message.")
  94. end
  95.  
  96. -- Main function to handle user input
  97. local function main()
  98. loadPackages()
  99.  
  100. while true do
  101. term.write("> ")
  102. local input = read()
  103. local args = {}
  104. for arg in input:gmatch("%S+") do
  105. table.insert(args, arg)
  106. end
  107.  
  108. if args[1] == "install" and args[2] then
  109. installPackage(args[2])
  110. elseif args[1] == "remove" and args[2] then
  111. removePackage(args[2])
  112. elseif args[1] == "list" then
  113. listPackages()
  114. elseif args[1] == "update" then
  115. updatePackages()
  116. elseif args[1] == "search" and args[2] then
  117. searchPackage(args[2])
  118. elseif args[1] == "help" then
  119. displayHelp()
  120. else
  121. print("Unknown command. Type 'help' for a list of commands.")
  122. end
  123. end
  124. end
  125.  
  126. -- Run the main function
  127. main()
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement