-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistfs.boot.lua
50 lines (40 loc) · 1.22 KB
/
distfs.boot.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
local function DoDistFS()
local dfs = require("distfs")
local fs = require("filesystem")
local io = require("io")
local serialization = require("serialization")
if not fs.exists("/lib/distfs.lua") then
io.stderr:write("Unable to load DistFS: DistFS library missing!")
return
end
require("filesystem").mount(
require("distfs").proxy
, "/distfs")
local function split(s)
local fields = {}
local pattern = string.format("([^%s]+)", "=")
s:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
if not fs.exists("/etc/distfs/distfs.cfg") then
io.stderr:write("DistFS configuration file missing! Reverting to defaults...")
end
local function toValue(s)
s = tostring(s)
if tonumber(s) ~= nil then return tonumber(s) end
local t = serialization.unserialize(s)
if t ~= nil then return t end
if s:lower() == "true" then return true end
if s:lower() == "nil" then return nil end
return false
end
for line in io.lines("/etc/distfs/distfs.cfg") do
local d = split(line)
dfs[d[1]] = toValue(d[2])
end
dfs.init()
end
local success, err = pcall(DoDistFS)
if not success then
--io.stderr:write("Failed to initialize DistFS: " .. err)
end