args = {...} url = "http://lua.gaywine.org" path = "bin/" if not fs.exists(path) then fs.makeDir(path) end temp = "temp/" if not fs.exists(temp) then fs.makeDir(temp) end if #args > 0 then programToInstall = args[1] end if #args > 1 then customPath = shell.resolve(args[2]) end function downloadFile(filename) fileUrl = url .. "/files/" .. programToInstall .. "/" .. filename result = http.get(fileUrl) resultText = result.readAll() file = fs.open(temp .. filename, "w") file.write(resultText) file.close() end function split(pString, pPattern) local Table = {} -- NOTE: use {n = 0} in Lua-5.0 local fpat = "(.-)" .. pPattern local last_end = 1 local s, e, cap = pString:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(Table,cap) end last_end = e+1 s, e, cap = pString:find(fpat, last_end) end if last_end <= #pString then cap = pString:sub(last_end) table.insert(Table, cap) end return Table end function getAllFiles() indexesUrl = url .. "/indexes/" .. programToInstall result = http.get(indexesUrl) resultText = result.readAll() resultTable = split(resultText, "\n") finalResult = {} for key, value in ipairs(resultTable) do finalResult[key] = split(value, " ")[1] end return finalResult end function finishInstall(files) for key, file in ipairs(files) do if customPath ~= nil then fs.move(temp .. file, customPath .. "/" .. file) else fs.move(temp .. binary, path .. binary) end end if customPath ~= nil then program = "shell.run(" .. customPath .. "/run.lua)" file = fs.open(path .. programToInstall .. "/run.lua") file.write(program) file.close() end fs.delete(temp) end local files = getAllFiles() for _,value in ipairs(files) do downloadFile(value) end finishInstall(files)