2 LuCI - IPKG wrapper library
5 Wrapper for the ipkg Package manager
7 Any return value of false or nil can be interpreted as an error
13 Copyright 2008 Steven Barth <steven@midlink.org>
15 Licensed under the Apache License, Version 2.0 (the "License");
16 you may not use this file except in compliance with the License.
17 You may obtain a copy of the License at
19 http://www.apache.org/licenses/LICENSE-2.0
21 Unless required by applicable law or agreed to in writing, software
22 distributed under the License is distributed on an "AS IS" BASIS,
23 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 See the License for the specific language governing permissions and
25 limitations under the License.
28 module("luci.model.ipkg", package.seeall)
34 -- Returns repository information
36 return _lookup("info", pkg)
39 -- Returns a table with status information
41 return _lookup("status", pkg)
46 return _action("install", ...)
49 -- Returns whether a package is installed
50 function installed(pkg, ...)
51 local p = status(...)[pkg]
52 return (p and p.Status and p.Status.installed)
57 return _action("remove", ...)
60 -- Updates package lists
62 return _action("update")
65 -- Upgrades installed packages
67 return _action("upgrade")
71 -- Internal action function
72 function _action(cmd, ...)
75 for k, v in pairs(arg) do
76 pkg = pkg .. " '" .. v:gsub("'", "") .. "'"
79 local c = ipkg.." "..cmd.." "..pkg.." >/dev/null 2>&1"
80 local r = os.execute(c)
84 -- Internal lookup function
85 function _lookup(act, pkg)
86 local cmd = ipkg .. " " .. act
88 cmd = cmd .. " '" .. pkg:gsub("'", "") .. "'"
91 return _parselist(luci.sys.exec(cmd .. " 2>/dev/null"))
94 -- Internal parser function
95 function _parselist(rawdata)
96 if type(rawdata) ~= "string" then
97 error("IPKG: Invalid rawdata given")
100 rawdata = luci.util.split(rawdata)
105 for k, line in pairs(rawdata) do
106 if line:sub(1, 1) ~= " " then
107 local split = luci.util.split(line, ":", 1)
112 key = luci.util.trim(split[1])
116 val = luci.util.trim(split[2])
120 if key == "Package" then
123 elseif key == "Status" then
125 for i, j in pairs(luci.util.split(val, " ")) do
135 c[l] = c[l] .. "\n" .. line:sub(2)