v4: 入口即菜单(仿 kejilion),11 项管理选项;安装改为菜单选 1;修重复文案

This commit is contained in:
2026-08-10 06:54:12 +00:00
parent 7f4a38494b
commit a244a5a425
+134 -32
View File
@@ -627,7 +627,7 @@ wizard_provider() {
# API Key
while true; do
ask_secret " API Key(输入不显示,直接回车可跳过)"
ask_secret " API Key"
CFG_APIKEY="$REPLY_VALUE"
if [ -z "$CFG_APIKEY" ]; then
warn " 未填写 API Key,模型将无法调用。"
@@ -1142,26 +1142,10 @@ do_restart() {
fi
}
main() {
init_log "$@"
# --menu:管理模式(由 claw 命令调用),不重装,只改配置/启停
for a in "$@"; do
if [ "$a" = "--menu" ]; then
plain ""
plain "${C_BOLD}OpenClaw 管理工具 v${SCRIPT_VERSION}${C_RESET}"
if ! command -v openclaw >/dev/null 2>&1; then
die "未检测到 OpenClaw,请先执行安装:" "bash <(curl -sL https://mjjtop.com/claw)"
fi
menu_mode
exit 0
fi
done
plain ""
plain "${C_BOLD}OpenClaw 一键安装配置脚本 v${SCRIPT_VERSION}${C_RESET}"
plain "日志:${LOG_FILE}"
# ---------------------------------------------------------------------------
# 9. 安装流程(由主菜单选 1 调用)
# ---------------------------------------------------------------------------
do_install() {
title "环境检查"
check_root
detect_os
@@ -1175,26 +1159,144 @@ main() {
resolve_home
detect_config_path
if ask_yes_no "现在配置 Telegram 和 API 模型吗?(选 n 可稍后在菜单里配)" "y"; then
wizard
write_config || warn "配置未完整写入,请按上面的提示处理后再重跑本脚本。"
write_config || warn "配置未完整写入,可稍后在菜单里重配。"
else
CFG_PROVIDER="skip"
plain "已跳过配置,稍后可在主菜单选 3 / 4 配置。"
fi
onboard_and_start
local start_rc=$?
install_claw_command
summary
ok "安装流程结束。"
}
if [ "${NONINTERACTIVE_SKIPPED:-0}" = "1" ]; then
ok "安装完成。请在交互终端执行 claw 完成配置并启动。"
# ---------------------------------------------------------------------------
# 10. 主菜单(入口即菜单,仿 kejilion 形态)
# ---------------------------------------------------------------------------
main_menu() {
resolve_home
detect_config_path
while true; do
local inst run upd
inst="未安装"; run="未运行"; upd=""
if command -v openclaw >/dev/null 2>&1; then
local lv; lv="$(openclaw_local_version)"
inst="已安装${lv:+ v$lv}"
local rv; rv="$(openclaw_remote_version 2>/dev/null)"
if [ -n "$rv" ] && [ -n "$lv" ] && [ "$rv" != "$lv" ]; then
upd=" ${C_YELLOW}有新版 v${rv}${C_RESET}"
fi
fi
is_running && run="${C_GREEN}运行中${C_RESET}" || run="${C_GREY}未运行${C_RESET}"
clear 2>/dev/null || true
plain "${C_BOLD}=======================================${C_RESET}"
plain "${C_BOLD} 🦞 OpenClaw 一键管理脚本${C_RESET}"
plain " ${inst} | ${run}${upd}"
plain " 终端输入 ${C_BOLD}claw${C_RESET} 可随时回到本菜单"
plain "${C_BOLD}=======================================${C_RESET}"
plain " 1. 安装 OpenClaw"
plain " 2. 查看当前配置"
plain " ---------------------"
plain " 3. 配置 / 更换 API 模型"
plain " 4. 配置 Telegram 机器人"
plain " ---------------------"
plain " 5. 启动"
plain " 6. 停止"
plain " 7. 重启"
plain " 8. 运行状态"
plain " 9. 查看日志"
plain " ---------------------"
plain " 10. 更新到最新版"
plain " 11. 卸载"
plain " 0. 退出"
plain ""
ask " 请输入选项并回车" "0"
local c="$REPLY_VALUE"
plain ""
case "$c" in
1) do_install; pause_any ;;
2) show_current_config; pause_any ;;
3)
if ! need_installed; then pause_any; continue; fi
CFG_PROVIDER=""; CFG_BASEURL=""; CFG_APIKEY=""; CFG_MODEL=""
CFG_TG_TOKEN=""; CFG_TG_USERID=""
wizard_provider
if [ "$CFG_PROVIDER" != "skip" ] && [ -n "$CFG_PROVIDER" ]; then
write_config && ok "模型配置已更新。" || warn "写入失败。"
ask_yes_no " 重启服务生效?" "y" && do_restart
fi
pause_any ;;
4)
if ! need_installed; then pause_any; continue; fi
CFG_TG_TOKEN=""; CFG_TG_USERID=""; CFG_PROVIDER="skip"
wizard_telegram
if [ -n "$CFG_TG_TOKEN" ] || [ -n "$CFG_TG_USERID" ]; then
write_config && ok "Telegram 配置已更新。" || warn "写入失败。"
ask_yes_no " 重启服务生效?" "y" && do_restart
fi
pause_any ;;
5) need_installed && { run_quiet openclaw gateway start && ok "已启动" || warn "启动失败"; }; pause_any ;;
6) need_installed && { run_quiet openclaw gateway stop && ok "已停止" || warn "停止失败"; }; pause_any ;;
7) need_installed && do_restart; pause_any ;;
8) need_installed && { openclaw status 2>&1 | head -40; }; pause_any ;;
9) need_installed && { openclaw logs 2>&1 | tail -40 || tail -40 "$LOG_FILE" 2>/dev/null; }; pause_any ;;
10)
if ! need_installed; then pause_any; continue; fi
info "正在更新…"
if npm_install_openclaw; then
ok "已更新到 v$(openclaw_local_version)"
ask_yes_no " 重启服务生效?" "y" && do_restart
else
warn "更新失败,请检查网络。"
fi
pause_any ;;
11)
if ! need_installed; then pause_any; continue; fi
warn "卸载会移除 OpenClaw 程序,但保留配置目录 ~/.openclaw"
if ask_yes_no " 确定卸载吗?" "n"; then
run_quiet openclaw gateway stop || true
run_quiet npm uninstall -g openclaw && ok "已卸载(配置已保留)" || warn "卸载失败"
fi
pause_any ;;
0) plain "已退出。"; return 0 ;;
*) warn "请输入 0-11 之间的选项。"; sleep 1 ;;
esac
done
}
need_installed() {
if command -v openclaw >/dev/null 2>&1; then return 0; fi
warn "还没安装 OpenClaw,请先选 1 安装。"
return 1
}
pause_any() {
plain ""
if [ -t 0 ]; then
printf " 按回车返回菜单…"
read -r _ || true
fi
}
main() {
init_log "$@"
# 非交互模式:直接跑安装,不进菜单
if [ "$NONINTERACTIVE" = "1" ] || [ ! -t 0 ]; then
plain ""
plain "${C_BOLD}OpenClaw 一键安装脚本 v${SCRIPT_VERSION}(非交互模式)${C_RESET}"
plain "日志:${LOG_FILE}"
do_install
exit 0
fi
if [ "$start_rc" -eq 0 ]; then
ok "全部完成,祝使用愉快。"
# 交互模式:入口即菜单
main_menu
exit 0
fi
warn "安装已完成,但服务未确认启动,请按上面的排查步骤处理。"
exit 1
}
main "$@"