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

46 lines
1.5 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")()
local installerCore = lexCrunch(u.read("instcore.lua"), {["$$SECTORS"] = tostring(tarSectors)})
local installerHead = lexCrunch(u.read("insthead.lua"), {["$$CORESIZE"] = tostring(#installerCore)})
local installerTail = lexCrunch(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")
put(lexCrunch(installerHead .. compressionEngine .. installerTail, {}))
put("--[[" .. compressedData .. "]]")