OC-misc/livefdd/etc/rc.d/livefdd.lua

53 lines
1.5 KiB
Lua
Raw Normal View History

2023-11-14 20:46:42 +11:00
function start()
local fs = require "filesystem"
local rootfs = fs.get("/")
local free = rootfs.spaceTotal() - rootfs.spaceUsed()
local function unpack(from,to)
if not fs.exists(from) then return false end
io.write(string.format("Unpacking %s to %s... ", from, to))
local opwd = os.getenv("PWD")
os.setenv("PWD", to)
os.execute(string.format("mtar -xz '%s'",from))
os.setenv("PWD", opwd)
print("Done!")
end
local function link(from)
from=fs.canonical(from)
local dt = {from}
for _, dir in ipairs(dt) do
for file in fs.list(dir) do
local fp = fs.concat(dir,file)
if file:match("/$") then
dt[#dt+1] = fp
else
local lt = fp:sub(#from+1)
while not fs.isDirectory(fs.path(lt)) and not fs.isLink(fs.path(lt)) do
lt = fs.path(lt)
end
fs.link(fs.concat(from,lt), lt)
end
end
end
end
if rootfs.isReadOnly() then -- live floppy
print("\27[2J\27[HPreparing live environment...")
fs.makeDirectory("/tmp/live")
unpack("/.live.mtar.lss","/tmp/live")
link("/tmp/live")
elseif not rootfs.isReadOnly() and free < 2^17 then -- installed on small media
print("\27[2J\27[HPreparing constrained environment...")
fs.makeDirectory("/tmp/live")
unpack("/.live.mtar.lss","/tmp/live")
unpack("/.inst.mtar.lss","/tmp/live")
link("/tmp/live")
else -- extract and deactivate
print("\27[2J\27[HFinalising installation...")
unpack("/.live.mtar.lss","/")
unpack("/.inst.mtar.lss","/")
unpack("/.extra.mtar.lss","/")
os.execute("rc livefdd disable")
end
end