forked from rayclaw/rayclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·111 lines (91 loc) · 1.94 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·111 lines (91 loc) · 1.94 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
#!/usr/bin/env bash
set -euo pipefail
BIN_NAME="rayclaw"
log() {
printf '%s\n' "$*"
}
err() {
printf 'Error: %s\n' "$*" >&2
}
need_cmd() {
command -v "$1" >/dev/null 2>&1
}
detect_os() {
case "$(uname -s)" in
Darwin) echo "darwin" ;;
Linux) echo "linux" ;;
*)
err "Unsupported OS: $(uname -s)"
exit 1
;;
esac
}
resolve_targets() {
local out=()
if [ -n "${RAYCLAW_INSTALL_DIR:-}" ]; then
out+=("${RAYCLAW_INSTALL_DIR%/}/$BIN_NAME")
fi
if need_cmd "$BIN_NAME"; then
out+=("$(command -v "$BIN_NAME")")
fi
out+=("/usr/local/bin/$BIN_NAME")
out+=("$HOME/.local/bin/$BIN_NAME")
# De-duplicate while preserving order.
local seen="|"
local path
for path in "${out[@]}"; do
if [ -n "$path" ] && [[ "$seen" != *"|$path|"* ]]; then
printf '%s\n' "$path"
seen+="$path|"
fi
done
}
remove_file() {
local target="$1"
if [ ! -e "$target" ]; then
return 1
fi
if [ -w "$target" ] || [ -w "$(dirname "$target")" ]; then
rm -f "$target"
else
if need_cmd sudo; then
sudo rm -f "$target"
else
err "No permission to remove $target and sudo is unavailable"
return 2
fi
fi
return 0
}
main() {
local os removed=0 failed=0 target
os="$(detect_os)"
log "Uninstalling $BIN_NAME on $os..."
while IFS= read -r target; do
if [ -z "$target" ]; then
continue
fi
if remove_file "$target"; then
log "Removed: $target"
removed=$((removed + 1))
else
rc=$?
if [ "$rc" -eq 2 ]; then
failed=1
fi
fi
done < <(resolve_targets)
if [ "$failed" -ne 0 ]; then
exit 1
fi
if [ "$removed" -eq 0 ]; then
log "$BIN_NAME binary not found. Nothing to uninstall."
exit 0
fi
log ""
log "$BIN_NAME has been removed."
log "Optional cleanup (not removed automatically):"
log " rm -rf ./rayclaw.data/runtime"
log " rm -f ./rayclaw.config.yaml ./rayclaw.config.yml"
}
main "$@"