2018-08-06 19:22:21 +10:00
|
|
|
local serial = require "serialization"
|
|
|
|
|
|
|
|
local tArgs = {...}
|
|
|
|
local src, dest = tArgs[1], tArgs[2].."/"
|
|
|
|
|
2020-10-19 16:44:57 +11:00
|
|
|
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
|
2020-10-19 16:46:58 +11:00
|
|
|
fstr = "mkdir '%s'"
|
2020-10-19 16:44:57 +11:00
|
|
|
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
|
2018-08-06 19:22:21 +10:00
|
|
|
|
|
|
|
local pathpre = src:match("(.+/).+/.+")
|
|
|
|
print(pathpre)
|
|
|
|
|
2020-10-19 16:44:57 +11:00
|
|
|
mkdir(dest.."/master/")
|
|
|
|
local pcfgname = os.tmpname()
|
|
|
|
wget(src,pcfgname)
|
|
|
|
local programs = parsecfg(pcfgname)
|
|
|
|
os.execute("rm '"..pcfgname.."'")
|
2018-08-06 19:22:21 +10:00
|
|
|
|
|
|
|
local dlfiles = {}
|
|
|
|
for k,v in pairs(programs) do
|
|
|
|
if v.files then
|
|
|
|
for l,m in pairs(v.files) do
|
|
|
|
dlfiles[#dlfiles+1] = l
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for k,v in pairs(dlfiles) do
|
|
|
|
local path,fn = v:match("(.+)/(.+)")
|
2019-11-09 17:12:00 +11:00
|
|
|
if v:sub(1,4) ~= "http" then
|
2020-10-19 16:44:57 +11:00
|
|
|
mkdir(dest..path)
|
|
|
|
wget(pathpre..v,dest..v)
|
2019-11-09 17:12:00 +11:00
|
|
|
else
|
2020-10-19 16:44:57 +11:00
|
|
|
mkdir(dest.."/external")
|
|
|
|
wget(v,dest.."/external/"..fn)
|
2019-11-09 17:12:00 +11:00
|
|
|
end
|
2018-08-06 19:22:21 +10:00
|
|
|
end
|
|
|
|
|
2020-10-19 16:44:57 +11:00
|
|
|
-- 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")
|