-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·87 lines (74 loc) · 2.06 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·87 lines (74 loc) · 2.06 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
#!/bin/sh
set -eu
INSTALL_ROOT="${CODEXDECK_INSTALL_ROOT:-${XDG_DATA_HOME:-$HOME/.local/share}/codexdeck}"
BIN_DIR="${CODEXDECK_BIN_DIR:-$HOME/.local/bin}"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/codexdeck"
PURGE_CONFIG=0
usage() {
cat <<'EOF'
Uninstall the user-owned CodexDeck installation.
Usage: ./uninstall.sh [options]
Options:
--install-root PATH Installation data directory.
--bin-dir PATH Directory containing the codexdeck command link.
--purge-config Also remove CodexDeck preferences.
-h, --help Show this help.
EOF
}
fail() {
printf 'codexdeck uninstaller: %s\n' "$*" >&2
exit 1
}
while [ "$#" -gt 0 ]; do
case "$1" in
--install-root)
[ "$#" -ge 2 ] || fail "--install-root requires a value"
INSTALL_ROOT=$2
shift 2
;;
--bin-dir)
[ "$#" -ge 2 ] || fail "--bin-dir requires a value"
BIN_DIR=$2
shift 2
;;
--purge-config)
PURGE_CONFIG=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
fail "unknown option: $1"
;;
esac
done
absolute_path() {
case "$1" in
/*) printf '%s\n' "$1" ;;
*) printf '%s/%s\n' "$(pwd -P)" "$1" ;;
esac
}
INSTALL_ROOT=$(absolute_path "$INSTALL_ROOT")
BIN_DIR=$(absolute_path "$BIN_DIR")
COMMAND_LINK="$BIN_DIR/codexdeck"
if [ -L "$COMMAND_LINK" ]; then
LINK_TARGET=$(readlink "$COMMAND_LINK")
case "$LINK_TARGET" in
"$INSTALL_ROOT"/*) rm -f "$COMMAND_LINK" ;;
*) fail "$COMMAND_LINK does not point into the CodexDeck installation" ;;
esac
elif [ -e "$COMMAND_LINK" ]; then
fail "$COMMAND_LINK exists but is not the CodexDeck installer link"
fi
if [ -d "$INSTALL_ROOT" ]; then
rm -rf "$INSTALL_ROOT"
fi
if [ "$PURGE_CONFIG" -eq 1 ] && [ -d "$CONFIG_DIR" ]; then
rm -rf "$CONFIG_DIR"
fi
printf 'CodexDeck was removed.\n'
if [ "$PURGE_CONFIG" -eq 0 ]; then
printf 'Preferences were retained in %s.\n' "$CONFIG_DIR"
fi