1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-14 22:38:07 +11:00
Zorya-NEO/util/OpenOS/zyneo-geninitramfs.lua

93 lines
1.9 KiB
Lua
Raw Normal View History

2020-03-20 07:50:37 +11:00
local fs = require("filesystem")
print("Regenerating Zorya NEO initramfs...")
2020-06-07 05:19:16 +10:00
fs.copy("/.zy2/image.tsar", "/.zy2/image.tsar.old")
local f = io.open("/.zy2/image.tsar", "wb")
2020-03-20 07:50:37 +11:00
local lst = {}
for ent in fs.list("/etc/zorya-neo/initramfs.d") do
if ent:sub(#ent) ~= "/" then
lst[#lst+1] = ent
end
end
table.sort(lst)
local modes = {
["fifo"] = 1,
["char device"] = 2,
["directory"] = 4,
["block device"] = 6,
["file"] = 8,
["link"] = 0xA,
["socket"] = 0xC
}
local function getperm(perm, mode)
local md = 0
for i=1, 9 do
if (perm:sub(10-i,10-i) ~= "-") then
md = md | (1 << (i-1))
end
end
return md | (modes[mode] << 12)
end
local function create_node(attr)
local ent = {
magic = 0x5f7d,
namesize = #attr.name,
name = attr.name,
mode = getperm(attr.permissions, attr.mode),
uid = attr.uid,
gid = attr.gid,
filesize = attr.filesize,
2020-06-17 15:22:48 +10:00
mtime = (attr.mtime*1000)//1
2020-03-20 07:50:37 +11:00
}
f:write(string.pack("=I2I2I2I2I2I6I6", ent.magic, ent.namesize, ent.mode, ent.uid, ent.gid, ent.filesize, ent.mtime))
2020-06-17 15:22:48 +10:00
f:write(attr.name or "")
if (ent.namesize & 1 > 0) then
f:write("\0")
end
2020-03-20 07:50:37 +11:00
f:write(attr.data or "")
2020-06-17 15:22:48 +10:00
if (ent.filesize & 1 > 0) then
f:write("\0")
end
2020-03-20 07:50:37 +11:00
end
local arc = {}
function arc.file(path, perm, data)
create_node({
data = data,
filesize = #data,
uid = 0,
gid = 0,
mtime = os.time(),
name = path,
permissions = perm or "rw-r--r--",
mode = "file"
})
end
function arc.dir(path, perm)
create_node({
uid = 0,
filesize = 0,
gid = 0,
mtime = os.time(),
name = path,
permissions = perm or "rwxr-xr-x",
mode = "directory"
})
end
for i=1, #lst do
print("> "..lst[i])
loadfile("/etc/zorya-neo/initramfs.d/"..lst[i])(arc)
end
local zy_dat = [[{os="Zorya NEO", version={2,0,0}, generator="OpenOS"}]]
create_node({
data = zy_dat,
filesize = #zy_dat,
uid = 0,
gid = 0,
mtime = os.time(),
name = "TRAILER!!!",
permissions = "---------",
mode = "file"
})
f:close()
print("Generated new initramfs.")