-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·91 lines (77 loc) · 2.79 KB
/
uninstall.sh
File metadata and controls
executable file
·91 lines (77 loc) · 2.79 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PURGE_RUNTIME="false"
DEV_RESET="false"
for arg in "$@"; do
case "$arg" in
--purge-runtime)
PURGE_RUNTIME="true"
;;
--dev-reset)
DEV_RESET="true"
;;
*)
echo "未知参数:$arg" >&2
echo "用法:bash uninstall.sh [--dev-reset] [--purge-runtime]" >&2
exit 2
;;
esac
done
# shellcheck source=scripts/core/common.sh
source "$PROJECT_DIR/scripts/core/common.sh"
# shellcheck source=scripts/core/runtime.sh
source "$PROJECT_DIR/scripts/core/runtime.sh"
# shellcheck source=scripts/core/config.sh
source "$PROJECT_DIR/scripts/core/config.sh"
# shellcheck source=scripts/init/systemd.sh
source "$PROJECT_DIR/scripts/init/systemd.sh"
# shellcheck source=scripts/init/systemd-user.sh
source "$PROJECT_DIR/scripts/init/systemd-user.sh"
# shellcheck source=scripts/init/script.sh
source "$PROJECT_DIR/scripts/init/script.sh"
init_project_context "$PROJECT_DIR"
load_env_if_exists
detect_install_scope auto
service_stop || true
remove_runtime_entry || true
remove_clashctl_entry || true
remove_shell_alias_entry || true
clear_shell_proxy_persist_state || true
if [ "$PURGE_RUNTIME" = "true" ]; then
rm -rf "$RUNTIME_DIR"
clear_controller_secret || true
echo "🗑️ 已删除运行目录:$RUNTIME_DIR"
echo "🧩 保留内容:项目目录仍在(已清理 controller secret)"
elif [ "$DEV_RESET" = "true" ]; then
cache_backup_dir="$(mktemp -d)"
cache_restore_needed="false"
subscriptions_backup_file="$cache_backup_dir/subscriptions.yaml"
subscriptions_restore_needed="false"
if [ -d "$RUNTIME_DIR/cache" ]; then
cp -a "$RUNTIME_DIR/cache" "$cache_backup_dir/" 2>/dev/null || true
cache_restore_needed="true"
fi
if [ -f "$RUNTIME_DIR/subscriptions.yaml" ]; then
cp -f "$RUNTIME_DIR/subscriptions.yaml" "$subscriptions_backup_file" 2>/dev/null || true
subscriptions_restore_needed="true"
fi
clean_runtime_state
if [ "$cache_restore_needed" = "true" ] && [ -d "$cache_backup_dir/cache" ]; then
mkdir -p "$RUNTIME_DIR"
rm -rf "$RUNTIME_DIR/cache" 2>/dev/null || true
mv "$cache_backup_dir/cache" "$RUNTIME_DIR/cache"
fi
if [ "$subscriptions_restore_needed" = "true" ] && [ -f "$subscriptions_backup_file" ]; then
mkdir -p "$RUNTIME_DIR"
cp -f "$subscriptions_backup_file" "$RUNTIME_DIR/subscriptions.yaml"
fi
rm -rf "$cache_backup_dir" 2>/dev/null || true
clear_controller_secret || true
echo "🧪 已清理安装状态:$RUNTIME_DIR"
echo "🧩 保留内容:subscriptions.yaml、下载缓存与项目目录仍在(已清理 controller secret)"
else
echo "📦 已卸载安装入口,保留运行目录:$RUNTIME_DIR"
echo "🧩 保留内容:runtime 数据仍在"
fi
echo "✨ 卸载完成"