mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 05:25:13 +08:00
🦄 Sync 2026-07-04 08:36:24
This commit is contained in:
1 parent
a524ec1eaf
commit
37d8256bc3
18 files changed
+690
-546
No files matched your search
@@ -99,6 +99,17 @@ local function write_wechat_log_and_exit(log_file, exit_file, content, exit_code
|
||||
end
|
||||
end
|
||||
|
||||
local function wechat_python3_bootstrap_cmd(log_file)
|
||||
return "if ! command -v python3 >/dev/null 2>&1; then " ..
|
||||
"echo '未检测到 python3,正在尝试安装 python3-light...' >> " .. shellquote(log_file) .. "; " ..
|
||||
"(opkg update && opkg install python3-light) >> " .. shellquote(log_file) .. " 2>&1 || true; " ..
|
||||
"fi; " ..
|
||||
"if ! command -v python3 >/dev/null 2>&1; then " ..
|
||||
"echo '❌ python3-light 自动安装失败,请手动执行: opkg update && opkg install python3-light' >> " .. shellquote(log_file) .. "; " ..
|
||||
"echo 127 > /tmp/openclaw-wechat-install.exit; exit 0; " ..
|
||||
"fi; "
|
||||
end
|
||||
|
||||
function index()
|
||||
-- 主入口: 服务 → OpenClaw (🧠 作为菜单图标)
|
||||
local page = entry({"admin", "services", "openclaw"}, alias("admin", "services", "openclaw", "basic"), _("OpenClaw"), 90)
|
||||
@@ -808,10 +819,8 @@ function action_backup()
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local action = http.formvalue("action") or "create"
|
||||
|
||||
-- 获取安装路径
|
||||
local install_path_uci = uci:get("openclaw", "main", "install_path") or "/opt"
|
||||
-- 实际安装路径
|
||||
local install_path = install_path_uci .. "/openclaw"
|
||||
-- 使用统一路径 helper,兼容用户误填 /mnt/data/openclaw 的场景。
|
||||
local install_path = get_install_path()
|
||||
local node_bin = install_path .. "/node/bin/node"
|
||||
local oc_entry = ""
|
||||
|
||||
@@ -1326,17 +1335,6 @@ function action_wechat_install()
|
||||
http.write_json({ status = "ok", message = "微信插件安装已在后台启动..." })
|
||||
return
|
||||
end
|
||||
if sys.exec("command -v python3 2>/dev/null"):gsub("%s+", "") == "" then
|
||||
write_wechat_log_and_exit(
|
||||
"/tmp/openclaw-wechat-install.log",
|
||||
"/tmp/openclaw-wechat-install.exit",
|
||||
"开始安装微信插件...\n安装路径: " .. install_path .. "\n❌ 错误: 未检测到 python3。\n请先安装依赖: opkg update && opkg install python3\n",
|
||||
127
|
||||
)
|
||||
http.prepare_content("application/json")
|
||||
http.write_json({ status = "ok", message = "微信插件安装已在后台启动..." })
|
||||
return
|
||||
end
|
||||
if not ensure_openclaw_user(oc_data) then
|
||||
write_wechat_log_and_exit(
|
||||
"/tmp/openclaw-wechat-install.log",
|
||||
@@ -1360,6 +1358,7 @@ function action_wechat_install()
|
||||
"echo '开始安装微信插件...' > /tmp/openclaw-wechat-install.log; " ..
|
||||
"echo '安装路径: %s' >> /tmp/openclaw-wechat-install.log; " ..
|
||||
"echo 'npx 路径: %s' >> /tmp/openclaw-wechat-install.log; " ..
|
||||
wechat_python3_bootstrap_cmd("/tmp/openclaw-wechat-install.log") ..
|
||||
"mkdir -p %s/.npm %s/.tmp %s/.openclaw/extensions; " ..
|
||||
"if [ ! -w %s/.openclaw/extensions ]; then chown -R openclaw:openclaw %s/.openclaw/extensions 2>/dev/null; fi; " ..
|
||||
"chown -R openclaw:openclaw %s/.npm %s/.tmp %s/.openclaw 2>/dev/null; " ..
|
||||
@@ -1496,7 +1495,11 @@ function action_wechat_login()
|
||||
"( " ..
|
||||
"echo '正在启动微信登录...' > /tmp/openclaw-wechat-qrcode.txt; " ..
|
||||
"echo '安装路径: %s' >> /tmp/openclaw-wechat-qrcode.txt; " ..
|
||||
"mkdir -p %s/.npm %s/.tmp %s/.openclaw; chown -R openclaw:openclaw %s/.npm %s/.tmp %s/.openclaw 2>/dev/null; " ..
|
||||
"mkdir -p %s/.npm %s/.tmp %s/.openclaw/openclaw-weixin; " ..
|
||||
"touch %s/.openclaw/openclaw.json 2>/dev/null || true; " ..
|
||||
"chown -R openclaw:openclaw %s/.npm %s/.tmp %s/.openclaw/openclaw-weixin 2>/dev/null; " ..
|
||||
"chown openclaw:openclaw %s/.openclaw %s/.openclaw/openclaw.json 2>/dev/null; " ..
|
||||
"su -s /bin/sh openclaw -c 'test -w %s/.npm && test -w %s/.tmp && test -w %s/.openclaw && test -w %s/.openclaw/openclaw-weixin && test -w %s/.openclaw/openclaw.json' || { echo '❌ openclaw 用户无法写入微信登录目录,请检查数据目录权限' >> /tmp/openclaw-wechat-qrcode.txt; echo 1 > /tmp/openclaw-wechat-login.exit; exit 0; }; " ..
|
||||
"cd %s && " ..
|
||||
"su -s /bin/sh openclaw -c 'HOME=%s OPENCLAW_HOME=%s OPENCLAW_STATE_DIR=%s/.openclaw OPENCLAW_CONFIG_PATH=%s/.openclaw/openclaw.json " ..
|
||||
"NPM_CONFIG_CACHE=%s/.npm npm_config_cache=%s/.npm TMPDIR=%s/.tmp PATH=%s/node/bin:%s/global/bin:$PATH " ..
|
||||
@@ -1504,9 +1507,10 @@ function action_wechat_login()
|
||||
"echo $? > /tmp/openclaw-wechat-login.exit; " ..
|
||||
") >/dev/null 2>&1 & echo $! > /tmp/openclaw-wechat-login.pid",
|
||||
install_path,
|
||||
oc_data, oc_data, oc_data, oc_data, oc_data, oc_data,
|
||||
oc_data, oc_data, oc_data, oc_data, oc_data,
|
||||
oc_data, oc_data, oc_data, install_path, install_path, node_bin, oc_entry
|
||||
oc_data, oc_data, oc_data, oc_data, oc_data, oc_data, oc_data,
|
||||
oc_data, oc_data, oc_data, oc_data, oc_data, oc_data, oc_data,
|
||||
oc_data, oc_data, oc_data, oc_data, oc_data, oc_data, oc_data, oc_data,
|
||||
install_path, install_path, node_bin, oc_entry
|
||||
) sys.exec(login_cmd)
|
||||
|
||||
http.prepare_content("application/json")
|
||||
@@ -1594,34 +1598,59 @@ function action_wechat_uninstall()
|
||||
local sys = require "luci.sys"
|
||||
|
||||
local install_path = get_install_path()
|
||||
local node_bin = install_path .. "/node/bin/node"
|
||||
local oc_data = install_path .. "/data"
|
||||
|
||||
-- 删除微信插件目录
|
||||
local wechat_ext_dir = install_path .. "/data/.openclaw/extensions/openclaw-weixin"
|
||||
if wechat_ext_dir == install_path .. "/data/.openclaw/extensions/openclaw-weixin" then
|
||||
sys.exec("rm -rf " .. shellquote(wechat_ext_dir) .. " 2>/dev/null")
|
||||
-- 删除微信插件目录和账号状态。所有路径都限制在当前 OpenClaw 数据目录下。
|
||||
local wechat_ext_dir = oc_data .. "/.openclaw/extensions/openclaw-weixin"
|
||||
local wechat_state_dir = oc_data .. "/.openclaw/openclaw-weixin"
|
||||
local npm_projects = oc_data .. "/.openclaw/npm/projects"
|
||||
sys.exec("rm -rf " .. shellquote(wechat_ext_dir) .. " " .. shellquote(wechat_state_dir) .. " 2>/dev/null")
|
||||
if nixio.fs.stat(npm_projects, "type") then
|
||||
sys.exec("find " .. shellquote(npm_projects) .. " -path '*/node_modules/@tencent-weixin/openclaw-weixin' -type d -prune -exec rm -rf {} + 2>/dev/null")
|
||||
sys.exec("find " .. shellquote(npm_projects) .. " -path '*/node_modules/@tencent-weixin/openclaw-weixin-cli' -type d -prune -exec rm -rf {} + 2>/dev/null")
|
||||
end
|
||||
|
||||
-- 从配置中删除微信相关配置
|
||||
local config_file = install_path .. "/data/.openclaw/openclaw.json"
|
||||
local config_file = oc_data .. "/.openclaw/openclaw.json"
|
||||
if nixio.fs.stat(config_file, "type") then
|
||||
-- 读取配置
|
||||
local cf = io.open(config_file, "r")
|
||||
local content = ""
|
||||
if cf then
|
||||
content = cf:read("*a") or ""
|
||||
cf:close()
|
||||
end
|
||||
|
||||
-- 删除微信配置块 (简单字符串替换)
|
||||
content = content:gsub(',?%s*"openclaw%-weixin"%s*:%s*%b{}', "")
|
||||
content = content:gsub('"openclaw%-weixin"%s*:%s*%b{}%s*,?', "")
|
||||
|
||||
-- 写回配置
|
||||
local wf = io.open(config_file, "w")
|
||||
if wf then
|
||||
wf:write(content)
|
||||
wf:close()
|
||||
local cleanup_js = [[
|
||||
const fs = require('fs');
|
||||
const p = process.env.OC_CONFIG;
|
||||
let d = {};
|
||||
try { d = JSON.parse(fs.readFileSync(p, 'utf8')); } catch (e) { process.exit(0); }
|
||||
function drop(o, k) { if (o && typeof o === 'object') delete o[k]; }
|
||||
function dropChannel(o) { drop(o, 'openclaw-weixin'); drop(o, 'weixin'); }
|
||||
if (d.plugins && Array.isArray(d.plugins.allow)) {
|
||||
d.plugins.allow = d.plugins.allow.filter((x) => x !== 'openclaw-weixin' && x !== 'weixin');
|
||||
}
|
||||
if (d.plugins) {
|
||||
dropChannel(d.plugins.installs);
|
||||
dropChannel(d.plugins.entries);
|
||||
}
|
||||
dropChannel(d.channels);
|
||||
dropChannel(d.channel);
|
||||
dropChannel(d);
|
||||
fs.writeFileSync(p, JSON.stringify(d, null, 2));
|
||||
]]
|
||||
if nixio.fs.stat(node_bin, "type") then
|
||||
sys.exec("OC_CONFIG=" .. shellquote(config_file) .. " " .. shellquote(node_bin) .. " -e " .. shellquote(cleanup_js) .. " 2>/dev/null")
|
||||
else
|
||||
local cf = io.open(config_file, "r")
|
||||
local content = ""
|
||||
if cf then
|
||||
content = cf:read("*a") or ""
|
||||
cf:close()
|
||||
end
|
||||
content = content:gsub(',?%s*"openclaw%-weixin"%s*:%s*%b{}', "")
|
||||
content = content:gsub('"openclaw%-weixin"%s*:%s*%b{}%s*,?', "")
|
||||
local wf = io.open(config_file, "w")
|
||||
if wf then
|
||||
wf:write(content)
|
||||
wf:close()
|
||||
end
|
||||
end
|
||||
sys.exec("chown openclaw:openclaw " .. shellquote(config_file) .. " 2>/dev/null")
|
||||
end
|
||||
|
||||
-- 清理临时文件
|
||||
@@ -1717,17 +1746,6 @@ function action_wechat_upgrade_plugin()
|
||||
http.write_json({ status = "ok", message = "微信插件升级已在后台启动..." })
|
||||
return
|
||||
end
|
||||
if sys.exec("command -v python3 2>/dev/null"):gsub("%s+", "") == "" then
|
||||
write_wechat_log_and_exit(
|
||||
"/tmp/openclaw-wechat-install.log",
|
||||
"/tmp/openclaw-wechat-install.exit",
|
||||
"正在升级微信插件...\n安装路径: " .. install_path .. "\n❌ 错误: 未检测到 python3。\n请先安装依赖: opkg update && opkg install python3\n",
|
||||
127
|
||||
)
|
||||
http.prepare_content("application/json")
|
||||
http.write_json({ status = "ok", message = "微信插件升级已在后台启动..." })
|
||||
return
|
||||
end
|
||||
if not ensure_openclaw_user(oc_data) then
|
||||
write_wechat_log_and_exit(
|
||||
"/tmp/openclaw-wechat-install.log",
|
||||
@@ -1751,6 +1769,7 @@ function action_wechat_upgrade_plugin()
|
||||
"echo '正在升级微信插件...' > /tmp/openclaw-wechat-install.log; " ..
|
||||
"echo '安装路径: %s' >> /tmp/openclaw-wechat-install.log; " ..
|
||||
"echo 'npx 路径: %s' >> /tmp/openclaw-wechat-install.log; " ..
|
||||
wechat_python3_bootstrap_cmd("/tmp/openclaw-wechat-install.log") ..
|
||||
"mkdir -p %s/.npm %s/.tmp %s/.openclaw/extensions; " ..
|
||||
"if [ ! -w %s/.openclaw/extensions ]; then chown -R openclaw:openclaw %s/.openclaw/extensions 2>/dev/null; fi; " ..
|
||||
"chown -R openclaw:openclaw %s/.npm %s/.tmp %s/.openclaw 2>/dev/null; " ..
|
||||
|
||||
Reference in new issue
Block a user