op-packages/luci-app-hermes/luasrc/model/hermes.lua
github-actions[bot] 7804ca71a0 🐤 Sync 2026-04-19 08:30:38
2026-04-19 08:30:38 +08:00

39 lines
937 B
Lua

local util = require "luci.util"
local jsonc = require "luci.jsonc"
local hermes = {}
hermes.blocks = function()
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
local vals = {}
if f then
local ret = f:read("*all")
f:close()
local obj = jsonc.parse(ret)
if obj and obj["blockdevices"] then
for _, val in pairs(obj["blockdevices"]) do
local fsize = val["fssize"]
if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then
-- fsize > 1G
vals[#vals+1] = val["mountpoint"]
end
end
end
end
return vals
end
hermes.find_paths = function(blocks, subdir)
local configs = {}
local default_path = ''
for _, mountpoint in pairs(blocks) do
table.insert(configs, mountpoint .. "/hermes/" .. subdir)
end
if #configs > 0 then
default_path = configs[1]
end
return configs, default_path
end
return hermes