Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·380 lines (327 loc) · 16.8 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·380 lines (327 loc) · 16.8 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/env bash
# Copyright 2026 Firefly Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
# ══════════════════════════════════════════════════════════════════════════════
# fireflyframework-agentic — Interactive Uninstaller
# ══════════════════════════════════════════════════════════════════════════════
readonly PACKAGE="fireflyframework-agentic"
readonly PACKAGE_IMPORT="fireflyframework_agentic"
readonly TOTAL_STEPS=4
# ── Installer state ──────────────────────────────────────────────────────────
INTERACTIVE=true
PYTHON_CMD=""
INSTALLED_VERSION=""
INSTALL_LOCATION=""
HAS_UV=false
SPINNER_PID=""
# ══════════════════════════════════════════════════════════════════════════════
# Colors — ANSI-C quoting ($'...') produces actual escape bytes
# ══════════════════════════════════════════════════════════════════════════════
setup_colors() {
if [[ -t 1 ]]; then
RED=$'\e[0;31m'
GREEN=$'\e[0;32m'
YELLOW=$'\e[1;33m'
BLUE=$'\e[0;34m'
MAGENTA=$'\e[0;35m'
CYAN=$'\e[0;36m'
WHITE=$'\e[1;37m'
DIM=$'\e[2m'
BOLD=$'\e[1m'
RESET=$'\e[0m'
else
RED='' GREEN='' YELLOW='' BLUE='' MAGENTA='' CYAN=''
WHITE='' DIM='' BOLD='' RESET=''
fi
}
# ══════════════════════════════════════════════════════════════════════════════
# TTY handling — critical for `curl ... | bash` piped execution
# ══════════════════════════════════════════════════════════════════════════════
setup_tty() {
if [[ ! -t 0 ]]; then
if [[ -e /dev/tty ]]; then
exec < /dev/tty
else
INTERACTIVE=false
fi
fi
}
# ── Cleanup ──────────────────────────────────────────────────────────────────
cleanup() {
if [[ -n "${SPINNER_PID:-}" ]]; then
kill "$SPINNER_PID" 2>/dev/null || true
wait "$SPINNER_PID" 2>/dev/null || true
SPINNER_PID=""
fi
tput cnorm 2>/dev/null || true
printf "\n %s⚠%s Uninstallation cancelled.\n\n" "$YELLOW" "$RESET"
exit 130
}
trap cleanup SIGINT SIGTERM
# ══════════════════════════════════════════════════════════════════════════════
# Output helpers
# ══════════════════════════════════════════════════════════════════════════════
info() { printf " %sℹ%s %s\n" "$BLUE" "$RESET" "$*"; }
success() { printf " %s✔%s %s\n" "$GREEN" "$RESET" "$*"; }
warn() { printf " %s⚠%s %s\n" "$YELLOW" "$RESET" "$*"; }
error() { printf " %s✖%s %s\n" "$RED" "$RESET" "$*"; }
step_header() {
local num="$1" title="$2"
printf "\n %s━━━ Step %d/%d · %s ━━━%s\n\n" \
"${BOLD}${CYAN}" "$num" "$TOTAL_STEPS" "$title" "$RESET"
}
divider() {
printf "\n %s════════════════════════════════════════════════════════════%s\n" \
"$DIM" "$RESET"
}
print_box() {
local text="$1"
local len=${#text}
local inner=$(( len + 4 ))
local border=""
for ((i = 0; i < inner; i++)); do border+="═"; done
printf "\n"
printf " %s╔%s╗%s\n" "$GREEN" "$border" "$RESET"
printf " %s║%s %s%s%s%s %s║%s\n" \
"$GREEN" "$RESET" "$BOLD" "$WHITE" "$text" "$RESET" "$GREEN" "$RESET"
printf " %s╚%s╝%s\n" "$GREEN" "$border" "$RESET"
printf "\n"
}
# ══════════════════════════════════════════════════════════════════════════════
# Prompts
# ══════════════════════════════════════════════════════════════════════════════
prompt_yn() {
local message="$1" default="${2:-y}"
if [[ "$INTERACTIVE" == false ]]; then
[[ "$default" == "y" ]] && return 0 || return 1
fi
local hint
if [[ "$default" == "y" ]]; then
hint="${DIM}[Y/n]${RESET}"
else
hint="${DIM}[y/N]${RESET}"
fi
printf " %s?%s %s %s " "$CYAN" "$RESET" "$message" "$hint"
local answer
read -r answer
answer="${answer:-$default}"
[[ "$answer" =~ ^[Yy] ]]
}
# ══════════════════════════════════════════════════════════════════════════════
# Spinner
# ══════════════════════════════════════════════════════════════════════════════
spinner_start() {
local message="$1"
local frames=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏")
tput civis 2>/dev/null || true
(
local i=0
while true; do
printf "\r %s%s%s %s" "$CYAN" "${frames[$i]}" "$RESET" "$message"
i=$(( (i + 1) % ${#frames[@]} ))
sleep 0.08
done
) &
SPINNER_PID=$!
}
spinner_stop() {
local status="$1" message="$2"
if [[ -n "${SPINNER_PID:-}" ]]; then
kill "$SPINNER_PID" 2>/dev/null || true
wait "$SPINNER_PID" 2>/dev/null || true
SPINNER_PID=""
fi
tput cnorm 2>/dev/null || true
printf "\r %-78s\r" ""
if [[ "$status" == "ok" ]]; then
success "$message"
else
error "$message"
fi
}
# ══════════════════════════════════════════════════════════════════════════════
# Banner
# ══════════════════════════════════════════════════════════════════════════════
banner() {
printf "%s" "$CYAN"
cat << 'EOF'
_____.__ _____.__
_/ ____\__|______ _____/ ____\ | ___.__.
\ __\| \_ __ \_/ __ \ __\| |< | |
| | | || | \/\ ___/| | | |_\___ |
|__| |__||__| \___ >__| |____/ ____|
\/ \/
_____ __ /\
_/ ____\___________ _____ ______ _ _____________| | __ \ \
\ __\_ __ \__ \ / \_/ __ \ \/ \/ / _ \_ __ \ |/ / \ \
| | | | \// __ \| Y Y \ ___/\ ( <_> ) | \/ < \ \
|__| |__| (____ /__|_| /\___ >\/\_/ \____/|__| |__|_ \ \ \
\/ \/ \/ \/ \/
________ _____ .__
/ _____/ ____ ____ / _ \ |__|
/ \ ____/ __ \ / \ / /_\ \| |
\ \_\ \ ___/| | \/ | \ |
\______ /\___ >___| /\____|__ /__|
\/ \/ \/ \/
EOF
printf "%s" "$RESET"
printf " %s%s%s%s %sUninstaller%s\n" "$BOLD" "$WHITE" "$PACKAGE" "$RESET" "$DIM" "$RESET"
printf " %sCopyright 2026 Firefly Software Foundation. Apache License 2.0.%s\n" "$DIM" "$RESET"
divider
}
# ══════════════════════════════════════════════════════════════════════════════
# Step 1 · Detect Installation
# ══════════════════════════════════════════════════════════════════════════════
step_detect_installation() {
step_header 1 "Detect Installation"
# Find Python
for cmd in python3 python; do
if command -v "$cmd" &>/dev/null; then
PYTHON_CMD="$cmd"
break
fi
done
if [[ -z "$PYTHON_CMD" ]]; then
error "Python not found. Cannot detect package installation."
exit 1
fi
success "Python: $("$PYTHON_CMD" --version 2>&1 | awk '{print $2}') ($PYTHON_CMD)"
# Check if package is installed
if INSTALLED_VERSION="$("$PYTHON_CMD" -c \
"import ${PACKAGE_IMPORT}; print(${PACKAGE_IMPORT}.__version__)" 2>/dev/null)"; then
success "Found: ${PACKAGE} v${INSTALLED_VERSION}"
else
warn "${PACKAGE} does not appear to be installed."
exit 0
fi
# Detect location
INSTALL_LOCATION="$("$PYTHON_CMD" -m pip show "$PACKAGE" 2>/dev/null \
| grep "^Location:" | awk '{print $2}')" || true
if [[ -n "$INSTALL_LOCATION" ]]; then
info "Location: ${INSTALL_LOCATION}"
fi
# Detect UV
if command -v uv &>/dev/null; then
HAS_UV=true
fi
}
# ══════════════════════════════════════════════════════════════════════════════
# Step 2 · Confirm
# ══════════════════════════════════════════════════════════════════════════════
step_confirm() {
step_header 2 "Confirmation"
printf " %sThe following will be removed:%s\n\n" "$YELLOW" "$RESET"
printf " %s•%s %s v%s\n" "$WHITE" "$RESET" "$PACKAGE" "$INSTALLED_VERSION"
if [[ -n "$INSTALL_LOCATION" ]]; then
printf " %sLocation: %s%s\n" "$DIM" "$INSTALL_LOCATION" "$RESET"
fi
printf "\n"
if ! prompt_yn "Proceed with uninstallation?"; then
info "Uninstallation cancelled."
exit 0
fi
}
# ══════════════════════════════════════════════════════════════════════════════
# Step 3 · Remove & Cleanup
# ══════════════════════════════════════════════════════════════════════════════
step_remove() {
step_header 3 "Remove & Cleanup"
# ── Uninstall package ─────────────────────────────────────────────────
if [[ "$HAS_UV" == true ]]; then
spinner_start "Removing ${PACKAGE} via UV..."
if uv pip uninstall "$PACKAGE" &>/dev/null 2>&1; then
spinner_stop "ok" "Removed ${PACKAGE} via UV"
else
spinner_stop "fail" "UV removal failed — trying pip"
spinner_start "Removing ${PACKAGE} via pip..."
if "$PYTHON_CMD" -m pip uninstall -y "$PACKAGE" &>/dev/null 2>&1; then
spinner_stop "ok" "Removed ${PACKAGE} via pip"
else
spinner_stop "fail" "Could not remove ${PACKAGE}"
error "Please try: ${PYTHON_CMD} -m pip uninstall ${PACKAGE}"
exit 1
fi
fi
else
spinner_start "Removing ${PACKAGE} via pip..."
if "$PYTHON_CMD" -m pip uninstall -y "$PACKAGE" &>/dev/null 2>&1; then
spinner_stop "ok" "Removed ${PACKAGE} via pip"
else
spinner_stop "fail" "Could not remove ${PACKAGE}"
error "Please try: ${PYTHON_CMD} -m pip uninstall ${PACKAGE}"
exit 1
fi
fi
# ── Clean source directory ────────────────────────────────────────────
if [[ -d "${PACKAGE}" ]]; then
printf "\n"
if prompt_yn "Remove local source directory '${PACKAGE}/'?" "n"; then
spinner_start "Removing source directory..."
rm -rf "${PACKAGE}"
spinner_stop "ok" "Source directory removed"
else
info "Keeping source directory"
fi
fi
# ── Clean pip cache ───────────────────────────────────────────────────
printf "\n"
if prompt_yn "Remove cached package files?" "n"; then
spinner_start "Cleaning pip cache..."
"$PYTHON_CMD" -m pip cache purge &>/dev/null 2>&1 || true
spinner_stop "ok" "Cache cleaned"
else
info "Skipping cache cleanup"
fi
}
# ══════════════════════════════════════════════════════════════════════════════
# Step 4 · Verify
# ══════════════════════════════════════════════════════════════════════════════
step_verify() {
step_header 4 "Verification"
spinner_start "Verifying removal..."
if "$PYTHON_CMD" -c "import ${PACKAGE_IMPORT}" &>/dev/null 2>&1; then
spinner_stop "fail" "Package is still importable — removal may be incomplete"
warn "Try: ${PYTHON_CMD} -m pip uninstall ${PACKAGE}"
else
spinner_stop "ok" "Package successfully removed"
fi
}
# ══════════════════════════════════════════════════════════════════════════════
# Summary
# ══════════════════════════════════════════════════════════════════════════════
print_farewell() {
divider
print_box "${PACKAGE} has been uninstalled."
info "Thank you for using ${PACKAGE}!"
printf "\n"
printf " %sReinstall anytime:%s\n" "$DIM" "$RESET"
printf " curl -fsSL https://raw.githubusercontent.com/fireflyframework/fireflyframework-agentic/main/install.sh | bash\n"
printf "\n"
printf " %sRepository:%s https://github.com/fireflyframework/fireflyframework-agentic\n\n" "$DIM" "$RESET"
}
# ══════════════════════════════════════════════════════════════════════════════
# Main
# ══════════════════════════════════════════════════════════════════════════════
main() {
setup_colors
setup_tty
banner
step_detect_installation
step_confirm
step_remove
step_verify
print_farewell
}
main "$@"