Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·71 lines (60 loc) · 2.23 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·71 lines (60 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# mihoctl 卸载器
# 用法: bash uninstall.sh
# Copyright (c) 2026 Knaithe - MIT License
set -u
REPO_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=.env
. "$REPO_DIR/.env"
. "$REPO_DIR/scripts/install-lib.sh"
USER_HOME=$(_real_home)
[ -n "$USER_HOME" ] || _die "无法确定用户家目录"
BASE_DIR="${MIHOCTL_BASE_DIR:-$USER_HOME/.mihoctl}"
# 以实际安装记录为准(服务方式、内核)
# shellcheck source=/dev/null
[ -f "$BASE_DIR/.env" ] && . "$BASE_DIR/.env"
KERNEL="${MIHOCTL_KERNEL:-mihomo}"
INIT_TYPE="${MIHOCTL_INIT:-$(_detect_init)}"
if [ "$INIT_TYPE" != "nohup" ] && ! _is_root; then
_die "该安装注册了系统服务($INIT_TYPE),请以 root 卸载: sudo bash uninstall.sh"
fi
# ------------------------------------------------------------
# 停止运行
# ------------------------------------------------------------
CLI_BIN=""
for c in /usr/local/bin/mihoctl "$USER_HOME/.local/bin/mihoctl"; do
[ -x "$c" ] && CLI_BIN="$c" && break
done
if [ -n "$CLI_BIN" ]; then
"$CLI_BIN" off >/dev/null 2>&1
fi
# 兜底清理仍在运行的内核/子进程(仅限本数据目录下的二进制)
if pgrep -f "$BASE_DIR/bin/" >/dev/null 2>&1; then
pkill -f "$BASE_DIR/bin/" 2>/dev/null
sleep 1
fi
_ok "服务已停止"
# ------------------------------------------------------------
# 移除服务注册 / 定时任务 / shell 注入 / 命令 / 数据
# ------------------------------------------------------------
_uninstall_service
_clean_crontab() { # $1=用户名(空 = 当前用户)
local list
if [ -n "$1" ]; then
list=$(crontab -l -u "$1" 2>/dev/null) || return 0
case "$list" in *mihoctl-sub-update*) : ;; *) return 0 ;; esac
printf '%s\n' "$list" | grep -v 'mihoctl-sub-update' | crontab -u "$1" -
else
list=$(crontab -l 2>/dev/null) || return 0
case "$list" in *mihoctl-sub-update*) : ;; *) return 0 ;; esac
printf '%s\n' "$list" | grep -v 'mihoctl-sub-update' | crontab -
fi
}
if command -v crontab >/dev/null 2>&1; then
_clean_crontab ""
[ -n "${SUDO_USER:-}" ] && _clean_crontab "$SUDO_USER"
fi
_revoke_rc
_uninstall_cli
rm -rf "$BASE_DIR"
_ok "卸载完成(shell 配置改动在新终端生效)"