-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_unpacker.lua
51 lines (44 loc) · 1.64 KB
/
build_unpacker.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local io <const> = require("io")
local requiredLibs <const> = {
{ "installer_disk_template/env_shim.lua", "env" },
{ "disk_template/slib/string.lua", nil },
{ "disk_template/lib/tar.lua", "tar" },
{ "disk_template/lib/util.lua", "util" },
{ "disk_template/lib/json.lua", "json" },
{ "disk_template/lib/serialization.lua", "serialization" },
{ "disk_template/lib/present.lua", "present" },
-- Must be last.
{ "installer_disk_template/unpacker_core.lua", nil },
}
local source = [[
-- AUTO GENERATED DO NOT MODIFY
-- Re-run build_unpacker.lua to change this script.
-- This script "just" unpacks the given tar file to a given disk.
-- Yes, this script tampers with require() which is bad for OpenOS.
-- The assumption is you plan to replace OpenOS and will not continue using it shortly after running this.
]]
for _, v in ipairs(requiredLibs) do
local text
do
local file = io.open(v[1], "rb")
assert(file)
text = file:read("a")
file:close()
end
if v[2] then
local fnname = "__GEN_" .. v[2]
source = source
.. "\n-- " .. v[1] .. "\n"
.. "local function " .. fnname .. "()\n"
.. text
.. "\nend\n" .. v[2] .. " = " .. fnname .. "()\n"
.. "package.loaded[" .. string.format("%q", v[2]) .. "] = " .. v[2] .. "\n"
else
source = source .. string.format("\ndo --%s\n", v[1]) .. text .. "\nend\n"
end
end
do
local target = io.open("installer_disk_template/unpacker.lua", "wb")
assert(target)
target:write(source)
end