2020-10-12 18:09:06 +11:00
|
|
|
local fsproxy = require "fsproxy"
|
|
|
|
local fs = require "filesystem"
|
2020-10-17 10:39:31 +11:00
|
|
|
local shell = require "shell"
|
|
|
|
local rpc = require "rpc"
|
2020-10-12 18:09:06 +11:00
|
|
|
|
2020-10-17 10:39:31 +11:00
|
|
|
local tA, tO = shell.parse(...)
|
2020-10-12 18:09:06 +11:00
|
|
|
if #tA < 1 then
|
2020-10-17 18:50:30 +11:00
|
|
|
print("Usage: exportfs <directory> [-d] [--rw] [--name=<name>] [--allow=hostname[,hostname,...]] [--deny=hostname[,hostname,...]]")
|
2020-10-12 18:09:06 +11:00
|
|
|
return
|
|
|
|
end
|
2020-10-17 18:50:30 +11:00
|
|
|
|
|
|
|
local allow, deny = {}, {}
|
|
|
|
for host in (tO.allow or ""):gmatch("[^,]+") do
|
|
|
|
allow[#allow+1] = host
|
|
|
|
end
|
|
|
|
for host in (tO.deny or ""):gmatch("[^,]+") do
|
|
|
|
deny[#deny+1] = host
|
|
|
|
end
|
|
|
|
|
2020-10-17 10:39:31 +11:00
|
|
|
local px = fsproxy.new(tA[1], not tO.rw)
|
|
|
|
local name = tO.name or tA[1]
|
|
|
|
for l,m in pairs(px) do
|
2020-10-17 10:45:36 +11:00
|
|
|
m = not tO.d and m or nil
|
2020-10-17 10:39:31 +11:00
|
|
|
rpc.register("fs_"..name.."_"..l,m)
|
2020-10-17 18:50:30 +11:00
|
|
|
for k,v in pairs(allow) do
|
|
|
|
rpc.allow("fs_"..name.."_"..l,v)
|
|
|
|
end
|
|
|
|
for k,v in pairs(deny) do
|
|
|
|
rpc.deny("fs_"..name.."_"..l,v)
|
|
|
|
end
|
2020-10-12 18:09:06 +11:00
|
|
|
end
|
2020-10-17 10:39:31 +11:00
|
|
|
print(string.format("%s (%s)", name, (tO.rw and "rw") or "ro"))
|