
#!/bin/bash# OpenClaw 管理脚本 - 数组选择版本set-e# 颜色定义RED\033[0;31mGREEN\033[0;32mYELLOW\033[1;33mBLUE\033[0;34mCYAN\033[0;36mNC\033[0m# No Color# 定义菜单数组menu_items(启动 OpenClaw (onboard)登录微信渠道打开仪表板显示版本信息运行诊断 (doctor)启动网关 (gateway)更新 OpenClaw停止 OpenClaw查看运行状态退出)# 定义对应的命令数组commands(start_openclawlogin_wechatshow_dashboardshow_versionrun_doctorstart_gatewayupdate_openclawstop_openclawcheck_statusexit_program)# 打印带颜色的消息print_info(){echo-e${GREEN}[INFO]${NC}$1}print_error(){echo-e${RED}[ERROR]${NC}$1}print_warning(){echo-e${YELLOW}[WARNING]${NC}$1}print_title(){echo-e${BLUE}${NC}echo-e${BLUE}$1${NC}echo-e${BLUE}${NC}}# 显示菜单show_menu(){clearecho-e${CYAN}echo╔══════════════════════════════════════╗echo║ OpenClaw 管理工具 v1.0 ║echo╚══════════════════════════════════════╝echo-e${NC}foriin${!menu_items[]};doprintf${GREEN}[%2d]${NC}%s\n$((i1))${menu_items[$i]}doneechoecho-e${YELLOW}请选择操作 [1-${#menu_items[]}]:${NC}}# 启动 OpenClawstart_openclaw(){print_title启动 OpenClawifpgrep-fopenclaw onboard/dev/null;thenprint_warningOpenClaw 已经在运行中returnfiprint_info启动 onboard...openclaw onboardsleep2ifpgrep-fopenclaw onboard/dev/null;thenprint_info✓ OpenClaw 启动成功elseprint_errorOpenClaw 启动失败fi}# 停止 OpenClawstop_openclaw(){print_title停止 OpenClawif!pgrep-fopenclaw/dev/null;thenprint_warningOpenClaw 未运行returnfiprint_info停止所有 OpenClaw 进程...pkill-fopenclawprint_info✓ OpenClaw 已停止||print_warning停止进程时出错}# 查看状态check_status(){print_titleOpenClaw 状态ifpgrep-fopenclaw/dev/null;thenprint_info✓ OpenClaw 正在运行echoprint_info运行中的进程:echo-e${CYAN}pgrep-afopenclaw|whilereadline;doecho •$linedoneecho-e${NC}elseprint_warning✗ OpenClaw 未运行fi}# 登录微信login_wechat(){print_title登录 OpenClaw 微信渠道print_info正在登录微信...echo-e${YELLOW}请扫描二维码完成登录...${NC}echoifopenclaw channels login--channelopenclaw-weixin;thenprint_info✓ 微信登录成功elseprint_error✗ 微信登录失败fiechoread-p按回车键继续...}# 打开仪表板show_dashboard(){print_titleOpenClaw 仪表板print_info启动仪表板 (按 CtrlC 退出)...echoopenclaw dashboard}# 显示版本show_version(){print_titleOpenClaw 版本信息echo-e${CYAN}openclaw--versionecho-e${NC}echoread-p按回车键继续...}# 运行诊断run_doctor(){print_titleOpenClaw 诊断echo-e${CYAN}openclaw doctorecho-e${NC}echoread-p按回车键继续...}# 启动网关start_gateway(){print_title启动 OpenClaw 网关ifpgrep-fopenclaw gateway/dev/null;thenprint_warning网关已经在运行中returnfiprint_info正在启动网关...openclaw gatewaysleep2ifpgrep-fopenclaw gateway/dev/null;thenprint_info✓ 网关启动成功elseprint_error网关启动失败fi}# 更新 OpenClawupdate_openclaw(){print_title更新 OpenClawecho-e${YELLOW}即将更新 OpenClaw 到最新版本...${NC}read-p确认更新? [y/N]: confirmif[[!$confirm~^[Yy]$]];thenprint_warning已取消更新returnfiprint_info正在检查更新...# 备份当前版本信息localold_version$(openclaw--version2/dev/null||echo未知)# 尝试不同的更新方法localupdate_successfalseifcommand-vnpm/dev/null;thenprint_info使用 npm 更新...ifnpmupdate-gopenclaw2/dev/null;thenupdate_successtruefifiif!$update_successcommand-vpip/dev/null;thenprint_info使用 pip 更新...ifpipinstall--upgradeopenclaw2/dev/null;thenupdate_successtruefifiif!$update_success;thenprint_error自动更新失败请手动更新returnfiprint_info✓ 更新完成# 显示新版本localnew_version$(openclaw--version2/dev/null||echo未知)print_info版本变化:$old_version→$new_versionechoread-p按回车键继续...}# 退出程序exit_program(){print_info感谢使用 OpenClaw 管理工具exit0}# 执行命令execute_command(){localchoice$1localcmd${commands[$((choice-1))]}if[[-n$cmd$cmd!exit_program]];thenecho$cmdechoif[[$cmd!show_dashboard$cmd!start_gateway$cmd!start_openclaw]];thenread-p按回车键继续...fielif[[$cmdexit_program]];then$cmdfi}# 验证输入validate_choice(){localchoice$1if[[$choice~^[0-9]$]][$choice-ge1][$choice-le${#menu_items[]}];thenreturn0elsereturn1fi}# 主循环main_loop(){whiletrue;doshow_menuread-rchoiceifvalidate_choice$choice;thenexecute_command$choiceif[[${commands[$((choice-1))]}exit_program]];thenbreakfielseprint_error无效选择请输入 1-${#menu_items[]}之间的数字sleep1fidone}# 检查 openclaw 是否安装check_openclaw(){if!command-vopenclaw/dev/null;thenprint_errorOpenClaw 未安装print_info请先安装 OpenClaw: npm install -g openclawexit1fi}# 捕获 CtrlCtrapecho ; print_warning 按 CtrlC 退出; exit_programINT# 运行主程序check_openclaw main_loop使用说明保存脚本nanoopenclaw_manager.shchmodx openclaw_manager.sh运行脚本./openclaw_manager.sh特性✅数组驱动菜单所有菜单项和命令都存储在数组中✅数字选择输入对应的数字即可选择功能✅彩色界面清晰的视觉反馈✅循环菜单执行完操作后自动返回主菜单✅输入验证只接受有效的数字输入✅状态检查执行前检查 OpenClaw 是否已安装✅优雅退出支持 CtrlC 和菜单退出扩展菜单示例如果需要添加新功能只需在数组中添加# 在 menu_items 数组添加menu_items(...新功能描述# 添加这行)# 在 commands 数组添加对应的函数名commands(...new_function# 添加这行)# 然后实现对应的函数new_function(){print_title新功能# 你的代码}这里为啥选择微信呢不用下载飞书配置那么麻烦微信扫码就行啦飞书还有周限制api调用凭证本人已经弃用飞书。安装插件openclaw pluginsinstalltencent-weixin/openclaw-weixin启用插件openclaw configsetplugins.entries.openclaw-weixin.enabledtrue重启网关openclaw gateway restart三、重新绑定微信账号安装并启用新插件后需要重新登录微信以完成绑定。在终端输入以下命令获取登录二维码openclaw channels login--channelopenclaw-weixin