2 FFLuCI - 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("ffluci.model.ipkg", package.seeall)
30 require("ffluci.util")
33 local statuslist = nil
35 -- Returns repository information
40 -- Returns a table with status information
41 function status(refresh)
42 if not statuslist or refresh then
43 statuslist = _parselist(ffluci.sys.exec(ipkg .. " status"))
55 local c = ipkg .. " install '" .. pkg:gsub("'", "") .. "' >/dev/null 2>&1"
56 local r = os.execute(c)
60 function installed(pkg, ...)
61 local p = status(...)[pkg]
62 return (p and p.Status and p.Status.installed)
65 function _parselist(rawdata)
66 if type(rawdata) ~= "string" then
67 error("IPKG: Invalid rawdata given")
70 rawdata = ffluci.util.split(rawdata)
75 for k, line in pairs(rawdata) do
76 if line:sub(1, 1) ~= " " then
77 local split = ffluci.util.split(line, ":", 1)
82 key = ffluci.util.trim(split[1])
86 val = ffluci.util.trim(split[2])
90 if key == "Package" then
93 elseif key == "Status" then
95 for i, j in pairs(ffluci.util.split(val, " ")) do
105 c[l] = c[l] .. "\n" .. line:sub(2)