-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·350 lines (304 loc) · 10 KB
/
install.sh
File metadata and controls
executable file
·350 lines (304 loc) · 10 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env bash
set -euo pipefail
# DrClaw installer / updater / uninstaller
# Usage: bash <(curl -fsSL https://raw.githubusercontent.com/qzzqzzb/drclaw/main/install.sh) [install|update|uninstall] [--purge-data]
# --- Colors -----------------------------------------------------------
if [ -t 1 ] && command -v tput >/dev/null 2>&1; then
BOLD=$(tput bold)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
RESET=$(tput sgr0)
else
BOLD="" RED="" GREEN="" YELLOW="" BLUE="" RESET=""
fi
info() { printf '%s[info]%s %s\n' "$BLUE" "$RESET" "$*"; }
success() { printf '%s[ok]%s %s\n' "$GREEN" "$RESET" "$*"; }
warn() { printf '%s[warn]%s %s\n' "$YELLOW" "$RESET" "$*"; }
die() { printf '%s[error]%s %s\n' "$RED" "$RESET" "$*" >&2; exit 1; }
usage() {
cat <<EOF
Usage:
install.sh [install]
install.sh update
install.sh uninstall [--purge-data]
Examples:
bash <(curl -fsSL https://raw.githubusercontent.com/qzzqzzb/drclaw/main/install.sh)
bash <(curl -fsSL https://raw.githubusercontent.com/qzzqzzb/drclaw/main/install.sh) update
bash <(curl -fsSL https://raw.githubusercontent.com/qzzqzzb/drclaw/main/install.sh) uninstall
bash <(curl -fsSL https://raw.githubusercontent.com/qzzqzzb/drclaw/main/install.sh) uninstall --purge-data
EOF
}
# --- Config ------------------------------------------------------------
DRCLAW_DIR="${DRCLAW_DIR:-$HOME/.drclaw-src}"
DRCLAW_DATA_DIR="${DRCLAW_DATA_DIR:-$HOME/.drclaw}"
SYMLINK_DIR="$HOME/.local/bin"
REPO_URL="https://github.com/qzzqzzb/drclaw.git"
MIN_PYTHON="3.10"
ACTION="install"
PURGE_DATA=0
POSITIONAL_ACTION_SET=0
for arg in "$@"; do
case "$arg" in
install|update|uninstall)
if [ "$POSITIONAL_ACTION_SET" -eq 1 ]; then
die "Multiple actions specified. Choose one of: install, update, uninstall."
fi
ACTION="$arg"
POSITIONAL_ACTION_SET=1
;;
--purge-data)
PURGE_DATA=1
;;
-h|--help)
usage
exit 0
;;
*)
die "Unknown argument: $arg"
;;
esac
done
if [ "$ACTION" != "uninstall" ] && [ "$PURGE_DATA" -eq 1 ]; then
die "--purge-data is only supported with uninstall."
fi
OS=""
ARCH=""
detect_platform() {
info "Detecting platform..."
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) info "macOS $ARCH" ;;
Linux) info "Linux $ARCH" ;;
MINGW*|MSYS*|CYGWIN*)
die "Windows detected. Please use WSL: https://learn.microsoft.com/en-us/windows/wsl/install"
;;
*) die "Unsupported OS: $OS" ;;
esac
}
check_python() {
info "Checking Python..."
PYTHON=""
for candidate in python3 python; do
if command -v "$candidate" >/dev/null 2>&1; then
PYTHON="$candidate"
break
fi
done
if [ -z "$PYTHON" ]; then
die "Python not found. Install Python >= $MIN_PYTHON:
macOS: brew install python@3.12
Ubuntu: sudo apt install python3
Fedora: sudo dnf install python3"
fi
PY_VERSION=$("$PYTHON" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PY_MAJOR=$("$PYTHON" -c 'import sys; print(sys.version_info.major)')
PY_MINOR=$("$PYTHON" -c 'import sys; print(sys.version_info.minor)')
if [ "$PY_MAJOR" -lt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 10 ]; }; then
die "Python $PY_VERSION found, but >= $MIN_PYTHON required.
macOS: brew install python@3.12
Ubuntu: sudo apt install python3.12"
fi
success "Python $PY_VERSION"
}
ensure_uv() {
if ! command -v uv >/dev/null 2>&1; then
info "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Source uv into current shell
if [ -f "$HOME/.local/bin/env" ]; then
# shellcheck disable=SC1091
. "$HOME/.local/bin/env"
elif [ -f "$HOME/.cargo/env" ]; then
# shellcheck disable=SC1091
. "$HOME/.cargo/env"
fi
command -v uv >/dev/null 2>&1 || die "uv installed but not on PATH. Restart your shell and re-run."
success "uv installed"
else
success "uv $(uv --version 2>/dev/null || echo '(found)')"
fi
}
ensure_git() {
command -v git >/dev/null 2>&1 || die "git not found. Install git first."
}
configure_sparse_checkout() {
mkdir -p "$DRCLAW_DIR/.git/info"
git -C "$DRCLAW_DIR" config core.sparseCheckout true
git -C "$DRCLAW_DIR" config core.sparseCheckoutCone false
cat > "$DRCLAW_DIR/.git/info/sparse-checkout" <<'EOF'
/*
!/assets/demos/
!/assets/demos/**
EOF
}
sync_repo() {
if [ -d "$DRCLAW_DIR/.git" ]; then
info "Updating $DRCLAW_DIR..."
configure_sparse_checkout
git -C "$DRCLAW_DIR" read-tree -mu HEAD
git -C "$DRCLAW_DIR" pull --rebase --quiet
success "Repository updated"
else
if [ -d "$DRCLAW_DIR" ]; then
warn "$DRCLAW_DIR exists but is not a git repo. Removing and re-cloning..."
rm -rf "$DRCLAW_DIR"
fi
info "Cloning DrClaw into $DRCLAW_DIR..."
git clone --quiet --filter=blob:none --no-checkout "$REPO_URL" "$DRCLAW_DIR"
configure_sparse_checkout
git -C "$DRCLAW_DIR" checkout --quiet HEAD
success "Repository cloned"
fi
}
install_dependencies() {
info "Installing dependencies (this may take a minute)..."
cd "$DRCLAW_DIR"
if [ "$OS" = "Darwin" ]; then
uv sync --extra tray --quiet
else
uv sync --quiet
fi
success "Dependencies installed"
}
symlink_binary() {
DRCLAW_BIN="$DRCLAW_DIR/.venv/bin/drclaw"
if [ ! -f "$DRCLAW_BIN" ]; then
die "Expected binary not found at $DRCLAW_BIN. Installation may have failed."
fi
mkdir -p "$SYMLINK_DIR"
ln -sf "$DRCLAW_BIN" "$SYMLINK_DIR/drclaw"
success "Symlinked drclaw -> $SYMLINK_DIR/drclaw"
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$SYMLINK_DIR"; then
SHELL_NAME="$(basename "${SHELL:-/bin/bash}")"
case "$SHELL_NAME" in
zsh) RC_FILE="~/.zshrc" ;;
bash) RC_FILE="~/.bashrc" ;;
fish) RC_FILE="~/.config/fish/config.fish" ;;
*) RC_FILE="your shell rc file" ;;
esac
warn "$SYMLINK_DIR is not in your PATH. Add it:"
if [ "$SHELL_NAME" = "fish" ]; then
echo " ${BOLD}fish_add_path $SYMLINK_DIR${RESET}"
else
echo " ${BOLD}echo 'export PATH=\"$SYMLINK_DIR:\$PATH\"' >> $RC_FILE${RESET}"
fi
echo ""
export PATH="$SYMLINK_DIR:$PATH"
fi
}
run_onboard() {
info "Running onboard..."
if drclaw onboard 2>/dev/null; then
success "Onboard complete"
else
warn "Onboard skipped (command may not exist yet — run 'drclaw onboard' manually)"
fi
}
print_install_summary() {
local label="$1"
echo ""
echo "${BOLD}${GREEN}DrClaw ${label}!${RESET}"
echo ""
echo " Source: $DRCLAW_DIR"
echo " Binary: $SYMLINK_DIR/drclaw"
echo " Config: $DRCLAW_DATA_DIR/config.json"
echo ""
echo "${BOLD}Next steps:${RESET}"
echo " 1. Set your API key in ${BOLD}$DRCLAW_DATA_DIR/config.json${RESET}"
echo " 2. Launch DrClaw: ${BOLD}drclaw daemon --debug-full -f web${RESET}"
echo ""
}
best_effort_uninstall_launchd() {
if [ "$OS" != "Darwin" ]; then
return
fi
if [ -x "$DRCLAW_DIR/.venv/bin/drclaw" ]; then
info "Stopping macOS LaunchAgent (if installed)..."
if "$DRCLAW_DIR/.venv/bin/drclaw" launchd uninstall >/dev/null 2>&1; then
success "LaunchAgent removed"
else
warn "LaunchAgent uninstall skipped"
fi
return
fi
if command -v drclaw >/dev/null 2>&1; then
info "Stopping macOS LaunchAgent (if installed)..."
if drclaw launchd uninstall >/dev/null 2>&1; then
success "LaunchAgent removed"
else
warn "LaunchAgent uninstall skipped"
fi
fi
}
do_install_or_update() {
detect_platform
check_python
ensure_uv
ensure_git
if [ "$ACTION" = "update" ] && [ ! -d "$DRCLAW_DIR/.git" ]; then
warn "Existing installation not found at $DRCLAW_DIR. Proceeding with a fresh install."
fi
sync_repo
install_dependencies
symlink_binary
run_onboard
if [ "$ACTION" = "update" ]; then
print_install_summary "updated"
else
print_install_summary "installed"
fi
}
do_uninstall() {
detect_platform
best_effort_uninstall_launchd
if [ -L "$SYMLINK_DIR/drclaw" ] || [ -e "$SYMLINK_DIR/drclaw" ]; then
info "Removing $SYMLINK_DIR/drclaw..."
rm -f "$SYMLINK_DIR/drclaw"
success "Removed binary symlink"
else
warn "Binary symlink not found at $SYMLINK_DIR/drclaw"
fi
if [ -d "$DRCLAW_DIR" ]; then
info "Removing $DRCLAW_DIR..."
rm -rf "$DRCLAW_DIR"
success "Removed source directory"
else
warn "Source directory not found at $DRCLAW_DIR"
fi
if [ "$PURGE_DATA" -eq 1 ]; then
if [ -d "$DRCLAW_DATA_DIR" ]; then
info "Removing $DRCLAW_DATA_DIR..."
rm -rf "$DRCLAW_DATA_DIR"
success "Removed data directory"
else
warn "Data directory not found at $DRCLAW_DATA_DIR"
fi
fi
echo ""
echo "${BOLD}${GREEN}DrClaw uninstalled!${RESET}"
echo ""
echo " Removed source: $DRCLAW_DIR"
echo " Removed binary: $SYMLINK_DIR/drclaw"
if [ "$PURGE_DATA" -eq 1 ]; then
echo " Removed data: $DRCLAW_DATA_DIR"
else
echo " Preserved data: $DRCLAW_DATA_DIR"
echo " To remove all local data too, run:"
echo " ${BOLD}bash <(curl -fsSL https://raw.githubusercontent.com/qzzqzzb/drclaw/main/install.sh) uninstall --purge-data${RESET}"
fi
echo ""
}
case "$ACTION" in
install|update)
do_install_or_update
;;
uninstall)
do_uninstall
;;
*)
die "Unsupported action: $ACTION"
;;
esac