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-04-01 03:52:24 +11:00
|
|
|
local args = {...}
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-04-01 03:52:24 +11:00
|
|
|
local cid = args[1]
|
|
|
|
local tarName = args[2]
|
|
|
|
local algorithmsInReverseOrder = {}
|
|
|
|
for i = 3, #args do
|
|
|
|
table.insert(algorithmsInReverseOrder, 1, args[i])
|
|
|
|
end
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-04-01 03:52:24 +11:00
|
|
|
local u = require("libs.frw")
|
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
|
|
|
-- Installer Lexcrunch Context --
|
|
|
|
local lexCrunch = require("libs.lexcrunch")()
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-04-01 03:52:24 +11:00
|
|
|
-- Installer Core --
|
|
|
|
|
|
|
|
-- installerFinalized:
|
|
|
|
-- Stuff that's already finished and put at the end of RISM. Prepend to this.
|
|
|
|
-- installerPayload / installerProgramLength:
|
|
|
|
-- The next-outer chunk that hasn't been written to the end of RISM
|
|
|
|
-- as the compression scheme (if one) has not been applied yet.
|
|
|
|
-- Really, installerProgramLength is only necessary because of the innermost chunk,
|
|
|
|
-- as that chunk has the TAR; additional data that's part of the same effective compression block,
|
|
|
|
-- but requires the program length to avoid it.
|
|
|
|
local installerPayload
|
|
|
|
local installerProgramLength
|
|
|
|
local installerFinalized = ""
|
|
|
|
|
|
|
|
do
|
|
|
|
local tarData = u.read(tarName)
|
|
|
|
local tarSectors = math.floor(#tarData / 512)
|
|
|
|
local installerCore = lexCrunch.process(u.read("instcore.lua"), {["$$SECTORS"] = tostring(tarSectors)})
|
|
|
|
installerPayload = installerCore .. tarData
|
|
|
|
installerProgramLength = #installerCore
|
|
|
|
end
|
2020-03-31 03:47:27 +11:00
|
|
|
|
2020-03-31 21:59:58 +11:00
|
|
|
-- Installer Compression --
|
2020-04-01 03:52:24 +11:00
|
|
|
for _, v in ipairs(algorithmsInReverseOrder) do
|
|
|
|
io.stderr:write("compressing (" .. v .. ")\n")
|
|
|
|
local algImpl = require(v .. ".compress")
|
|
|
|
local algEngine, algData = algImpl(installerPayload, lexCrunch)
|
|
|
|
io.stderr:write("result: " .. #installerPayload .. " -> " .. #algData .. "\n")
|
|
|
|
-- prepend the program length of the last section
|
|
|
|
algEngine = lexCrunch.process("$iBlockingLen = " .. installerProgramLength .. " " .. algEngine, {})
|
|
|
|
-- commit
|
|
|
|
installerPayload = algEngine
|
|
|
|
installerProgramLength = #installerPayload
|
|
|
|
installerFinalized = algData .. installerFinalized
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Installer Final --
|
|
|
|
|
|
|
|
-- This is a special case, so the program length/payload/etc. business has to be repeated.
|
2020-03-31 21:59:58 +11:00
|
|
|
put("--" .. cid .. "\n")
|
|
|
|
put("--This is released into the public domain. No warranty is provided, implied or otherwise.\n")
|
2020-04-01 03:52:24 +11:00
|
|
|
put(lexCrunch.process(u.read("insthead.lua"), {["$$CORESIZE"] = tostring(installerProgramLength)}))
|
|
|
|
|
|
|
|
local RISM = installerPayload .. installerFinalized
|
|
|
|
RISM = RISM:gsub("\xFE", "\xFE\xFE")
|
|
|
|
RISM = RISM:gsub("]]", "]\xFE]")
|
|
|
|
RISM = "\x00" .. RISM
|
|
|
|
put("--[[" .. RISM .. "]]")
|
2020-03-30 08:43:38 +11:00
|
|
|
|
2020-03-31 22:41:08 +11:00
|
|
|
-- Dumping debug info --
|
|
|
|
local dbg = io.open("iSymTab", "wb")
|
|
|
|
lexCrunch.dump(dbg)
|
|
|
|
dbg:close()
|
|
|
|
|