From 3cbdd15b50c032d576eb3d5b0695a7e99bd0be79 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:25:37 +0800 Subject: [PATCH] luci: fix sing-box app update --- luci-app-passwall/luasrc/passwall/api.lua | 40 ++++++++++++++++++----- luci-app-passwall/luasrc/passwall/com.lua | 1 + luci-app-passwall/po/zh-cn/passwall.po | 4 +-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index 06072d9bf..dfb5cda2c 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -814,12 +814,23 @@ function to_extract(app_name, file, subfix) return {code = 1, error = i18n.translate("File path required.")} end - if sys.exec("echo -n $(opkg list-installed | grep -c unzip)") ~= "1" then - exec("/bin/rm", {"-f", file}) - return { - code = 1, - error = i18n.translate("Not installed unzip, Can't unzip!") - } + local tools_name + if com[app_name].zipped then + if not com[app_name].zipped_suffix or com[app_name].zipped_suffix == "zip" then + tools_name = "unzip" + end + if com[app_name].zipped_suffix and com[app_name].zipped_suffix == "tar.gz" then + tools_name = "tar" + end + if tools_name then + if sys.exec("echo -n $(command -v %s)" % { tools_name }) == "" then + exec("/bin/rm", {"-f", file}) + return { + code = 1, + error = i18n.translate("Not installed %s, Can't unzip!" % { tools_name }) + } + end + end end sys.call("/bin/rm -rf /tmp/".. app_name .."_extract.*") @@ -833,8 +844,19 @@ function to_extract(app_name, file, subfix) local tmp_dir = util.trim(util.exec("mktemp -d -t ".. app_name .."_extract.XXXXXX")) local output = {} - exec("/usr/bin/unzip", {"-o", file, app_name, "-d", tmp_dir}, - function(chunk) output[#output + 1] = chunk end) + + if tools_name then + if tools_name == "unzip" then + local bin = sys.exec("echo -n $(command -v unzip)") + exec(bin, {"-o", file, app_name, "-d", tmp_dir}, function(chunk) output[#output + 1] = chunk end) + elseif tools_name == "tar" then + local bin = sys.exec("echo -n $(command -v tar)") + if com[app_name].zipped_suffix == "tar.gz" then + exec(bin, {"-zxf", file, "-C", tmp_dir}, function(chunk) output[#output + 1] = chunk end) + sys.call("/bin/mv -f " .. tmp_dir .. "/*/" .. com[app_name].name:lower() .. " " .. tmp_dir) + end + end + end local files = util.split(table.concat(output)) @@ -853,7 +875,7 @@ function to_move(app_name,file) local bin_path = file local cmd_rm_tmp = "/bin/rm -rf /tmp/" .. app_name .. "_download.*" if fs.stat(file, "type") == "dir" then - bin_path = file .. "/" .. app_name + bin_path = file .. "/" .. com[app_name].name:lower() cmd_rm_tmp = "/bin/rm -rf /tmp/" .. app_name .. "_extract.*" end diff --git a/luci-app-passwall/luasrc/passwall/com.lua b/luci-app-passwall/luasrc/passwall/com.lua index b298f2546..a7f33c885 100644 --- a/luci-app-passwall/luasrc/passwall/com.lua +++ b/luci-app-passwall/luasrc/passwall/com.lua @@ -55,6 +55,7 @@ _M.singbox = { get_url = gh_pre_release_url, cmd_version = "version | awk '{print $3}' | sed -n 1P", zipped = true, + zipped_suffix = "tar.gz", default_path = "/usr/bin/sing-box", match_fmt_str = "linux%%-%s", file_tree = { diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index eff910ab5..7d4e8b605 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -1372,8 +1372,8 @@ msgstr "无" msgid "You did not fill in the %s path. Please save and apply then update manually." msgstr "您没有填写 %s 路径。请保存应用后再手动更新。" -msgid "Not installed unzip, Can't unzip!" -msgstr "未安装unzip,无法解压。" +msgid "Not installed %s, Can't unzip!" +msgstr "未安装 %s,无法解压!" msgid "Can't determine ARCH, or ARCH not supported." msgstr "无法确认ARCH架构,或是不支持。"