+
+function getPackageVersion()
+ local opkgFile = "/usr/lib/opkg/status"
+ local line
+ local flag = false
+ for line in io.lines(opkgFile) do
+ if flag then
+ return line:match('[%d%.$-]+') or ""
+ elseif line:find("Package: " .. packageName:gsub("%-", "%%%-")) then
+ flag = true
+ end
+ end
+ return ""
+end
+
+function getFileLines(file)
+ local f = io.open(file)
+ if f then
+ local t = f:read("*a")
+ local _,n = t:gsub("\n","")
+ f:close()
+ return n
+ else
+ return "0"
+ end
+end
+
+function checkDnsmasq() return fs.access("/usr/sbin/dnsmasq") end
+function checkUnbound() return fs.access("/usr/sbin/unbound") end
+function checkIpset()
+ if fs.access("/usr/sbin/ipset") and sys.call("/usr/sbin/ipset help hash:net >/dev/null 2>&1") == 0 then
+ return true
+ else
+ return false
+ end
+end
+
+function checkDnsmasqIpset()
+ if checkDnsmasq() then
+ local o = util.trim(util.exec("/usr/sbin/dnsmasq -v 2>/dev/null"))
+ if not o:match("no%-ipset") and o:match("ipset") and checkIpset() then
+ return true
+ else
+ return false
+ end
+ else
+ return false
+ end
+end
+