Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Package Manager for CC Tweaked
- local packages = {}
- local logFile = "/disk/packages/log.txt"
- -- Load packages from Pastebin (replace with actual URLs)
- local function loadPackages()
- -- Simulated package loading from Pastebin
- packages = {
- ["example1"] = {version = "1.0", description = "Example package 1"},
- ["example2"] = {version = "2.1", description = "Example package 2"},
- }
- end
- -- Log actions
- local function logAction(action)
- local file = fs.open(logFile, "a")
- file.writeLine(os.date("%Y-%m-%d %H:%M:%S") .. " - " .. action)
- file.close()
- end
- -- Install package
- local function installPackage(packageName)
- if not packages[packageName] then
- print("Package not found.")
- return
- end
- print("Installing " .. packageName .. "...")
- for i = 1, 100, math.random(5, 15) do
- sleep(0.1)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Installing " .. packageName .. ": " .. i .. "%")
- end
- print("\n" .. packageName .. " installed successfully.")
- logAction("Installed package: " .. packageName)
- end
- -- Remove package
- local function removePackage(packageName)
- if not packages[packageName] then
- print("Package not found.")
- return
- end
- print("Removing " .. packageName .. "...")
- for i = 1, 100, math.random(5, 15) do
- sleep(0.1)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Removing " .. packageName .. ": " .. i .. "%")
- end
- print("\n" .. packageName .. " removed successfully.")
- logAction("Removed package: " .. packageName)
- end
- -- List installed packages
- local function listPackages()
- print("Installed Packages:")
- for name, info in pairs(packages) do
- print(" - " .. name .. " (v" .. info.version .. "): " .. info.description)
- end
- end
- -- Update packages (deletes and reinstalls)
- local function updatePackages()
- print("Updating packages...")
- for packageName in pairs(packages) do
- removePackage(packageName)
- installPackage(packageName)
- end
- logAction("Updated all packages.")
- end
- -- Search for a package
- local function searchPackage(packageName)
- print("Searching for packages matching '" .. packageName .. "'...")
- for name, info in pairs(packages) do
- if string.find(name, packageName) then
- print(" - " .. name .. " (v" .. info.version .. "): " .. info.description)
- end
- end
- end
- -- Display help
- local function displayHelp()
- print("Commands:")
- print(" install <package> - Install a package.")
- print(" remove <package> - Remove a package.")
- print(" update - Update all packages.")
- print(" list - List installed packages.")
- print(" search <query> - Search for packages.")
- print(" help - Show this help message.")
- end
- -- Main function to handle user input
- local function main()
- loadPackages()
- while true do
- term.write("> ")
- local input = read()
- local args = {}
- for arg in input:gmatch("%S+") do
- table.insert(args, arg)
- end
- if args[1] == "install" and args[2] then
- installPackage(args[2])
- elseif args[1] == "remove" and args[2] then
- removePackage(args[2])
- elseif args[1] == "list" then
- listPackages()
- elseif args[1] == "update" then
- updatePackages()
- elseif args[1] == "search" and args[2] then
- searchPackage(args[2])
- elseif args[1] == "help" then
- displayHelp()
- else
- print("Unknown command. Type 'help' for a list of commands.")
- end
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement