refactored instgen to be much cleaner and natively support merging programs.cfg files
This commit is contained in:
parent
8b3ccc8e4b
commit
407d8fa43c
@ -3,19 +3,67 @@ local serial = require "serialization"
|
|||||||
local tArgs = {...}
|
local tArgs = {...}
|
||||||
local src, dest = tArgs[1], tArgs[2].."/"
|
local src, dest = tArgs[1], tArgs[2].."/"
|
||||||
|
|
||||||
os.execute("mkdir "..dest.."/master/")
|
local _OSVERSION = _OSVERSION or ""
|
||||||
os.execute("wget "..src.." -O "..dest.."/master/programs.cfg")
|
|
||||||
|
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 -p '%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("(.+/).+/.+")
|
local pathpre = src:match("(.+/).+/.+")
|
||||||
print(pathpre)
|
print(pathpre)
|
||||||
|
|
||||||
local f = io.open(dest.."/master/programs.cfg","rb")
|
mkdir(dest.."/master/")
|
||||||
if not f then
|
local pcfgname = os.tmpname()
|
||||||
print("Unable to open programs.cfg")
|
wget(src,pcfgname)
|
||||||
return false
|
local programs = parsecfg(pcfgname)
|
||||||
end
|
os.execute("rm '"..pcfgname.."'")
|
||||||
local programs = serial.unserialize(f:read("*a"))
|
|
||||||
f:close()
|
|
||||||
|
|
||||||
local dlfiles = {}
|
local dlfiles = {}
|
||||||
for k,v in pairs(programs) do
|
for k,v in pairs(programs) do
|
||||||
@ -29,14 +77,23 @@ end
|
|||||||
for k,v in pairs(dlfiles) do
|
for k,v in pairs(dlfiles) do
|
||||||
local path,fn = v:match("(.+)/(.+)")
|
local path,fn = v:match("(.+)/(.+)")
|
||||||
if v:sub(1,4) ~= "http" then
|
if v:sub(1,4) ~= "http" then
|
||||||
os.execute("mkdir -p "..dest..path)
|
mkdir(dest..path)
|
||||||
os.execute("wget "..pathpre..v.." -O "..dest..v)
|
wget(pathpre..v,dest..v)
|
||||||
print("wget "..pathpre..v.." -O "..dest..v..">/dev/null")
|
|
||||||
else
|
else
|
||||||
os.execute("mkdir -p "..dest.."/external")
|
mkdir(dest.."/external")
|
||||||
print("wget "..v.." -O "..dest.."/external/"..v)
|
wget(v,dest.."/external/"..fn)
|
||||||
os.execute("wget "..v.." -O "..dest.."/external/"..fn.."> /dev/null")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
os.execute("wget https://git.shadowkat.net/izaya/OC-misc/raw/branch/master/repo-installer/repoinstaller.lua -O "..dest.."/.install")
|
-- 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")
|
||||||
|
Loading…
Reference in New Issue
Block a user