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

32 lines
959 B
Lua
Raw Normal View History

-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
-- KittenOS NEO Installer Generator --
local alg, tarName = ...
local function read(fn)
local f = io.open(fn, "rb")
local d = f:read("*a")
f:close()
return d
end
local tarData = read(tarName)
local tarSectors = math.floor(#tarData / 512)
local instCode = "K=" .. tarSectors .. "\n" .. read(alg .. "/instdeco.lua") .. read("instbase.lua")
instCode = require("libs.lexcrunch")(instCode)
io.write(instCode)
-- the \x00 is the indicator to start reading
io.write("--[[\x00")
io.stderr:write("compressing...\n")
local compressedData = require(alg .. ".compress")(tarData)
io.stderr:write("compression with " .. alg .. ": " .. #tarData .. " -> " .. #compressedData .. "\n")
-- Program the read-in state machine
compressedData = compressedData:gsub("\xFE", "\xFE\xFE")
compressedData = compressedData:gsub("]]", "]\xFE]")
io.write(compressedData)
io.write("]]")