Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Frog Package Manager
- -- Version 1.2
- local function setColor(color)
- if term.isColor() then
- term.setTextColor(color)
- end
- end
- local function installProgram(name, code)
- if fs.exists(name) then
- print("Removed old " .. name)
- fs.delete(name)
- end
- shell.run("pastebin get " .. code .. " " .. name)
- end
- local function errorMsg(message)
- setColor(colors.red)
- print(message)
- setColor(colors.white)
- end
- -- Main Program
- local args = { ... }
- local packages = {}
- if #args == 0 then
- errorMsg("Usage: fpm ( list | update | upgrade | install )")
- return
- end
- if args[1] == "update" then
- installProgram("packages.list", "BuF1Hm9q")
- print("Successfully downloaded updated Package List!")
- return
- end
- if not fs.exists("packages.list") then
- errorMsg("Update your package list first! 'fpm update'")
- return
- end
- -- Loading packages into memory from file.
- for line in io.lines("packages.list") do
- local firstCommaIndex = string.find(line, ",")
- local secondCommaIndex = string.find(string.sub(line, firstCommaIndex + 1), ",") + firstCommaIndex
- local packageName = string.sub(line, 1, firstCommaIndex - 1)
- local packageCode = string.sub(line, firstCommaIndex + 1, secondCommaIndex - 1)
- local packageDesc = string.sub(line, secondCommaIndex + 1)
- local package = { packageName, packageCode, packageDesc }
- table.insert(packages, package)
- end
- if args[1] == "list" then
- local lineCount = 0
- for i in pairs(packages) do
- setColor(colors.orange)
- term.write(i .. ". ")
- setColor(colors.green)
- term.write(packages[i][1])
- setColor(colors.white)
- print(" - " .. packages[i][3])
- lineCount = lineCount + 1
- if lineCount == 5 then
- setColor(colors.orange)
- term.write("Press any key to continue")
- os.pullEvent("key")
- term.clearLine()
- oldx, oldy = term.getCursorPos()
- term.setCursorPos(1, oldy)
- lineCount = 0
- end
- end
- end
- if args[1] == "install" then
- if args[2] == nil then
- errorMsg("Please specify a package! 'fpm install [package]'")
- end
- local packageExists = false
- for i in pairs(packages) do
- if packages[i][1] == args[2] then
- installProgram(packages[i][1], packages[i][2])
- packageExists = true
- end
- end
- if not packageExists then
- errorMsg("Package not found!")
- end
- end
- if arg[1] == "upgrade" then
- for i in pairs(packages) do
- if fs.exists(packages[i][1]) then
- installProgram(packages[i][1], packages[i][2])
- end
- end
- print("\nUpgrade complete!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement