OC-misc/livefdd/bin/livefdc.lua

112 lines
3.0 KiB
Lua
Raw Normal View History

2023-11-14 20:46:42 +11:00
local serial = require "serialization"
local fs = require "filesystem"
local tA = {...}
if #tA < 8 then
print([[livefdc requires 8 arguments, in this order:
- path to clean OpenOS installer
- path to repoinstaller-compatible disk
- comma-separated list of packages to install in the base system
- comma-separated list of packages to archive for live use
- comma-separated list of packages to archive for constrained use
- comma-separated list of extra packages to be unpacked when there is space
- comma-separated list of paths to move into the extra archive
- output path
]])
os.exit(1)
end
local function parsecs(str)
local rt = {}
for w in str:gmatch("[^,]+") do
rt[#rt+1] = w
end
return rt
end
local oospath = fs.canonical(tA[1])
local pkgpath = fs.canonical(tA[2])
local basepkg, livepkg, instpkg, extpkg = parsecs(tA[3]), parsecs(tA[4]), parsecs(tA[5]), parsecs(tA[6])
local archivepaths = parsecs(tA[7])
local outpath = fs.canonical(tA[8])
local f = io.open(pkgpath .. "/master/programs.cfg", "rb")
local pkgs = serial.unserialize(f:read("*a"))
f:close()
local ipkgs,opkgs = {}, {}
local function run(cmd)
print(cmd)
os.execute(cmd)
end
local function mkdir(path)
print("mkdir",path)
fs.makeDirectory(path)
end
local function copy(from,to)
print("copy",from,to)
fs.copy(from,to)
end
local function move(from,to)
print("move",from,to)
fs.rename(from,to)
end
local function installPkg(pkgname, dest)
local pkg, opkg = pkgs[pkgname], {}
assert(pkg, "package not available")
print(string.format("Installing %s to %s", pkgname, dest))
for k,v in pairs(pkg.files or {}) do
v = v:match("^//") and v:sub(2) or fs.concat("/usr", v)
mkdir(fs.concat(dest,v))
copy(pkgpath .. "/" .. k,fs.concat(dest,v,fs.name(k)))
opkg[k] = fs.concat(v,fs.name(k))
end
for k,v in pairs(pkg.dependencies or {}) do
if k:match("^https?://") then
v = v:match("^//") and v:sub(2) or fs.concat("/usr", v)
mkdir(fs.concat(dest,v))
copy(fs.concat(pkgpath, "external", k:match("^https://(.+)$")), fs.concat(dest,v,fs.name(k)))
opkg[k] = fs.concat(v,fs.name(k))
elseif not ipkgs[k] then
installPkg(k,dest)
end
end
ipkgs[pkgname] = pkg
opkgs[pkgname] = opkg
return true
end
mkdir(outpath)
run(string.format("cp -rv '%s' '%s/img'",oospath,outpath))
for k,v in ipairs(basepkg) do
installPkg(v, fs.concat(outpath, "img"))
end
for k,v in ipairs(livepkg) do
installPkg(v, fs.concat(outpath, "live"))
end
for k,v in ipairs(instpkg) do
installPkg(v, fs.concat(outpath, "inst"))
end
for k,v in ipairs(extpkg) do
installPkg(v, fs.concat(outpath, "extra"))
end
for k,v in ipairs(archivepaths) do
mkdir(fs.concat(outpath, "extra", fs.path(v)))
move(fs.concat(outpath, "img", v), fs.concat(outpath, "extra", v))
end
local f = io.open(fs.concat(outpath, "img", "/etc/opdata.svd"), "wb")
f:write(serial.serialize(opkgs))
f:close()
local opwd = os.getenv("PWD")
for k,v in ipairs({"live","inst","extra"}) do
os.setenv("PWD", fs.concat(outpath, v))
run(string.format("mtar -czv '%s/img/.%s.mtar.lss' *", outpath, v))
end
os.setenv("PWD",opwd)