Compare commits
2 Commits
b3aa15b580
...
9dd5f5d4ad
Author | SHA1 | Date | |
---|---|---|---|
9dd5f5d4ad | |||
0dbd1d5f8c |
@ -5,15 +5,25 @@ function shenv.quit()
|
||||
end
|
||||
shenv.cd = os.chdir
|
||||
shenv.mkdir = fs.makeDirectory
|
||||
local function findPath(name)
|
||||
path = os.getenv("PATH") or "/boot/exec"
|
||||
for l in path:gmatch("[^\n]+") do
|
||||
if fs.exists(l.."/"..name) then
|
||||
return l.."/"..name
|
||||
elseif fs.exists(l.."/"..name..".lua") then
|
||||
return l.."/"..name..".lua"
|
||||
end
|
||||
end
|
||||
end
|
||||
setmetatable(shenv,{__index=function(_,k)
|
||||
local fp = findPath(k)
|
||||
if _G[k] then
|
||||
return _G[k]
|
||||
elseif fs.exists("/boot/exec/"..k..".lua") then
|
||||
--[[
|
||||
elseif fp then
|
||||
local rqid = string.format("shell-%d",math.random(1,99999))
|
||||
return function(...)
|
||||
local tA = {...}
|
||||
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile("/boot/exec/"..k..".lua"),table.unpack(tA))) end,"/boot/exec/"..k..".lua")
|
||||
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
|
||||
local tE = {}
|
||||
repeat
|
||||
tE = {coroutine.yield()}
|
||||
@ -24,17 +34,19 @@ setmetatable(shenv,{__index=function(_,k)
|
||||
end
|
||||
return table.unpack(tE)
|
||||
end
|
||||
until tTasks[pid] == nil
|
||||
until not os.taskInfo(pid)
|
||||
end
|
||||
]]--
|
||||
return loadfile("/boot/exec/"..k..".lua")
|
||||
end
|
||||
end})
|
||||
print(_VERSION)
|
||||
os.setenv("run",true)
|
||||
while os.getenv("run") do
|
||||
io.write((os.getenv("PWD") or _VERSION).."> ")
|
||||
tResult = {pcall(load(io.read(),"shell","t",shenv))}
|
||||
io.write(string.format("%s:%s> ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
|
||||
local input=io.read()
|
||||
if input:sub(1,1) == "=" then
|
||||
input = "return "..input:sub(2)
|
||||
end
|
||||
tResult = {pcall(load(input,"shell","t",shenv))}
|
||||
if tResult[1] == true then table.remove(tResult,1) end
|
||||
for k,v in pairs(tResult) do
|
||||
print(v)
|
||||
|
106
lib/unionfs.lua
Normal file
106
lib/unionfs.lua
Normal file
@ -0,0 +1,106 @@
|
||||
local unionfs = {}
|
||||
|
||||
local function normalise(path)
|
||||
return table.concat(fs.segments(path),"/")
|
||||
end
|
||||
|
||||
function unionfs.create(...)
|
||||
local paths,fids,fc = {...}, {}, 0
|
||||
for k,v in pairs(paths) do
|
||||
paths[k] = "/"..normalise(v)
|
||||
end
|
||||
local proxy = {}
|
||||
local function realpath(path)
|
||||
path = path or ""
|
||||
for k,v in pairs(paths) do
|
||||
if fs.exists(v.."/"..path) then
|
||||
return v.."/"..path
|
||||
end
|
||||
end
|
||||
return paths[1].."/"..path
|
||||
end
|
||||
|
||||
function proxy.spaceUsed()
|
||||
return fs.spaceUsed(paths[1])
|
||||
end
|
||||
function proxy.spaceTotal()
|
||||
return fs.spaceTotal(paths[1])
|
||||
end
|
||||
function proxy.isReadOnly()
|
||||
return fs.isReadOnly(paths[1])
|
||||
end
|
||||
function proxy.isDirectory(path)
|
||||
return fs.isDirectory(realpath(path))
|
||||
end
|
||||
function proxy.lastModified(path)
|
||||
return fs.lastModified(realpath(path))
|
||||
end
|
||||
|
||||
function proxy.exists(path)
|
||||
return fs.exists(realpath(path))
|
||||
end
|
||||
function proxy.remove(path)
|
||||
return fs.remove(realpath(path))
|
||||
end
|
||||
function proxy.size(path)
|
||||
return fs.size(realpath(path))
|
||||
end
|
||||
|
||||
function proxy.list(path)
|
||||
local nt,rt = {},{}
|
||||
if #fs.segments(path) < 1 then
|
||||
for k,v in pairs(paths) do
|
||||
print(v.."/"..path)
|
||||
for l,m in ipairs(fs.list(v.."/"..path)) do
|
||||
nt[m] = true
|
||||
end
|
||||
end
|
||||
for k,v in pairs(nt) do
|
||||
rt[#rt+1] = k
|
||||
end
|
||||
table.sort(rt)
|
||||
return rt
|
||||
else
|
||||
return fs.list(realpath(path))
|
||||
end
|
||||
end
|
||||
|
||||
function proxy.open(path,mode)
|
||||
local fh, r = fs.open(realpath(path),mode)
|
||||
if not fh then return fh, r end
|
||||
fids[fc] = fh
|
||||
fc = fc + 1
|
||||
return fc - 1
|
||||
end
|
||||
|
||||
function proxy.close(fid)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
local rfh = fids[fid]
|
||||
fids[fid] = nil
|
||||
return rfh:close()
|
||||
end
|
||||
function proxy.write(fid,d)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
return fids[fid]:write(d)
|
||||
end
|
||||
function proxy.read(fid,d)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
return fids[fid]:read(d)
|
||||
end
|
||||
function proxy.seek(fid,d)
|
||||
if not fids[fid] then
|
||||
return false, "file not open"
|
||||
end
|
||||
return fids[fid]:seek(d)
|
||||
end
|
||||
|
||||
return proxy
|
||||
end
|
||||
|
||||
return unionfs
|
Loading…
Reference in New Issue
Block a user