-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·126 lines (119 loc) · 4.63 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·126 lines (119 loc) · 4.63 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
#!/usr/bin/env bash
#
# flutter-cli uninstaller — reverses `install.sh`:
# 1. Strips the `# >>> flutter-cli shim >>>` block from every supported
# rc file we find (idempotent — skips files where the block isn't
# present, so it's safe to run twice).
# 2. Removes the `flutter-cli` binary from every known install
# location (~/.local/bin, ~/.cargo/bin, /usr/local/bin, $BIN_DIR)
# plus `cargo uninstall flutter-cli` (and the legacy `fl-cli`) for
# build-from-source installs.
#
# Usage:
# ./uninstall.sh # remove shim + binary
# ./uninstall.sh --keep-bin # remove the shim only, leave the binary
# ./uninstall.sh --keep-rc # remove the binary only, leave rc alone
# BIN_DIR=~/.local/bin ./uninstall.sh # also check this extra dir
set -euo pipefail
if [ -t 1 ]; then
BOLD=$'\033[1m'; DIM=$'\033[2m'; GREEN=$'\033[32m'
YELLOW=$'\033[33m'; RED=$'\033[31m'; RESET=$'\033[0m'
else
BOLD=""; DIM=""; GREEN=""; YELLOW=""; RED=""; RESET=""
fi
info() { printf "${DIM}·${RESET} %s\n" "$*"; }
ok() { printf "${GREEN}✓${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW}!${RESET} %s\n" "$*" >&2; }
KEEP_BIN="false"
KEEP_RC="false"
while [ $# -gt 0 ]; do
case "$1" in
--keep-bin) KEEP_BIN="true"; shift ;;
--keep-rc) KEEP_RC="true"; shift ;;
-h|--help)
sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'
exit 0 ;;
*) printf "${RED}✗${RESET} unknown option: %s\n" "$1" >&2; exit 1 ;;
esac
done
# ─── 1. strip the shim from rc files ───────────────────────────────
if [ "$KEEP_RC" = "false" ]; then
MARK_START="# >>> flutter-cli shim >>>"
MARK_END="# <<< flutter-cli shim <<<"
# Every shell rc / profile file the installer (or a user manually
# following the README) could have dropped the eval line into. Covers
# interactive shells (.zshrc/.bashrc), login shells
# (.zprofile/.bash_profile/.zlogin/.profile), and fish. Each file is
# checked for the sentinel block before touching, so listing extras
# has no cost when they don't contain the shim.
RC_CANDIDATES=(
"$HOME/.zshrc"
"$HOME/.zprofile"
"$HOME/.zlogin"
"$HOME/.bashrc"
"$HOME/.bash_profile"
"$HOME/.profile"
"$HOME/.config/fish/config.fish"
)
for rc in "${RC_CANDIDATES[@]}"; do
[ -f "$rc" ] || continue
if ! grep -Fq "$MARK_START" "$rc"; then
continue
fi
# Strip the block in-place. We use a portable awk pass (no GNU
# sed `-i` extensions) so the script runs on macOS BSD tools too.
tmp="$(mktemp)"
awk -v s="$MARK_START" -v e="$MARK_END" '
$0 == s {in_block=1; next}
$0 == e {in_block=0; next}
!in_block {print}
' "$rc" > "$tmp"
# Collapse any trailing blank lines we may have introduced.
awk 'NF{f=1} f' "$tmp" > "$rc"
rm -f "$tmp"
ok "Removed flutter-cli shim from $rc"
done
fi
# ─── 2. remove the binary ──────────────────────────────────────────
if [ "$KEEP_BIN" = "true" ]; then
info "Skipped binary removal (--keep-bin)."
else
removed=0
# Sweep every dir the installer (current or past) may have used —
# plus an explicit BIN_DIR override if the user set one on install.
# Only delete regular files (not symlinks to system services).
for candidate in \
${BIN_DIR:+"$BIN_DIR/flutter-cli"} \
"$HOME/.local/bin/flutter-cli" \
"${CARGO_HOME:-$HOME/.cargo}/bin/flutter-cli" \
"/usr/local/bin/flutter-cli"
do
if [ -f "$candidate" ] && [ ! -L "$candidate" ]; then
rm -f "$candidate"
ok "Removed $candidate"
removed=$((removed + 1))
fi
done
# Tidy cargo's bookkeeping for users who built from source — both the
# current crate name (`flutter-cli`) and the previous one (`fl-cli`,
# renamed in 0.4.7). After this, `cargo install --list` no longer
# claims either is installed.
if command -v cargo >/dev/null; then
if cargo install --list 2>/dev/null | grep -q '^flutter-cli '; then
cargo uninstall flutter-cli >/dev/null 2>&1 || true
ok "Cleaned cargo's record of flutter-cli (build-from-source install)"
removed=$((removed + 1))
fi
if cargo install --list 2>/dev/null | grep -q '^fl-cli '; then
cargo uninstall fl-cli >/dev/null 2>&1 || true
ok "Cleaned cargo's record of fl-cli (legacy build-from-source install)"
removed=$((removed + 1))
fi
fi
if [ "$removed" -eq 0 ]; then
warn "flutter-cli binary not found in any known location — nothing to remove"
fi
fi
cat <<EOF
${BOLD}Done.${RESET} Open a new terminal (or run ${BOLD}exec \$SHELL${RESET}) to pick up the change.
EOF