Skip to content

Commit b08c89d

Browse files
authored
Merge pull request #238 from wnlen/dev
Dev
2 parents a8c98c0 + 9ee524f commit b08c89d

4 files changed

Lines changed: 112 additions & 66 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bash install.sh
6565
clashctl add ➕ 添加订阅
6666
clashctl add local ➕ 从 runtime/subscriptions 导入本地订阅
6767
clashctl use 💱 切换订阅
68-
clashctl ls 📡 查看订阅列表
68+
clashctl ls 📜 查看订阅列表
6969
🔐 密钥管理
7070
clashctl secret 🔑 查看密钥
7171
clashctl secret 123 🔐 设置密钥
@@ -82,7 +82,6 @@ bash install.sh
8282
clashctl log/logs 📜 查看日志
8383

8484
💡 显示更多帮助命令:clashctl -h
85-
💡 更多高级能力:clashctl help advanced
8685
```
8786
8887
------

scripts/core/clashctl.sh

Lines changed: 83 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,83 +29,58 @@ Usage:
2929
use 💱 切换订阅
3030
select 💫 切换节点
3131
32-
33-
📦 Subscription:
34-
ls 📡 查看订阅列表
35-
36-
🕹️ Control:
37-
clashui 🕹️ 查看 Web 控制台
38-
secret 🔑 查看或设置 Web 密钥
39-
clashsecret 🔑 查看或设置 Web 密钥
40-
41-
🩺 Diagnose:
42-
doctor 🩺 诊断环境与运行状态
43-
status 🔍️ 查看状态总览
44-
boot 🚦 管理开机代理接管
45-
log/logs 📜 查看日志
46-
completion 💡 导出 Bash / Zsh 补全脚本
47-
48-
💡 更多高级能力:clashctl help advanced
49-
EOF
50-
}
51-
52-
usage_advanced() {
53-
cat <<EOF
54-
🐱 Clash 高级命令
55-
5632
🧩 Config:
5733
config 🧩 配置编译管理
34+
config kernel mihomo|clash 🧩 切换指定内核
5835
mixin 🧩 Mixin 配置管理
5936
relay 🔗 多跳节点管理
37+
6038
61-
📡 Subscription Advanced:
39+
📦 Subscription:
40+
config show 📡 查看当前订阅
41+
config regen 🔄 更新当前订阅
42+
ls 📜 查看订阅列表
6243
sub 📡 订阅高级管理(启用 / 禁用 / 重命名 / 删除)
63-
health 🩷 多订阅健康审计
6444
65-
🩺 Runtime & Diagnose:
45+
🕹️ Control:
46+
clashui 🕹️ 查看 Web 控制台
47+
secret 🔑 查看或设置 Web 密钥
48+
49+
🧪 Transparent proxy:
6650
tun 🧪 Tun 模式管理
67-
tun doctor 🩺 诊断环境与运行状态
68-
tun log/logs 📜 查看日志
51+
tun doctor 🩺 诊断环境与运行状态
52+
tun log/logs 📜 查看日志
6953
7054
🚀 Lifecycle:
71-
boot on|off|status 🚦 管理开机代理接管
72-
boot runtime on|off|status 🚦 仅管理内核开机自启
73-
boot proxy on|off|status 📜 仅管理开机代理保持
55+
boot on|off|status 🚦 管理开机代理接管
56+
boot runtime on|off|status 🚦 仅管理内核开机自启
57+
boot proxy on|off|status 📜 仅管理开机代理保持
7458
upgrade 🚀 升级当前或指定内核
7559
update 🔄 更新项目代码
7660
completion bash|zsh 💡 导出 Shell 补全脚本
7761
dev reset 🧪 恢复到安装前状态(保留项目目录和已下载文件)
7862
63+
🩺 Diagnose:
64+
doctor 🩺 诊断环境与运行状态
65+
status 🔍️ 查看状态总览
66+
log/logs 📜 查看日志
67+
completion 💡 导出 Bash / Zsh 补全脚本
68+
7969
📌 Advanced Examples:
8070
clashctl sub list
8171
clashctl sub enable hk
8272
clashctl sub disable hk
8373
clashctl sub rename hk hk-bak
8474
clashctl sub remove hk
8575
86-
clashctl config show
87-
clashctl config explain
88-
clashctl config regen
89-
clashctl config kernel mihomo
9076
clashctl relay add 多跳-示例 节点A 节点B --domain example.com
9177
clashctl relay list
9278
93-
clashctl tun doctor
94-
clashctl update --force
95-
clashctl dev reset
96-
97-
🚀 Main Path Reminder:
98-
clashctl add [订阅链接] [名称]
99-
clashctl add local
100-
clashctl use
101-
clashon
102-
clashctl select
103-
clashctl status
104-
10579
💡 Notes:
10680
当前编译链固定为 active-only
10781
只处理当前 active 主订阅
10882
Tun 模式属于高级能力,开启前建议先执行:clashctl tun doctor
83+
10984
EOF
11085
}
11186

@@ -2972,7 +2947,7 @@ cmd_ui_help_summary() {
29722947
printf ' %-18s %s\n' "clashctl add" "➕ 添加订阅"
29732948
printf ' %-18s %s\n' "clashctl add local" "➕ 从 runtime/subscriptions 导入本地订阅"
29742949
printf ' %-18s %s\n' "clashctl use" "💱 切换订阅"
2975-
printf ' %-18s %s\n' "clashctl ls" "📡 查看订阅列表"
2950+
printf ' %-18s %s\n' "clashctl ls" "📜 查看订阅列表"
29762951
echo "📌 高级"
29772952
printf ' %-18s %s\n' "clashctl tun" "🧪 Tun 模式管理"
29782953
printf ' %-18s %s\n' "clashctl mixin" "🧩 Mixin 配置管理"
@@ -4897,8 +4872,11 @@ doctor_tun_checks() {
48974872
process_cap_rc=2
48984873
case "$backend" in
48994874
systemd|systemd-user)
4900-
tun_process_has_cap_net_admin "$backend" >/dev/null 2>&1
4901-
process_cap_rc=$?
4875+
if tun_process_has_cap_net_admin "$backend" >/dev/null 2>&1; then
4876+
process_cap_rc=0
4877+
else
4878+
process_cap_rc=$?
4879+
fi
49024880
;;
49034881
esac
49044882

@@ -5135,27 +5113,42 @@ tun_runtime_pid() {
51355113

51365114
tun_process_capability_text() {
51375115
local backend="${1:-unknown}"
5138-
local pid cap_eff cap_value net_admin net_raw
5116+
local pid=""
5117+
local cap_eff=""
5118+
local cap_value=0
5119+
local net_admin="no"
5120+
local net_raw="no"
51395121

51405122
pid="$(tun_runtime_pid "$backend" 2>/dev/null || true)"
51415123
if [ -z "${pid:-}" ] || [ ! -r "/proc/$pid/status" ]; then
51425124
echo "未读取到运行中 mihomo 进程能力"
51435125
return 0
51445126
fi
51455127

5146-
cap_eff="$(sed -nE 's/^CapEff:[[:space:]]*([0-9a-fA-F]+)$/\1/p' "/proc/$pid/status" 2>/dev/null | head -n 1)"
5128+
cap_eff="$(
5129+
sed -nE 's/^CapEff:[[:space:]]*([0-9a-fA-F]+)$/\1/p' "/proc/$pid/status" 2>/dev/null \
5130+
| head -n 1
5131+
)"
5132+
51475133
if [ -z "${cap_eff:-}" ]; then
51485134
echo "pid=$pid,未读取到 CapEff"
51495135
return 0
51505136
fi
51515137

5138+
case "$cap_eff" in
5139+
*[!0-9a-fA-F]*)
5140+
echo "pid=$pid,CapEff 格式异常:$cap_eff"
5141+
return 0
5142+
;;
5143+
esac
5144+
51525145
cap_value=$((16#$cap_eff))
5153-
net_admin="no"
5154-
net_raw="no"
5155-
if [ $((cap_value & (1 << 12))) -ne 0 ]; then
5146+
5147+
if (( cap_value & (1 << 12) )); then
51565148
net_admin="yes"
51575149
fi
5158-
if [ $((cap_value & (1 << 13))) -ne 0 ]; then
5150+
5151+
if (( cap_value & (1 << 13) )); then
51595152
net_raw="yes"
51605153
fi
51615154

@@ -5164,16 +5157,29 @@ tun_process_capability_text() {
51645157

51655158
tun_process_has_cap_net_admin() {
51665159
local backend="${1:-unknown}"
5167-
local pid cap_eff cap_value
5160+
local pid=""
5161+
local cap_eff=""
5162+
local cap_value=0
51685163

51695164
pid="$(tun_runtime_pid "$backend" 2>/dev/null || true)"
51705165
[ -n "${pid:-}" ] && [ -r "/proc/$pid/status" ] || return 2
51715166

5172-
cap_eff="$(sed -nE 's/^CapEff:[[:space:]]*([0-9a-fA-F]+)$/\1/p' "/proc/$pid/status" 2>/dev/null | head -n 1)"
5167+
cap_eff="$(
5168+
sed -nE 's/^CapEff:[[:space:]]*([0-9a-fA-F]+)$/\1/p' "/proc/$pid/status" 2>/dev/null \
5169+
| head -n 1
5170+
)"
5171+
51735172
[ -n "${cap_eff:-}" ] || return 2
51745173

5174+
case "$cap_eff" in
5175+
*[!0-9a-fA-F]*)
5176+
return 2
5177+
;;
5178+
esac
5179+
51755180
cap_value=$((16#$cap_eff))
5176-
if [ $((cap_value & (1 << 12))) -ne 0 ]; then
5181+
5182+
if (( cap_value & (1 << 12) )); then
51775183
return 0
51785184
fi
51795185

@@ -5339,8 +5345,11 @@ tun_doctor_primary_reason() {
53395345
process_cap_rc=2
53405346
case "$backend" in
53415347
systemd|systemd-user)
5342-
tun_process_has_cap_net_admin "$backend" >/dev/null 2>&1
5343-
process_cap_rc=$?
5348+
if tun_process_has_cap_net_admin "$backend" >/dev/null 2>&1; then
5349+
process_cap_rc=0
5350+
else
5351+
process_cap_rc=$?
5352+
fi
53445353
;;
53455354
esac
53465355

@@ -6000,9 +6009,20 @@ cmd_add() {
60006009

60016010
sub_fmt="$(detect_subscription_format "$sub_url")"
60026011

6012+
ui_progress_line 5 "正在保存订阅..."
6013+
60036014
set_subscription "$sub_url" "$sub_fmt" "$sub_name" "false"
6015+
6016+
ui_progress_line 65 "正在设为当前订阅..."
6017+
60046018
set_active_subscription "$sub_name"
6005-
apply_runtime_change_after_config_mutation
6019+
6020+
ui_progress_line 85 "正在应用配置..."
6021+
6022+
apply_runtime_change_after_config_mutation >/dev/null
6023+
6024+
ui_progress_done "订阅添加完成"
6025+
60066026
print_add_feedback "$sub_name" "$sub_url"
60076027
cmd_ls
60086028
}

scripts/core/common.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ ui_kv() {
119119
printf '%s %s:%s\n' "$icon" "$key" "$value"
120120
}
121121

122+
ui_progress_line() {
123+
local percent="$1"
124+
local message="$2"
125+
126+
if [ -t 2 ]; then
127+
printf '\r\033[K⏳ [%3s%%] %s' "$percent" "$message" >&2
128+
else
129+
printf '⏳ [%3s%%] %s\n' "$percent" "$message" >&2
130+
fi
131+
}
132+
133+
ui_progress_done() {
134+
local message="${1:-完成}"
135+
136+
if [ -t 2 ]; then
137+
printf '\r\033[K✅ [100%%] %s\n' "$message" >&2
138+
else
139+
printf '✅ [100%%] %s\n' "$message" >&2
140+
fi
141+
}
142+
143+
ui_progress_clear() {
144+
if [ -t 2 ]; then
145+
printf '\r\033[K' >&2
146+
fi
147+
}
148+
122149
install_phase_begin() {
123150
local icon="$1"
124151
local text="$2"

scripts/core/update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ update_project_code() {
203203
fi
204204

205205
if git_has_local_changes && [ "$force_mode" != "true" ]; then
206-
die "检测到本地有未提交改动,请先提交,或使用 clashctl update --force"
206+
die "检测到本地有未提交改动,请先提交,或使用 clashctl update --force 强制覆盖"
207207
fi
208208

209209
info "正在获取最新代码"

0 commit comments

Comments
 (0)