X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fipkg%2Fluasrc%2Fmodel%2Fipkg.lua;h=d0d9788fd8be6c861a74aaead8ec23a06026608c;hb=f83cdb1b8bff33f47867af8941d4aabcda1575f4;hp=607c3638ed8dae32827292b05e8571a57a8e53a5;hpb=8338e5e8f5984b99add8bd30d0060e44bcdb915f;p=project%2Fluci.git diff --git a/libs/ipkg/luasrc/model/ipkg.lua b/libs/ipkg/luasrc/model/ipkg.lua index 607c3638e..d0d9788fd 100644 --- a/libs/ipkg/luasrc/model/ipkg.lua +++ b/libs/ipkg/luasrc/model/ipkg.lua @@ -1,7 +1,7 @@ --[[ LuCI - Lua Configuration Interface -(c) 2008 Jo-Philipp Wich +(c) 2008-2011 Jo-Philipp Wich (c) 2008 Steven Barth Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +15,7 @@ $Id$ local os = require "os" local io = require "io" +local fs = require "nixio.fs" local util = require "luci.util" local type = type @@ -22,9 +23,10 @@ local pairs = pairs local error = error local table = table -local ipkg = "opkg" +local ipkg = "opkg --force-removal-of-dependent-packages --force-overwrite" +local icfg = "/etc/opkg.conf" ---- LuCI IPKG/OPKG call abstraction library +--- LuCI OPKG call abstraction library module "luci.model.ipkg" @@ -35,15 +37,21 @@ local function _action(cmd, ...) pkg = pkg .. " '" .. v:gsub("'", "") .. "'" end - local c = ipkg.." "..cmd.." "..pkg.." >/dev/null 2>&1" + local c = "%s %s %s >/tmp/opkg.stdout 2>/tmp/opkg.stderr" %{ ipkg, cmd, pkg } local r = os.execute(c) - return (r == 0), r + local e = fs.readfile("/tmp/opkg.stderr") + local o = fs.readfile("/tmp/opkg.stdout") + + fs.unlink("/tmp/opkg.stderr") + fs.unlink("/tmp/opkg.stdout") + + return r, o or "", e or "" end -- Internal parser function local function _parselist(rawdata) if type(rawdata) ~= "function" then - error("IPKG: Invalid rawdata given") + error("OPKG: Invalid rawdata given") end local data = {} @@ -84,7 +92,7 @@ local function _lookup(act, pkg) cmd = cmd .. " '" .. pkg:gsub("'", "") .. "'" end - -- IPKG sometimes kills the whole machine because it sucks + -- OPKG sometimes kills the whole machine because it sucks -- Therefore we have to use a sucky approach too and use -- tmpfiles instead of directly reading the output local tmpfile = os.tmpname() @@ -113,7 +121,7 @@ end --- Install one or more packages. -- @param ... List of packages to install -- @return Boolean indicating the status of the action --- @return IPKG return code +-- @return OPKG return code, STDOUT and STDERR function install(...) return _action("install", ...) end @@ -129,28 +137,30 @@ end --- Remove one or more packages. -- @param ... List of packages to install -- @return Boolean indicating the status of the action --- @return IPKG return code +-- @return OPKG return code, STDOUT and STDERR function remove(...) return _action("remove", ...) end --- Update package lists. -- @return Boolean indicating the status of the action --- @return IPKG return code +-- @return OPKG return code, STDOUT and STDERR function update() return _action("update") end --- Upgrades all installed packages. -- @return Boolean indicating the status of the action --- @return IPKG return code +-- @return OPKG return code, STDOUT and STDERR function upgrade() return _action("upgrade") end -- List helper function _list(action, pat, cb) - local fd = io.popen(ipkg .. " " .. action .. (pat and " '*" .. pat:gsub("'", "") .. "*'" or "")) + local fd = io.popen(ipkg .. " " .. action .. + (pat and (" '%s'" % pat:gsub("'", "")) or "")) -- .. " | grep -vE '^ '") + if fd then local name, version, desc while true do @@ -192,3 +202,32 @@ end function list_installed(pat, cb) _list("list_installed", pat, cb) end + +--- Determines the overlay root used by opkg. +-- @return String containing the directory path of the overlay root. +function overlay_root() + local od = "/" + local fd = io.open(icfg, "r") + + if fd then + local ln + + repeat + ln = fd:read("*l") + if ln and ln:match("^%s*option%s+overlay_root%s+") then + od = ln:match("^%s*option%s+overlay_root%s+(%S+)") + + local s = fs.stat(od) + if not s or s.type ~= "dir" then + od = "/" + end + + break + end + until not ln + + fd:close() + end + + return od +end