|
1 | 1 | #!/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. |
3 | 3 |
|
4 | 4 | set -e |
5 | 5 |
|
6 | 6 | INSTALL_DIR="${EDGE_INSTALL_DIR:-$HOME/.local/bin}" |
7 | 7 |
|
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}" |
51 | 10 |
|
52 | 11 | # 1. Binary. |
53 | 12 | if [ -f "$INSTALL_DIR/edge" ]; then |
|
57 | 16 | echo "no edge binary at $INSTALL_DIR/edge" |
58 | 17 | fi |
59 | 18 |
|
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. |
61 | 20 | 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 |
63 | 24 | sed -i.edgebak "\|export PATH=\"$INSTALL_DIR:\$PATH\"|d" "$rc" |
64 | | - echo "cleaned PATH entry from $rc (backup at $rc.edgebak)" |
| 25 | + changed=1 |
65 | 26 | 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)" |
66 | 33 | done |
67 | 34 |
|
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 | + |
69 | 45 | 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" ;; |
72 | 48 | *) |
73 | 49 | 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" |
75 | 51 | read -r ans |
76 | 52 | 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" ;; |
79 | 55 | esac |
80 | 56 | else |
81 | | - echo "leaving Chromium installed (non-interactive)" |
| 57 | + echo "leaving chrome-headless-shell cache at $CHROME_DIR (non-interactive)" |
82 | 58 | fi |
83 | 59 | ;; |
84 | 60 | esac |
|
0 commit comments