Skip to content

Commit dfe9db3

Browse files
Refactor uninstall script for edge binary and cache
1 parent b713873 commit dfe9db3

1 file changed

Lines changed: 30 additions & 54 deletions

File tree

cli/setup/uninstall.sh

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,12 @@
11
#!/usr/bin/env bash
2-
# Remove the edge binary, its PATH entry, and optionally the Chromium install.sh added.
2+
# Remove the edge binary, its PATH entry, and the bundled chrome-headless-shell cache.
33

44
set -e
55

66
INSTALL_DIR="${EDGE_INSTALL_DIR:-$HOME/.local/bin}"
77

8-
# Pick sudo only when not root and sudo exists; matches install.sh.
9-
SUDO=""
10-
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then
11-
SUDO="sudo"
12-
fi
13-
14-
# Remove Chromium via the host's native package manager. Reads /etc/os-release on Linux.
15-
uninstall_browser() {
16-
case "$(uname -s)" in
17-
Darwin)
18-
if command -v brew >/dev/null 2>&1; then
19-
brew uninstall --cask chromium
20-
return
21-
fi
22-
echo "Homebrew not found; remove Chromium manually" >&2
23-
return 1
24-
;;
25-
Linux)
26-
local id="" id_like=""
27-
if [ -r /etc/os-release ]; then
28-
# shellcheck disable=SC1091
29-
. /etc/os-release
30-
id="${ID:-}"
31-
id_like="${ID_LIKE:-}"
32-
fi
33-
case " ${id} ${id_like} " in
34-
*" debian "*|*" ubuntu "*)
35-
$SUDO apt-get remove -y chromium && $SUDO apt-get autoremove -y ;;
36-
*" fedora "*|*" rhel "*|*" centos "*)
37-
$SUDO dnf remove -y chromium ;;
38-
*" arch "*)
39-
$SUDO pacman -Rs --noconfirm chromium ;;
40-
*" opensuse "*|*" suse "*)
41-
$SUDO zypper remove -y chromium ;;
42-
*" alpine "*)
43-
$SUDO apk del chromium ;;
44-
*)
45-
echo "unsupported distro (${id:-unknown}); remove Chromium manually" >&2
46-
return 1 ;;
47-
esac
48-
;;
49-
esac
50-
}
8+
# Browser model: install.sh downloads a pinned chrome-headless-shell to ~/.cache/edge, so uninstall just removes that directory: no package-manager dispatch, no sudo, and we never touch system Chromium that other apps may depend on.
9+
CHROME_DIR="${EDGE_CHROME_DIR:-$HOME/.cache/edge}"
5110

5211
# 1. Binary.
5312
if [ -f "$INSTALL_DIR/edge" ]; then
@@ -57,28 +16,45 @@ else
5716
echo "no edge binary at $INSTALL_DIR/edge"
5817
fi
5918

60-
# 2. PATH entry. Leave a .edgebak in case the user wants to roll it back.
19+
# 2. PATH and EDGE_CHROME_PATH entries. Leave a .edgebak in case the user wants to roll it back.
6120
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
62-
if [ -f "$rc" ] && grep -qs "$INSTALL_DIR" "$rc"; then
21+
[ -f "$rc" ] || continue
22+
changed=0
23+
if grep -qs "$INSTALL_DIR" "$rc"; then
6324
sed -i.edgebak "\|export PATH=\"$INSTALL_DIR:\$PATH\"|d" "$rc"
64-
echo "cleaned PATH entry from $rc (backup at $rc.edgebak)"
25+
changed=1
6526
fi
27+
if grep -qs 'EDGE_CHROME_PATH=' "$rc"; then
28+
[ -f "$rc.edgebak" ] || cp "$rc" "$rc.edgebak"
29+
sed -i.tmp '/EDGE_CHROME_PATH=/d' "$rc" && rm -f "$rc.tmp"
30+
changed=1
31+
fi
32+
[ "$changed" = 1 ] && echo "cleaned edge entries from $rc (backup at $rc.edgebak)"
6633
done
6734

68-
# 3. Chromium. Opt-in because the user may rely on it for other apps. `edge uninstall` sets EDGE_UNINSTALL_REMOVE_BROWSER after asking in Rust, so we skip the prompt then.
35+
# 3. Bundled chrome-headless-shell cache. Opt-in; `edge uninstall` sets EDGE_UNINSTALL_REMOVE_BROWSER after asking in Rust, so we skip the prompt then.
36+
remove_chrome_cache() {
37+
if [ -d "$CHROME_DIR" ]; then
38+
rm -rf "$CHROME_DIR"
39+
echo "removed $CHROME_DIR"
40+
else
41+
echo "no chrome-headless-shell cache at $CHROME_DIR"
42+
fi
43+
}
44+
6945
case "${EDGE_UNINSTALL_REMOVE_BROWSER:-}" in
70-
1) uninstall_browser ;;
71-
0) echo "leaving Chromium installed" ;;
46+
1) remove_chrome_cache ;;
47+
0) echo "leaving chrome-headless-shell cache at $CHROME_DIR" ;;
7248
*)
7349
if [ -t 0 ]; then
74-
printf "remove system Chromium too? [y/N] "
50+
printf "remove bundled chrome-headless-shell cache at %s? [y/N] " "$CHROME_DIR"
7551
read -r ans
7652
case "$ans" in
77-
[yY]|[yY][eE][sS]) uninstall_browser ;;
78-
*) echo "leaving Chromium installed" ;;
53+
[yY]|[yY][eE][sS]) remove_chrome_cache ;;
54+
*) echo "leaving chrome-headless-shell cache at $CHROME_DIR" ;;
7955
esac
8056
else
81-
echo "leaving Chromium installed (non-interactive)"
57+
echo "leaving chrome-headless-shell cache at $CHROME_DIR (non-interactive)"
8258
fi
8359
;;
8460
esac

0 commit comments

Comments
 (0)