lib/uninstall.sh

1.8 KB · 67 lines · bash

1#!/usr/bin/env bash
2
3BRT_INSTALL_DIR="${BRT_DIR:-${BRT_INSTALL_DIR:-${HOME}/.local/share/brt}}"
4BRT_BIN_DIR="${BRT_BIN_DIR:-${HOME}/.local/bin}"
5BRT_STATE_DIR="${HOME}/.brt"
6
7brt_uninstall_confirm() {
8 printf "Uninstall brt and remove packages it installed? [Y/n] "
9 read -r ans
10 [[ -z "$ans" || "$ans" =~ ^[Yy]$ ]]
11}
12
13brt_uninstall() {
14 brt_info "Removing brt..."
15
16 if ! brt_uninstall_confirm; then
17 brt_info "Uninstall cancelled"
18 return 0
19 fi
20
21 # Stop any access servers
22 if [[ -f "${BRT_LIB}/access.sh" ]]; then
23 # shellcheck source=access.sh
24 source "${BRT_LIB}/access.sh"
25 brt_access_force_stop 2>/dev/null || true
26 elif [[ -f "${BRT_STATE_DIR}/access.pid" ]]; then
27 local pid
28 pid=$(tr -d '[:space:]' < "${BRT_STATE_DIR}/access.pid" 2>/dev/null || true)
29 if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
30 kill "$pid" 2>/dev/null || true
31 brt_info "Stopped access server (PID ${pid})"
32 fi
33 fi
34
35 # Remove packages brt installed (tracked in ~/.brt/installed-deps)
36 if [[ -f "${BRT_LIB}/deps.sh" ]]; then
37 # shellcheck source=deps.sh
38 source "${BRT_LIB}/deps.sh"
39 brt_uninstall_media_dependencies || true
40 fi
41
42 # Remove symlink
43 if [[ -L "${BRT_BIN_DIR}/brt" || -f "${BRT_BIN_DIR}/brt" ]]; then
44 rm -f "${BRT_BIN_DIR}/brt"
45 brt_ok "Removed ${BRT_BIN_DIR}/brt"
46 fi
47
48 # Remove install directory
49 if [[ -d "$BRT_INSTALL_DIR" ]]; then
50 rm -rf "$BRT_INSTALL_DIR"
51 brt_ok "Removed ${BRT_INSTALL_DIR}"
52 fi
53
54 # Remove state/config
55 if [[ -d "$BRT_STATE_DIR" ]]; then
56 rm -rf "$BRT_STATE_DIR"
57 brt_ok "Removed ${BRT_STATE_DIR}"
58 fi
59
60 brt_ok "brt uninstalled"
61 # shellcheck source=update.sh
62 source "${BRT_LIB}/update.sh"
63 brt_remove_startup_check_hook || true
64 brt_info "Removed startup update checks from shell config"
65 brt_info "PATH entries in shell rc files were left unchanged"
66}
67