local serial = require "serialization" local tArgs = {...} local src, dest = tArgs[1], tArgs[2].."/" local filter = {} for k,v in ipairs({table.unpack(tArgs,3)}) do filter[v] = true end local _OSVERSION = _OSVERSION or "" local function normalisePath(path) local pt = {} for seg in path:gmatch("[^/]+") do pt[#pt+1] = seg end pre = "" if path:sub(1,1) == "/" then pre = "/" end return pre .. table.concat(pt, "/") end local function wget(src,dest) dest=normalisePath(dest) local fstr = "wget '%s' -qO '%s'" local command = string.format(fstr,src,dest) print(command) return os.execute(command) end local dirs = {} local function mkdir(path) path=normalisePath(path) if dirs[path] then return true end local fstr = "mkdir -p '%s'" if _OSVERSION:sub(1,6) == "OpenOS" then fstr = "mkdir '%s'" end local command = string.format(fstr,path) print(command) dirs[path] = true return os.execute(command) end local function parsecfg(path) path=normalisePath(path) local f = io.open(path,"rb") if not f then error("unable to open "..tostring(path).." for parsing") end local rt = serial.unserialize(f:read("*a")) f:close() if type(rt) ~= "table" then error("unable to parse "..tostring(path)) end return rt end local function writecfg(t,path) path=normalisePath(path) local f = io.open(path, "wb") if not f then error("unable to open "..tostring(path).." for writing") end f:write(serial.serialize(t)) f:close() end local pathpre = src:match("(.+/).+/.+") print(pathpre) mkdir(dest.."/master/") local pcfgname = os.tmpname() wget(src,pcfgname) local programs = parsecfg(pcfgname) os.execute("rm '"..pcfgname.."'") if tArgs[3] then for k,v in pairs(programs) do if not filter[k] then programs[k] = nil end end end local dlfiles = {} for k,v in pairs(programs) do for l,m in pairs(v.files or {}) do dlfiles[#dlfiles+1] = l end for l,m in pairs(v.dependencies or {}) do if l:match("^https?://") then dlfiles[#dlfiles+1] = l end end end for k,v in pairs(dlfiles) do local path = v:match("^(.+)/[^/]+$") or v if v:match("^https?://") then local fp = v:match("^https?://(.+)$") mkdir(dest.."/external/"..fp:match("^(.+)/[^/]+$")) wget(v,dest.."/external/"..fp) else mkdir(dest..path) wget(pathpre..v,dest..v) end end -- merge programs.cfg with existing if applicable local w, oprograms = pcall(parsecfg, dest.."/master/programs.cfg") if w then for k,v in pairs(oprograms) do programs[k] = programs[k] or v end end writecfg(programs, dest.."/master/programs.cfg") wget("https://git.shadowkat.net/izaya/OC-misc/raw/branch/master/repo-installer/repoinstaller.lua", dest.."/.install")