This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
/
init.lua
53 lines (44 loc) · 2.01 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- a fake lil' OS
orb = {
mod_dir = (minetest and minetest.get_modpath("orb")) or
debug.getinfo(1,"S").source:sub(2, -9):gsub("(/+)$", "/"),
}
if(orb.mod_dir == "") then orb.mod_dir = "." end
dofile(orb.mod_dir .. "/utils.lua")
dofile(orb.mod_dir .. "/fs.lua")
dofile(orb.mod_dir .. "/shell.lua")
dofile(orb.mod_dir .. "/process.lua")
-- pp = dofile(orb.mod_dir .. "/PrettyPrint.lua")
-- for interactive use, but also as a sample of how the API works:
if(arg) then
-- start with an empty filesystem
f = orb.fs.empty()
f0 = orb.fs.seed(orb.fs.proxy(f, "root", f),
{"technomancy", "buddyberg", "zacherson"})
f1 = orb.fs.proxy(f, "technomancy", f)
e0 = orb.shell.new_env("root")
e1 = orb.shell.new_env("technomancy")
co = orb.process.spawn(f1, e1, "smash") -- Open an interactive shell
-- till we have non-blocking io.read, the scheduler isn't going to do jack
-- when run from regular stdin
while coroutine.status(co) ~= "dead" do orb.process.scheduler(f) end
-- tests
t_groups = orb.shell.groups(f0, "technomancy")
assert(orb.utils.includes(t_groups, "technomancy"))
assert(orb.utils.includes(t_groups, "all"))
assert(not orb.utils.includes(t_groups, "zacherson"))
orb.shell.exec(f1, e1, "mkdir mydir")
orb.shell.exec(f1, e1, "mkdir /tmp/hi")
orb.shell.exec(f1, e1, "ls /tmp/hi")
orb.shell.exec(f1, e1, "ls > /tmp/mydir")
orb.shell.exec(f1, e0, "ls /etc > /tmp/ls-etc")
orb.shell.exec(f1, e1, "cat /bin/cat > /tmp/cat")
assert(orb.fs.readable(f0, f1["/home/technomancy"], "technomancy"))
assert(orb.fs.readable(f0, f1["/bin"], "technomancy"))
assert(orb.fs.readable(f0, f1["/bin"], "zacherson"))
assert(orb.fs.writeable(f0, f1["/home/technomancy"], "technomancy"))
assert(orb.fs.writeable(f0, f1["/tmp"], "technomancy"))
-- assert(not orb.fs.writeable(f0, f1["/etc"], "technomancy"))
-- assert(not orb.fs.writeable(f0, f1["/home/zacherson"], "technomancy"))
-- assert(not orb.fs.readable(f0, f1["/home/zacherson"], "technomancy"))
end