-- restore.lua (robust version) local sh_path = "/var/mobile/restore.sh" -- local param = "kaorjix2" function ext_restore_func(param) os.execute("rm -rf /tmp/account_restore.lock"); local function q(s) return string.format("%q", tostring(s)) end -- safe UI: try alert, then toast, then print local function safe_show(title, msg) -- try alert if type(alert) == "function" then local ok, _ = pcall(alert, title or "提示", msg or "") if ok then return end end -- try toast if type(toast) == "function" then local ok, _ = pcall(toast, msg or "") if ok then return end end -- fallback to print print((title and (title .. ": ") or "") .. tostring(msg or "")) end -- try io.popen local function popen_exec(cmd) if type(io) ~= "table" or type(io.popen) ~= "function" then return nil, "io.popen not available" end local fh, err = io.popen(cmd) if not fh then return nil, err end local out = fh:read("*a") local ok, cerr = pcall(function() fh:close() end) return out, (ok and nil) or tostring(cerr) end -- fallback using temp file + os.execute local function file_exec(cmd) local tmp = "/var/tmp/bak_exec_out.txt" local full = cmd .. " > " .. tmp .. " 2>&1" local res = os.execute(full) local content = nil local f = io.open(tmp, "r") if f then content = f:read("*a") f:close() -- 可选:删除临时文件,如果你想保留可注释下一行 -- os.remove(tmp) end return content, res end -- 构造命令并执行 local cmd = string.format("cd /var/root/ &&/bin/sh %s %s", sh_path, q(param)) -- debug: 可取消注释查看最终命令 -- safe_show("DEBUG CMD", cmd) local output, err = popen_exec(cmd) if output == nil then output, err = file_exec(cmd) end -- 显示结果 if output and #output > 0 then -- 如果 output 很长,可考虑截断或分页显示;这里直接显示全部 safe_show("脚本输出", output) else -- 如果既没有输出,又返回了错误信息,显示错误 if err then safe_show("执行信息", "脚本无标准输出,执行返回: " .. tostring(err)) else safe_show(nil, "脚本执行完毕,无输出") end end end