* Updated IPKG model
This commit is contained in:
parent
f2fc9438a2
commit
e4c7d9b596
1 changed files with 53 additions and 17 deletions
|
@ -30,38 +30,74 @@ require("ffluci.sys")
|
||||||
require("ffluci.util")
|
require("ffluci.util")
|
||||||
|
|
||||||
ipkg = "ipkg"
|
ipkg = "ipkg"
|
||||||
local statuslist = nil
|
|
||||||
|
|
||||||
-- Returns repository information
|
-- Returns repository information
|
||||||
function info(pkg)
|
function info(pkg)
|
||||||
-- To be implemented
|
return _lookup("info", pkg)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns a table with status information
|
-- Returns a table with status information
|
||||||
function status(refresh)
|
function status(pkg)
|
||||||
if not statuslist or refresh then
|
return _lookup("status", pkg)
|
||||||
statuslist = _parselist(ffluci.sys.exec(ipkg .. " status"))
|
|
||||||
end
|
|
||||||
|
|
||||||
return statuslist
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Installs a package
|
-- Installs packages
|
||||||
function install(pkg)
|
function install(...)
|
||||||
if not pkg then
|
return _action("install", ...)
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local c = ipkg .. " install '" .. pkg:gsub("'", "") .. "' >/dev/null 2>&1"
|
|
||||||
local r = os.execute(c)
|
|
||||||
return (r == 0), r
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns whether a package is installed
|
||||||
function installed(pkg, ...)
|
function installed(pkg, ...)
|
||||||
local p = status(...)[pkg]
|
local p = status(...)[pkg]
|
||||||
return (p and p.Status and p.Status.installed)
|
return (p and p.Status and p.Status.installed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Removes packages
|
||||||
|
function remove(...)
|
||||||
|
return _action("remove", ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Updates package lists
|
||||||
|
function update()
|
||||||
|
return _action("update")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Upgrades installed packages
|
||||||
|
function upgrade()
|
||||||
|
return _action("upgrade")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Internal action function
|
||||||
|
function _action(cmd, ...)
|
||||||
|
local pkg = ""
|
||||||
|
arg.n = nil
|
||||||
|
for k, v in pairs(arg) do
|
||||||
|
pkg = pkg .. " '" .. v:gsub("'", "") .. "'"
|
||||||
|
end
|
||||||
|
|
||||||
|
local c = ipkg.." "..cmd.." "..pkg.." >/dev/null 2>&1"
|
||||||
|
local r = os.execute(c)
|
||||||
|
return (r == 0), r
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Internal lookup function
|
||||||
|
function _lookup(act, pkg)
|
||||||
|
local cmd = ipkg .. " " .. act
|
||||||
|
if pkg then
|
||||||
|
cmd = cmd .. " '" .. pkg:gsub("'", "") .. "'"
|
||||||
|
end
|
||||||
|
|
||||||
|
local info = _parselist(ffluci.sys.exec(cmd .. " 2>/dev/null"))
|
||||||
|
|
||||||
|
if pkg then
|
||||||
|
return info[pkg]
|
||||||
|
else
|
||||||
|
return info
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Internal parser function
|
||||||
function _parselist(rawdata)
|
function _parselist(rawdata)
|
||||||
if type(rawdata) ~= "string" then
|
if type(rawdata) ~= "string" then
|
||||||
error("IPKG: Invalid rawdata given")
|
error("IPKG: Invalid rawdata given")
|
||||||
|
|
Loading…
Reference in a new issue