2022-06-19 00:27:20 +00:00
|
|
|
local utils = require "../utils"
|
2022-06-18 15:05:18 +00:00
|
|
|
local t = require "../utils/templater"
|
|
|
|
local dirs = {}
|
2022-06-19 00:29:00 +00:00
|
|
|
local links = {}
|
2022-06-18 15:05:18 +00:00
|
|
|
|
|
|
|
local function generate_mount_data()
|
|
|
|
local string = "#!/bin/sh\n"
|
|
|
|
for i=1,#dirs do
|
|
|
|
local dir = dirs[i]
|
|
|
|
if dir.type == "file" then
|
|
|
|
touch(dir.mountpoint)
|
|
|
|
string = string .. t([[
|
2022-06-19 00:27:20 +00:00
|
|
|
mkdir -p '{{dirname}}' || exit 1
|
2022-06-18 15:05:18 +00:00
|
|
|
touch -a '{{path}}' || exit 1
|
|
|
|
mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || exit 1
|
|
|
|
]],
|
2022-06-19 00:27:20 +00:00
|
|
|
{ dirname = utils.dirname(dir.path),
|
|
|
|
path = dir.path, mountpoint = dir.mountpoint, uid = dir.uid, gid = dir.gid }
|
2022-06-18 15:05:18 +00:00
|
|
|
)
|
|
|
|
elseif dir.type == "dir" then
|
|
|
|
mkdir(dir.mountpoint)
|
|
|
|
string = string .. t([[
|
|
|
|
mkdir -p '{{path}}' || exit 1
|
|
|
|
mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || exit 1
|
|
|
|
]],
|
|
|
|
dir
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-06-19 00:29:00 +00:00
|
|
|
for i=1,#links do
|
|
|
|
local link = links[i]
|
|
|
|
string = string .. t([[
|
|
|
|
mkdir -p '{{dirname}}' || exit 1
|
|
|
|
ln -s '{{target}}' '{{path}}' || exit 1
|
|
|
|
]],
|
|
|
|
{ dirname = utils.dirname(link.path),
|
|
|
|
target = link.target, path = link.path }
|
|
|
|
)
|
|
|
|
end
|
2022-06-18 15:05:18 +00:00
|
|
|
add_file("/usr/local/bin/mount-data", string)
|
|
|
|
chmod("/usr/local/bin/mount-data", 700)
|
|
|
|
end
|
|
|
|
local function add_data_dir(path, mountpoint, uid, gid)
|
|
|
|
table.insert(dirs, {
|
|
|
|
type = "dir",
|
|
|
|
path = path, mountpoint = mountpoint, uid = uid, gid = gid
|
|
|
|
})
|
|
|
|
generate_mount_data()
|
|
|
|
end
|
|
|
|
local function add_data_file(path, mountpoint, uid, gid)
|
|
|
|
table.insert(dirs, {
|
|
|
|
type = "file",
|
|
|
|
path = path, mountpoint = mountpoint, uid = uid, gid = gid
|
|
|
|
})
|
|
|
|
generate_mount_data()
|
|
|
|
end
|
2022-06-19 00:29:00 +00:00
|
|
|
local function add_data_link(target, path)
|
|
|
|
table.insert(links, { target = target, path = path })
|
|
|
|
generate_mount_data()
|
|
|
|
end
|
2022-06-18 15:05:18 +00:00
|
|
|
|
|
|
|
modules.data = {
|
|
|
|
add_data_dir = add_data_dir,
|
|
|
|
add_data_file = add_data_file,
|
2022-06-19 00:29:00 +00:00
|
|
|
add_data_link = add_data_link,
|
2022-06-18 15:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mkdir("/data")
|
|
|
|
-- XXX: hardcodeado
|
|
|
|
modules.fstab.add_mount("/dev/sdb /data ext4 defaults 0 0")
|