2013-04-08 01:20:45 +02:00
|
|
|
local uci = require("uci").cursor()
|
|
|
|
|
2013-04-04 10:18:08 +02:00
|
|
|
local M = {}
|
|
|
|
|
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
|