2013-04-08 01:20:45 +02:00
|
|
|
local uci = require("uci").cursor()
|
|
|
|
|
2013-04-04 10:18:08 +02:00
|
|
|
local M = {}
|
|
|
|
|
2013-07-11 10:30:59 +02:00
|
|
|
function string:split(sep)
|
|
|
|
local sep, fields = sep or ":", {}
|
|
|
|
local pattern = string.format("([^%s]+)", sep)
|
|
|
|
self:gsub(pattern, function(c) fields[#fields+1] = c end)
|
|
|
|
return fields
|
|
|
|
end
|
|
|
|
|
2013-07-08 16:53:45 +02:00
|
|
|
function M.toboolean(s)
|
|
|
|
if not s then return false end
|
|
|
|
|
|
|
|
local b = s:lower()
|
|
|
|
return (b == "1" or b == "t" or b == "true") and true or false
|
|
|
|
end
|
|
|
|
|
2013-04-08 01:20:45 +02:00
|
|
|
function M.getUciSectionName(config, type)
|
|
|
|
local sname = nil
|
|
|
|
uci:foreach(config, type, function(s) sname = s[".name"] end)
|
|
|
|
return sname
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.exists(file)
|
|
|
|
local r = io.open(file) --ignore returned message
|
|
|
|
if r ~= nil then io.close(r) end
|
|
|
|
return r ~= nil
|
|
|
|
end
|
|
|
|
|
2013-06-30 19:06:55 +02:00
|
|
|
--FIXME: somehow protect this function from running arbitrary commands
|
2013-04-08 01:20:45 +02:00
|
|
|
function M.symlink(from, to)
|
|
|
|
if from == nil or from == "" or to == nil or to == "" then return -1 end
|
|
|
|
local x = "ln -s " .. from .. " " .. to
|
|
|
|
return os.execute(x)
|
|
|
|
end
|
|
|
|
|
2013-04-04 10:18:08 +02:00
|
|
|
return M
|