-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·202 lines (181 loc) · 4.45 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·202 lines (181 loc) · 4.45 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env bash
set -euo pipefail
PURGE=false
YES=false
DRY_RUN=false
print_usage() {
cat <<'USAGE'
Usage: uninstall.sh [options]
Options:
--purge Also remove model/cache/config artifacts.
--yes Skip interactive confirmation.
--dry-run Show planned removals without deleting files.
--help Show this help.
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--purge)
PURGE=true
shift
;;
--yes)
YES=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
--help|-h)
print_usage
exit 0
;;
*)
printf 'Unknown argument: %s\n' "$1" >&2
print_usage >&2
exit 2
;;
esac
done
FORWARD_FLAGS=()
if [[ "$PURGE" == true ]]; then
FORWARD_FLAGS+=("--purge")
fi
if [[ "$YES" == true ]]; then
FORWARD_FLAGS+=("--yes")
fi
if [[ "$DRY_RUN" == true ]]; then
FORWARD_FLAGS+=("--dry-run")
fi
if command -v fsfs >/dev/null 2>&1; then
exec fsfs uninstall "${FORWARD_FLAGS[@]}"
fi
DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
BINARY_PATH="${INSTALL_LOCATION:-$HOME/.local/bin/fsfs}"
INDEX_DIR="${FRANKENSEARCH_INDEX_DIR:-$PWD/.frankensearch}"
MODEL_DIR="${FRANKENSEARCH_MODEL_DIR:-$DATA_HOME/frankensearch/models}"
CONFIG_DIR="$CONFIG_HOME/frankensearch"
CACHE_DIR="$CACHE_HOME/frankensearch"
BASH_COMPLETION="$DATA_HOME/bash-completion/completions/fsfs"
ZSH_COMPLETION_SITE="$DATA_HOME/zsh/site-functions/_fsfs"
ZSH_COMPLETION_HOME="$HOME/.zfunc/_fsfs"
FISH_COMPLETION="$CONFIG_HOME/fish/completions/fsfs.fish"
CLAUDE_HOOK_FSFS="$HOME/.claude/hooks/fsfs.sh"
CLAUDE_HOOK_FRANKENSEARCH="$HOME/.claude/hooks/frankensearch.sh"
CLAUDE_CODE_HOOK_FSFS="$HOME/.config/claude-code/hooks/fsfs.sh"
CLAUDE_CODE_HOOK_FRANKENSEARCH="$HOME/.config/claude-code/hooks/frankensearch.sh"
CURSOR_HOOK_FSFS="$HOME/.config/cursor/hooks/fsfs.sh"
CURSOR_HOOK_FRANKENSEARCH="$HOME/.config/cursor/hooks/frankensearch.sh"
ALWAYS_TARGETS=(
"$BINARY_PATH"
"$INDEX_DIR"
"$BASH_COMPLETION"
"$ZSH_COMPLETION_SITE"
"$ZSH_COMPLETION_HOME"
"$FISH_COMPLETION"
"$CLAUDE_HOOK_FSFS"
"$CLAUDE_HOOK_FRANKENSEARCH"
"$CLAUDE_CODE_HOOK_FSFS"
"$CLAUDE_CODE_HOOK_FRANKENSEARCH"
"$CURSOR_HOOK_FSFS"
"$CURSOR_HOOK_FRANKENSEARCH"
)
PURGE_TARGETS=(
"$MODEL_DIR"
"$CONFIG_DIR"
"$CACHE_DIR"
)
safe_guard_path() {
local path="$1"
[[ -n "$path" ]] || return 1
[[ "$path" != "/" ]] || return 1
[[ "$path" != "$HOME" ]] || return 1
return 0
}
show_plan() {
printf 'fsfs uninstall plan\n'
printf ' mode: %s\n' "$([[ "$DRY_RUN" == true ]] && printf 'dry-run' || printf 'execute')"
printf ' purge: %s\n' "$PURGE"
printf '\n'
printf 'Always removed:\n'
local target
for target in "${ALWAYS_TARGETS[@]}"; do
printf ' - %s\n' "$target"
done
printf '\n'
printf 'Purge-only targets:\n'
for target in "${PURGE_TARGETS[@]}"; do
printf ' - %s\n' "$target"
done
}
if [[ "$YES" == false && "$DRY_RUN" == false ]]; then
show_plan
printf '\nProceed with uninstall? [y/N]: '
read -r answer
case "$answer" in
y|Y|yes|YES) ;;
*)
printf 'Cancelled.\n'
exit 0
;;
esac
fi
removed=0
skipped=0
failed=0
remove_path() {
local path="$1"
local purge_only="$2"
if [[ "$purge_only" == "true" && "$PURGE" == false ]]; then
printf 'SKIP %s (requires --purge)\n' "$path"
skipped=$((skipped + 1))
return
fi
if [[ ! -e "$path" && ! -L "$path" ]]; then
printf 'MISS %s\n' "$path"
skipped=$((skipped + 1))
return
fi
if ! safe_guard_path "$path"; then
printf 'ERROR %s (unsafe path)\n' "$path"
failed=$((failed + 1))
return
fi
if [[ "$DRY_RUN" == true ]]; then
printf 'PLAN %s\n' "$path"
skipped=$((skipped + 1))
return
fi
if [[ -d "$path" && ! -L "$path" ]]; then
if rm -rf "$path"; then
printf 'OK %s\n' "$path"
removed=$((removed + 1))
else
printf 'ERROR %s\n' "$path"
failed=$((failed + 1))
fi
else
if rm -f "$path"; then
printf 'OK %s\n' "$path"
removed=$((removed + 1))
else
printf 'ERROR %s\n' "$path"
failed=$((failed + 1))
fi
fi
}
show_plan
printf '\n'
for path in "${ALWAYS_TARGETS[@]}"; do
remove_path "$path" false
done
for path in "${PURGE_TARGETS[@]}"; do
remove_path "$path" true
done
printf '\nSummary: removed=%d skipped=%d failed=%d\n' "$removed" "$skipped" "$failed"
if [[ "$failed" -gt 0 ]]; then
exit 1
fi