1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-16 23:48:05 +11:00
OC-KittenOS/inst/build.lua

51 lines
1.6 KiB
Lua
Raw Normal View History

-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
-- KittenOS NEO Installer Generator --
2020-03-31 03:47:27 +11:00
local alg, tarName, cid = ...
cid = (cid or "UNKNOWN"):sub(1, 7)
2020-03-31 03:47:27 +11:00
local u = require("libs.frw")
local algImpl = require(alg .. ".compress")
2020-03-31 03:47:27 +11:00
local instSize = 0
local function put(data)
io.write(data)
instSize = instSize + #data
end
-- TAR File --
local tarData = u.read(tarName)
local tarSectors = math.floor(#tarData / 512)
2020-03-31 03:47:27 +11:00
-- Installer Lexcrunch Context --
local lexCrunch = require("libs.lexcrunch")()
2020-03-31 22:41:08 +11:00
local installerCore = lexCrunch.process(u.read("instcore.lua"), {["$$SECTORS"] = tostring(tarSectors)})
local installerHead = lexCrunch.process(u.read("insthead.lua"), {["$$CORESIZE"] = tostring(#installerCore)})
local installerTail = lexCrunch.process(u.read("insttail.lua"), {})
2020-03-31 03:47:27 +11:00
-- Installer Compression --
local rawData = installerCore .. tarData
io.stderr:write("compressing...\n")
local compressionEngine, compressedData = algImpl(rawData, lexCrunch)
-- RISM [[
compressedData = compressedData:gsub("\xFE", "\xFE\xFE")
compressedData = compressedData:gsub("]]", "]\xFE]")
compressedData = "\x00" .. compressedData
-- ]]
io.stderr:write("compression with " .. alg .. ": " .. #rawData .. " -> " .. #compressedData .. "\n")
2020-03-31 03:47:27 +11:00
-- Installer Final Generation --
put("--" .. cid .. "\n")
put("--This is released into the public domain. No warranty is provided, implied or otherwise.\n")
2020-03-31 22:41:08 +11:00
put(lexCrunch.process(installerHead .. compressionEngine .. installerTail, {}))
put("--[[" .. compressedData .. "]]")
2020-03-31 22:41:08 +11:00
-- Dumping debug info --
local dbg = io.open("iSymTab", "wb")
lexCrunch.dump(dbg)
dbg:close()