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 src, dest = tArgs[1], tArgs[2].."/"
|
||||
|
||||
os.execute("mkdir "..dest.."/master/")
|
||||
os.execute("wget "..src.." -O "..dest.."/master/programs.cfg")
|
||||
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 -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("(.+/).+/.+")
|
||||
print(pathpre)
|
||||
|
||||
local f = io.open(dest.."/master/programs.cfg","rb")
|
||||
if not f then
|
||||
print("Unable to open programs.cfg")
|
||||
return false
|
||||
end
|
||||
local programs = serial.unserialize(f:read("*a"))
|
||||
f:close()
|
||||
mkdir(dest.."/master/")
|
||||
local pcfgname = os.tmpname()
|
||||
wget(src,pcfgname)
|
||||
local programs = parsecfg(pcfgname)
|
||||
os.execute("rm '"..pcfgname.."'")
|
||||
|
||||
local dlfiles = {}
|
||||
for k,v in pairs(programs) do
|
||||
@ -29,14 +77,23 @@ end
|
||||
for k,v in pairs(dlfiles) do
|
||||
local path,fn = v:match("(.+)/(.+)")
|
||||
if v:sub(1,4) ~= "http" then
|
||||
os.execute("mkdir -p "..dest..path)
|
||||
os.execute("wget "..pathpre..v.." -O "..dest..v)
|
||||
print("wget "..pathpre..v.." -O "..dest..v..">/dev/null")
|
||||
mkdir(dest..path)
|
||||
wget(pathpre..v,dest..v)
|
||||
else
|
||||
os.execute("mkdir -p "..dest.."/external")
|
||||
print("wget "..v.." -O "..dest.."/external/"..v)
|
||||
os.execute("wget "..v.." -O "..dest.."/external/"..fn.."> /dev/null")
|
||||
mkdir(dest.."/external")
|
||||
wget(v,dest.."/external/"..fn)
|
||||
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