2020-03-30 08:43:38 +11:00
|
|
|
-- 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-30 08:43:38 +11:00
|
|
|
|
2020-03-31 03:47:27 +11:00
|
|
|
local u = require("libs.frw")
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-03-31 21:59:58 +11:00
|
|
|
local algImpl = require(alg .. ".compress")
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-03-31 03:47:27 +11:00
|
|
|
local instSize = 0
|
|
|
|
local function put(data)
|
|
|
|
io.write(data)
|
|
|
|
instSize = instSize + #data
|
|
|
|
end
|
|
|
|
|
2020-03-31 21:59:58 +11:00
|
|
|
-- TAR File --
|
|
|
|
local tarData = u.read(tarName)
|
|
|
|
local tarSectors = math.floor(#tarData / 512)
|
2020-03-31 03:47:27 +11:00
|
|
|
|
2020-03-31 21:59:58 +11:00
|
|
|
-- Installer Lexcrunch Context --
|
|
|
|
local lexCrunch = require("libs.lexcrunch")()
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-03-31 21:59:58 +11:00
|
|
|
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
|
|
|
|
2020-03-31 21:59:58 +11:00
|
|
|
-- Installer Compression --
|
|
|
|
local rawData = installerCore .. tarData
|
2020-03-30 08:43:38 +11:00
|
|
|
io.stderr:write("compressing...\n")
|
2020-03-31 21:59:58 +11:00
|
|
|
local compressionEngine, compressedData = algImpl(rawData, lexCrunch)
|
|
|
|
-- RISM [[
|
2020-03-30 08:43:38 +11:00
|
|
|
compressedData = compressedData:gsub("\xFE", "\xFE\xFE")
|
|
|
|
compressedData = compressedData:gsub("]]", "]\xFE]")
|
2020-03-31 21:59:58 +11:00
|
|
|
compressedData = "\x00" .. compressedData
|
|
|
|
-- ]]
|
|
|
|
io.stderr:write("compression with " .. alg .. ": " .. #rawData .. " -> " .. #compressedData .. "\n")
|
2020-03-31 03:47:27 +11:00
|
|
|
|
2020-03-31 21:59:58 +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 .. "]]")
|
2020-03-30 08:43:38 +11:00
|
|
|
|