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 03:47:27 +11:00
local tarData = u.read ( tarName )
2020-03-30 08:43:38 +11:00
local tarSectors = math.floor ( # tarData / 512 )
2020-03-31 03:47:27 +11:00
local instSize = 0
local function put ( data )
io.write ( data )
instSize = instSize + # data
end
put ( " -- " .. cid .. " \n " )
put ( " --This is released into the public domain. No warranty is provided, implied or otherwise. \n " )
local instCode = " K= " .. tarSectors .. " \n " .. u.read ( alg .. " /instdeco.lua " ) .. u.read ( " instbase.lua " )
2020-03-30 08:43:38 +11:00
instCode = require ( " libs.lexcrunch " ) ( instCode )
2020-03-31 03:47:27 +11:00
put ( instCode )
2020-03-30 08:43:38 +11:00
-- the \x00 is the indicator to start reading
2020-03-31 03:47:27 +11:00
put ( " --[[ \x00 " )
2020-03-30 08:43:38 +11:00
io.stderr : write ( " compressing... \n " )
local compressedData = require ( alg .. " .compress " ) ( tarData )
2020-03-31 03:47:27 +11:00
u.write ( alg .. " /output.bin " , compressedData )
2020-03-30 08:43:38 +11:00
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 ] " )
2020-03-31 03:47:27 +11:00
put ( compressedData )
put ( " ]] " )
local status = " "
local statusDetail = " "
local blinkI = " "
if instSize > 65536 then
blinkI = " 5;31; "
status = " DO NOT SHIP "
statusDetail = " The installer is too big to ship safely. \n It's possible it may crash on Tier 1 systems. \n Upgrade the compression system or remove existing code. "
elseif instSize > 64000 then
blinkI = " 33; "
status = " Shippable * "
statusDetail = " The installer is getting dangerously large. \n Reserve further room for bugfixes. "
else
blinkI = " 32; "
status = " All Green "
statusDetail = " The installer is well within budget with room for features. \n Develop as normal. "
end
io.stderr : write ( " \n " )
local ctS , ctM , ctE = " \x1b [1; " .. blinkI .. " 7m " , " \x1b [0;7m " , " \x1b [0m \n "
io.stderr : write ( ctS .. " " .. ctM .. " " .. ctE )
io.stderr : write ( ctS .. status .. ctM .. string.format ( " %07i " , 65536 - instSize ) .. ctE )
io.stderr : write ( ctS .. " " .. ctM .. " " .. ctE )
io.stderr : write ( " \n " )
io.stderr : write ( statusDetail .. " \n " )
io.stderr : write ( " \n " )
io.stderr : write ( " Size: " .. instSize .. " \n " )
io.stderr : write ( " max. 65536 \n " )
io.stderr : write ( " \n " )
2020-03-30 08:43:38 +11:00