return value and tparser.striptags(tostring(value))
end
+-- for bash, ash and similar shells single-quoted strings are taken
+-- literally except for single quotes (which terminate the string)
+-- (and the exception noted below for dash (-) at the start of a
+-- command line parameter).
+function shellsqescape(value)
+ local res
+ res, _ = string.gsub(value, "'", "'\\''")
+ return res
+end
+
+-- bash, ash and other similar shells interpret a dash (-) at the start
+-- of a command-line parameters as an option indicator regardless of
+-- whether it is inside a single-quoted string. It must be backlash
+-- escaped to resolve this. This requires in some funky special-case
+-- handling. It may actually be a property of the getopt function
+-- rather than the shell proper.
+function shellstartsqescape(value)
+ res, _ = string.gsub(value, "^\-", "\\-")
+ res, _ = string.gsub(res, "^-", "\-")
+ return shellsqescape(value)
+end
+
-- containing the resulting substrings. The optional max parameter specifies
-- the number of bytes to process, regardless of the actual length of the given
-- string. The optional last parameter, regex, specifies whether the separator
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 -1
+ end
+ local libs = exec("/usr/bin/ldd " .. fullpathexe)
+ if not libs then
+ return 0
+ end
+ for k, v in ipairs(split(libs)) do
+ if v:find(wantedlib) then
+ return 1
+ end
+ end
+ return 0
+end
--
-- Coroutine safe xpcall and pcall versions modified for Luci