luci-base: utils: Make checklib return a boolean
[project/luci.git] / modules / luci-base / luasrc / util.lua
index 5bf0beb..896e36b 100644 (file)
@@ -157,7 +157,7 @@ end
 -- command line parameter).
 function shellsqescape(value)
    local res
-   res, _ = string.gsub(res, "'", "'\\''")
+   res, _ = string.gsub(value, "'", "'\\''")
    return res
 end
 
@@ -636,6 +636,23 @@ function libpath()
        return require "nixio.fs".dirname(ldebug.__file__)
 end
 
+function checklib(fullpathexe, wantedlib)
+       local fs = require "nixio.fs"
+       local haveldd = fs.access('/usr/bin/ldd')
+       if not haveldd then
+               return false
+       end
+       local libs = exec("/usr/bin/ldd " .. fullpathexe)
+       if not libs then
+               return false
+       end
+       for k, v in ipairs(split(libs)) do
+               if v:find(wantedlib) then
+                       return true
+               end
+       end
+       return false
+end
 
 --
 -- Coroutine safe xpcall and pcall versions modified for Luci