diff --git a/openwrt/files/luci/model/cbi/ua3f/utils.lua b/openwrt/files/luci/model/cbi/ua3f/utils.lua index 6f64f1a..7bd3378 100644 --- a/openwrt/files/luci/model/cbi/ua3f/utils.lua +++ b/openwrt/files/luci/model/cbi/ua3f/utils.lua @@ -6,16 +6,30 @@ local function cmd_exists(cmd) return sys.call("command -v " .. cmd .. " >/dev/null 2>&1") == 0 end +local function opkg_installed(pkg) + if not cmd_exists("opkg") then return false end + local output = sys.exec("opkg list-installed " .. pkg .. " 2>&1") + if output:find(pkg, 1, true) then + return true + end + if output:find("Could not lock /var/lock/opkg.lock", 1, true) then + return true + end + return false +end + +local function apk_installed(pkg) + if not cmd_exists("apk") then return false end + local output = sys.exec("apk info | grep " .. pkg .. " 2>&1") + return output:find(pkg, 1, true) ~= nil +end + function M.nfqueue_exists() - local opkg = cmd_exists("opkg") and sys.call("opkg list-installed kmod-nft-queue | grep -q kmod-nft-queue") == 0 - local apk = cmd_exists("apk") and (sys.call("apk info | grep -q kmod-nft-queue") == 0) - return opkg or apk + return opkg_installed("kmod-nft-queue") or apk_installed("kmod-nft-queue") end function M.tproxy_exists() - local opkg = cmd_exists("opkg") and sys.call("opkg list-installed kmod-nft-tproxy | grep -q kmod-nft-tproxy") == 0 - local apk = cmd_exists("apk") and (sys.call("apk info | grep -q kmod-nft-tproxy") == 0) - return opkg or apk + return opkg_installed("kmod-nft-tproxy") or apk_installed("kmod-nft-tproxy") end function M.offloading_enabled()