@@ -2841,6 +2841,165 @@ install_runtime_brief_line() {
28412841 esac
28422842}
28432843
2844+ gum_run_as_root () {
2845+ if [ " $( id -u 2> /dev/null || echo 1) " = " 0" ]; then
2846+ " $@ "
2847+ return $?
2848+ fi
2849+
2850+ if command -v sudo > /dev/null 2>&1 ; then
2851+ sudo " $@ "
2852+ return $?
2853+ fi
2854+
2855+ echo " ❗ 安装 gum 需要 root 权限或 sudo:$* "
2856+ return 1
2857+ }
2858+
2859+ install_gum_with_apt () {
2860+ local key_tmp
2861+
2862+ command -v gpg > /dev/null 2>&1 || {
2863+ echo " ❗ Debian/Ubuntu 安装 gum 需要 gpg,请先安装 gnupg"
2864+ return 1
2865+ }
2866+
2867+ key_tmp=" $( mktemp) "
2868+ if ! curl_download -fsSL https://repo.charm.sh/apt/gpg.key -o " $key_tmp " ; then
2869+ rm -f " $key_tmp " 2> /dev/null || true
2870+ echo " ❗ 下载 Charm APT GPG key 失败"
2871+ return 1
2872+ fi
2873+
2874+ gum_run_as_root mkdir -p /etc/apt/keyrings || {
2875+ rm -f " $key_tmp " 2> /dev/null || true
2876+ return 1
2877+ }
2878+ gum_run_as_root gpg --batch --yes --dearmor -o /etc/apt/keyrings/charm.gpg " $key_tmp " || {
2879+ rm -f " $key_tmp " 2> /dev/null || true
2880+ echo " ❗ 写入 Charm APT GPG key 失败"
2881+ return 1
2882+ }
2883+ rm -f " $key_tmp " 2> /dev/null || true
2884+
2885+ printf ' %s\n' ' deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *' \
2886+ | gum_run_as_root tee /etc/apt/sources.list.d/charm.list > /dev/null || return 1
2887+
2888+ gum_run_as_root apt-get update || return 1
2889+ gum_run_as_root apt-get install -y gum
2890+ }
2891+
2892+ install_charm_yum_repo () {
2893+ local repo_tmp
2894+
2895+ command -v rpm > /dev/null 2>&1 || {
2896+ echo " ❗ 安装 gum 需要 rpm 命令"
2897+ return 1
2898+ }
2899+
2900+ repo_tmp=" $( mktemp) "
2901+ {
2902+ echo " [charm]"
2903+ echo " name=Charm"
2904+ echo " baseurl=https://repo.charm.sh/yum/"
2905+ echo " enabled=1"
2906+ echo " gpgcheck=1"
2907+ echo " gpgkey=https://repo.charm.sh/yum/gpg.key"
2908+ } > " $repo_tmp "
2909+
2910+ gum_run_as_root mkdir -p /etc/yum.repos.d || {
2911+ rm -f " $repo_tmp " 2> /dev/null || true
2912+ return 1
2913+ }
2914+ gum_run_as_root cp " $repo_tmp " /etc/yum.repos.d/charm.repo || {
2915+ rm -f " $repo_tmp " 2> /dev/null || true
2916+ return 1
2917+ }
2918+ rm -f " $repo_tmp " 2> /dev/null || true
2919+
2920+ gum_run_as_root rpm --import https://repo.charm.sh/yum/gpg.key
2921+ }
2922+
2923+ install_gum_with_yum_repo () {
2924+ local manager=" $1 "
2925+
2926+ install_charm_yum_repo || return 1
2927+ gum_run_as_root " $manager " install -y gum
2928+ }
2929+
2930+ install_gum () {
2931+ if command -v gum > /dev/null 2>&1 ; then
2932+ echo " 🖥️ gum 已安装:$( gum --version 2> /dev/null || echo gum) "
2933+ return 0
2934+ fi
2935+
2936+ echo " 🖥️ 正在安装可选 TUI 依赖 gum..."
2937+
2938+ if command -v apt-get > /dev/null 2>&1 ; then
2939+ install_gum_with_apt
2940+ elif command -v dnf > /dev/null 2>&1 ; then
2941+ install_gum_with_yum_repo dnf
2942+ elif command -v yum > /dev/null 2>&1 ; then
2943+ install_gum_with_yum_repo yum
2944+ elif command -v pacman > /dev/null 2>&1 ; then
2945+ gum_run_as_root pacman -S --noconfirm gum
2946+ elif command -v apk > /dev/null 2>&1 ; then
2947+ gum_run_as_root apk add --no-cache gum
2948+ else
2949+ echo " ❗ 未检测到支持的包管理器,请手动安装 gum"
2950+ echo " 见 https://github.com/charmbracelet/gum#installation"
2951+ return 1
2952+ fi
2953+
2954+ if command -v gum > /dev/null 2>&1 ; then
2955+ echo " ✅ gum 安装成功:$( gum --version 2> /dev/null || echo gum) "
2956+ return 0
2957+ fi
2958+
2959+ echo " ❗ gum 安装完成后仍不可用,请检查 PATH"
2960+ return 1
2961+ }
2962+
2963+ prompt_install_tui () {
2964+ case " ${CLASH_INSTALL_GUM:- } " in
2965+ true|1|yes|YES|y|Y)
2966+ install_gum || true
2967+ return 0
2968+ ;;
2969+ false|0|no|NO|n|N)
2970+ return 0
2971+ ;;
2972+ esac
2973+
2974+ if command -v gum > /dev/null 2>&1 ; then
2975+ echo " 🖥️ TUI 依赖已就绪(gum $( gum --version 2> /dev/null || echo ' ?' ) )"
2976+ return 0
2977+ fi
2978+
2979+ [ -t 0 ] || {
2980+ echo " 🖥️ 未安装可选 TUI 依赖 gum;需要时可运行:clashctl tui install-gum"
2981+ return 0
2982+ }
2983+
2984+ echo
2985+ echo " 🖥️ 可选 TUI 控制台需要 gum(Charm 出品的终端 UI 工具)"
2986+ echo " 安装后可通过 clashctl tui 进入交互式控制台"
2987+ printf " 是否现在安装 gum?[y/N] "
2988+
2989+ local answer
2990+ read -r answer 2> /dev/null || answer=" "
2991+ case " ${answer:- N} " in
2992+ [Yy]|[Yy][Ee][Ss])
2993+ echo
2994+ install_gum || true
2995+ ;;
2996+ * )
2997+ echo
2998+ echo " ⏭️ 已跳过 gum 安装,后续可运行:clashctl tui install-gum"
2999+ ;;
3000+ esac
3001+ }
3002+
28443003print_install_summary () {
28453004 local clashctl_file
28463005 local kernel_text project_path arch_text install_actor install_scope_text
0 commit comments