-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathinstall.sh
More file actions
547 lines (472 loc) · 14.2 KB
/
install.sh
File metadata and controls
547 lines (472 loc) · 14.2 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
#!/bin/bash
set -e
REPO="maxritter/pilot-shell"
VERSION="${VERSION:-}"
VERSION="${VERSION#v}"
INSTALLER_ARGS=""
RESTART_PILOT=false
AUTO_UPDATE=false
SKIP_VERSION_CHECK=false
USE_LOCAL_INSTALLER=false
while [ $# -gt 0 ]; do
case "$1" in
--restart-pilot)
# Legacy flag from v8.x and early v9.0.x — implies auto-update and
# auto-restart. Newer launchers pass --auto-update instead so we no
# longer inherit a raw-mode terminal from the Rich installer.
RESTART_PILOT=true
AUTO_UPDATE=true
shift
;;
--auto-update)
# Skip the local-install confirm prompt without auto-restarting Pilot.
# Called by `pilot update` in v9.0.x post-fix.
AUTO_UPDATE=true
shift
;;
--skip-version-check)
SKIP_VERSION_CHECK=true
shift
;;
--local)
USE_LOCAL_INSTALLER=true
SKIP_VERSION_CHECK=true
shift
;;
*)
if [ -z "$INSTALLER_ARGS" ]; then
INSTALLER_ARGS="$1"
else
INSTALLER_ARGS="$INSTALLER_ARGS $1"
fi
shift
;;
esac
done
get_latest_release() {
local redirect_url="https://github.com/${REPO}/releases/latest"
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
local version=""
if command -v curl >/dev/null 2>&1; then
local redirect_location
redirect_location=$(curl -sIo /dev/null -w '%{redirect_url}' "$redirect_url" 2>/dev/null | tr -d '\r') || true
if [ -n "$redirect_location" ] && [ "$redirect_location" != "%{redirect_url}" ]; then
version=$(echo "$redirect_location" | sed -n 's|.*/releases/tag/v\([^/]*\).*|\1|p') || true
fi
elif command -v wget >/dev/null 2>&1; then
local redirect_location
redirect_location=$(wget --spider -S "$redirect_url" 2>&1 | grep -i 'location:' | tail -1 | sed 's/.*location: *//I' | tr -d '\r') || true
if [ -n "$redirect_location" ]; then
version=$(echo "$redirect_location" | sed -n 's|.*/releases/tag/v\([^/]*\).*|\1|p') || true
fi
fi
if [ -n "$version" ]; then
echo "$version"
return 0
fi
if command -v curl >/dev/null 2>&1; then
version=$(curl -fsSL "$api_url" 2>/dev/null | grep -m1 '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/') || true
elif command -v wget >/dev/null 2>&1; then
version=$(wget -qO- "$api_url" 2>/dev/null | grep -m1 '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/') || true
fi
if [ -n "$version" ]; then
echo "$version"
return 0
fi
return 1
}
if [ -z "$VERSION" ]; then
echo " [..] Fetching latest version..."
VERSION=$(get_latest_release) || true
if [ -z "$VERSION" ]; then
echo " [!!] Failed to fetch latest version from GitHub."
echo " [!!] Please specify a version: VERSION=6.0.0 curl ... | bash"
exit 1
fi
echo " [OK] Latest version: $VERSION"
else
echo " Using specified version: $VERSION"
if [ "$SKIP_VERSION_CHECK" = true ]; then
echo " [..] Skipping version check (--skip-version-check)"
fi
fi
case "$VERSION" in
dev-*)
REPO_RAW="https://raw.githubusercontent.com/${REPO}/${VERSION}"
;;
*)
REPO_RAW="https://raw.githubusercontent.com/${REPO}/v${VERSION}"
;;
esac
is_in_container() {
[ -f "/.dockerenv" ] || [ -f "/run/.containerenv" ]
}
download_file() {
local path="$1"
local dest="$2"
local url="${REPO_RAW}/${path}"
mkdir -p "$(dirname "$dest")"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$dest"
elif command -v wget >/dev/null 2>&1; then
wget -q "$url" -O "$dest"
else
echo "Error: Neither curl nor wget found."
exit 1
fi
}
check_uv() {
command -v uv >/dev/null 2>&1
}
install_uv() {
local UV_INSTALL_URL="https://astral.sh/uv/install.sh"
local UV_INSTALL_SHA256="3a020f8d69019caca567c9038999d130b0ea85866483caf2042c386cb685aef4"
local tmp_uv
tmp_uv="$(mktemp -t pilot-uv-install.XXXXXX.sh)" || tmp_uv=/tmp/pilot-uv-install.sh
trap "rm -f \"$tmp_uv\"" EXIT
chmod 600 "$tmp_uv" 2>/dev/null || true
echo " [..] Installing uv (pinned)..."
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$UV_INSTALL_URL" -o "$tmp_uv" || {
echo " [!!] curl failed"
exit 1
}
elif command -v wget >/dev/null 2>&1; then
wget -qO "$tmp_uv" "$UV_INSTALL_URL" || {
echo " [!!] wget failed"
exit 1
}
else
echo " [!!] Need curl or wget"
exit 1
fi
local actual_sha
if command -v shasum >/dev/null 2>&1; then
actual_sha="$(shasum -a 256 "$tmp_uv" | awk '{print $1}')"
elif command -v sha256sum >/dev/null 2>&1; then
actual_sha="$(sha256sum "$tmp_uv" | awk '{print $1}')"
else
echo " [!!] Neither shasum nor sha256sum available — cannot verify uv installer"
exit 1
fi
if [ "$actual_sha" != "$UV_INSTALL_SHA256" ]; then
echo " [!!] uv install.sh sha256 mismatch:"
echo " expected: $UV_INSTALL_SHA256"
echo " actual: $actual_sha"
echo " refusing to execute. Audit upstream and update installer/upstreams.yaml."
exit 1
fi
sh "$tmp_uv"
trap - EXIT
rm -f "$tmp_uv"
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if ! check_uv; then
echo " [!!] Failed to install uv"
exit 1
fi
echo " [OK] uv installed"
}
show_macos_gatekeeper_warning() {
echo ""
echo " ⚠️ macOS Gatekeeper is blocking the pilot binary"
echo ""
echo " The installer requires pilot to verify your license."
echo " Please follow these steps to unblock it:"
echo ""
echo " 1. Open System Settings → Privacy & Security"
echo " 2. Scroll down to find a message about 'pilot' being blocked"
echo " 3. Click 'Allow Anyway'"
echo " 4. Re-run this installer"
echo ""
echo " Or run this command to remove the quarantine flag:"
echo " xattr -cr $HOME/.pilot/bin"
echo ""
}
confirm_local_install() {
echo ""
echo " Local installation will:"
echo " • Add 'pilot' and 'ccp' command to your favorite shell config (~/.bashrc, ~/.zshrc, fish)"
echo " • Configure Claude Code (~/.claude.json, ~/.claude/settings.json) and Codex CLI (~/.codex/config.toml) to Pilot best-practices"
echo " • Install additional tool dependencies via Homebrew or NPM on your system"
echo ""
confirm=""
if [ -t 0 ]; then
printf " Continue? [Y/n]: "
read -r confirm
elif [ -e /dev/tty ]; then
printf " Continue? [Y/n]: "
read -r confirm </dev/tty
else
echo " No interactive terminal available, continuing with defaults."
confirm="y"
fi
case "$confirm" in
[Nn] | [Nn][Oo])
echo " Cancelled."
exit 0
;;
esac
}
download_installer() {
local installer_dir="$HOME/.pilot/installer"
echo " [..] Downloading installer..."
rm -rf "$installer_dir"
mkdir -p "$installer_dir/installer"
local base_url=""
case "$VERSION" in
dev-*) base_url="https://github.com/${REPO}/releases/download/${VERSION}" ;;
*) base_url="https://github.com/${REPO}/releases/download/v${VERSION}" ;;
esac
local tree_url="${base_url}/tree.json"
local tag_ref=""
case "$VERSION" in
dev-*) tag_ref="$VERSION" ;;
*) tag_ref="v${VERSION}" ;;
esac
local api_url="https://api.github.com/repos/${REPO}/git/trees/${tag_ref}?recursive=true"
local tree_json=""
if command -v curl >/dev/null 2>&1; then
tree_json=$(curl -fsSL "$tree_url" 2>/dev/null) || true
elif command -v wget >/dev/null 2>&1; then
tree_json=$(wget -qO- "$tree_url" 2>/dev/null) || true
fi
if [ -z "$tree_json" ]; then
if command -v curl >/dev/null 2>&1; then
tree_json=$(curl -fsSL "$api_url" 2>/dev/null) || true
elif command -v wget >/dev/null 2>&1; then
tree_json=$(wget -qO- "$api_url" 2>/dev/null) || true
fi
fi
if [ -z "$tree_json" ]; then
echo " [!!] Failed to fetch file list from GitHub API"
exit 1
fi
echo "$tree_json" | grep -oE '"path": ?"installer/[^"]*\.(py|yaml)"' | sed 's/"path": *"//g; s/"$//g' | while IFS= read -r file_path; do
case "$file_path" in
*__pycache__* | *dist/* | *build/* | *tests/*) continue ;;
esac
local dest_file="$installer_dir/$file_path"
mkdir -p "$(dirname "$dest_file")"
download_file "$file_path" "$dest_file"
done
download_file "pyproject.toml" "$installer_dir/pyproject.toml"
echo " [OK] Installer downloaded"
}
get_platform_suffix() {
local os_name=""
local arch=""
case "$(uname -s)" in
Linux) os_name="linux" ;;
Darwin) os_name="darwin" ;;
*) return 1 ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch="x86_64" ;;
arm64 | aarch64) arch="arm64" ;;
*) return 1 ;;
esac
echo "${os_name}-${arch}"
}
get_local_so_name() {
local platform_tag=""
case "$(uname -s)" in
Linux)
case "$(uname -m)" in
x86_64 | amd64) platform_tag="x86_64-linux-gnu" ;;
arm64 | aarch64) platform_tag="aarch64-linux-gnu" ;;
esac
;;
Darwin) platform_tag="darwin" ;;
esac
echo "pilot.cpython-312-${platform_tag}.so"
}
download_pilot_binary() {
local bin_dir="$HOME/.pilot/bin"
local platform_suffix
local so_name
local base_url
platform_suffix=$(get_platform_suffix) || {
echo " [!!] Unsupported platform for Pilot binary"
return 1
}
so_name=$(get_local_so_name)
case "$VERSION" in
dev-*) base_url="https://github.com/${REPO}/releases/download/${VERSION}" ;;
*) base_url="https://github.com/${REPO}/releases/download/v${VERSION}" ;;
esac
if [ -d "$bin_dir" ]; then
rm -rf "$bin_dir"
fi
mkdir -p "$bin_dir"
echo " [..] Downloading Pilot binary (${platform_suffix})..."
local so_url="${base_url}/pilot-${platform_suffix}.so"
local so_path="${bin_dir}/${so_name}"
if command -v curl >/dev/null 2>&1; then
if ! curl -fsSL "$so_url" -o "$so_path" 2>/dev/null; then
echo " [!!] Failed to download pilot module"
return 1
fi
elif command -v wget >/dev/null 2>&1; then
if ! wget -q "$so_url" -O "$so_path" 2>/dev/null; then
echo " [!!] Failed to download pilot module"
return 1
fi
fi
chmod +x "$so_path"
local wrapper_url="${base_url}/pilot"
local wrapper_path="${bin_dir}/pilot"
if command -v curl >/dev/null 2>&1; then
if ! curl -fsSL "$wrapper_url" -o "$wrapper_path" 2>/dev/null; then
echo " [!!] Failed to download pilot wrapper"
rm -f "$so_path"
return 1
fi
elif command -v wget >/dev/null 2>&1; then
if ! wget -q "$wrapper_url" -O "$wrapper_path" 2>/dev/null; then
echo " [!!] Failed to download pilot wrapper"
rm -f "$so_path"
return 1
fi
fi
chmod +x "$wrapper_path"
echo " [..] Verifying pilot binary..."
local pilot_version
pilot_version=$("$wrapper_path" --version 2>/dev/null) || true
if [ -z "$pilot_version" ] && [ "$(uname -s)" = "Darwin" ]; then
echo " [..] Removing macOS quarantine attributes..."
xattr -cr "$bin_dir" 2>/dev/null || true
spctl --add "$wrapper_path" 2>/dev/null || true
spctl --add "$so_path" 2>/dev/null || true
pilot_version=$("$wrapper_path" --version 2>/dev/null) || true
fi
if [ -z "$pilot_version" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
show_macos_gatekeeper_warning
exit 1
else
echo " [!!] Pilot binary failed to execute"
return 1
fi
fi
local installed_version
installed_version=$(echo "$pilot_version" | sed -n 's/.* v\([^ ]*\).*/\1/p')
if [ -z "$installed_version" ]; then
echo " [!!] Could not determine pilot version"
return 1
fi
echo " [OK] Pilot binary ready (v${installed_version})"
}
run_installer() {
local installer_dir="$HOME/.pilot/installer"
echo ""
export PYTHONPATH="$installer_dir:${PYTHONPATH:-}"
local version_arg="--target-version $VERSION"
local local_arg=""
if [ "$USE_LOCAL_INSTALLER" = true ]; then
local_arg="--local --local-repo-dir $(pwd)"
fi
local system_arg=""
if ! is_in_container; then
system_arg="--local-system"
fi
uv run --python 3.12 --no-project \
--with rich==15.0.0 --with certifi==2026.5.20 --with PyYAML==6.0.3 \
python -m installer install $system_arg $version_arg $local_arg "$@"
}
is_native_windows() {
case "$(uname -s)" in
MINGW* | MSYS* | CYGWIN*) return 0 ;;
*) return 1 ;;
esac
}
if is_native_windows; then
echo ""
echo "======================================================================"
echo " Pilot Shell — Windows Detected"
echo "======================================================================"
echo ""
echo " Pilot Shell requires a Unix environment (macOS, Linux, or WSL2)."
echo ""
echo " Install WSL2 first (PowerShell as admin):"
echo " wsl --install -d Ubuntu"
echo ""
echo " Then open Ubuntu and re-run this installer."
echo ""
exit 1
fi
echo ""
echo "======================================================================"
echo " Pilot Shell Installer (v${VERSION})"
echo "======================================================================"
echo ""
if is_in_container; then
echo " Running inside container — skipping system dependencies"
echo ""
elif [ "$AUTO_UPDATE" = true ]; then
echo " Updating local installation..."
echo ""
elif [ "$USE_LOCAL_INSTALLER" = true ]; then
echo " Local installation selected (--local)"
echo ""
confirm_local_install
else
confirm_local_install
fi
echo ""
echo "Downloading Pilot Shell (v${VERSION})..."
echo ""
if check_uv; then
echo " [OK] uv already installed"
else
install_uv
fi
if ! command -v git >/dev/null 2>&1; then
case "$(uname -s)" in
Linux)
if command -v dnf >/dev/null 2>&1; then
echo " [..] Installing git (required by Homebrew)..."
sudo dnf install -y git && echo " [OK] git installed" ||
echo " [!!] Failed to install git via dnf"
elif command -v yum >/dev/null 2>&1; then
echo " [..] Installing git (required by Homebrew)..."
sudo yum install -y git && echo " [OK] git installed" ||
echo " [!!] Failed to install git via yum"
elif command -v apt-get >/dev/null 2>&1; then
echo " [..] Installing git (required by Homebrew)..."
sudo apt-get update -qq && sudo apt-get install -y git &&
echo " [OK] git installed" ||
echo " [!!] Failed to install git via apt"
fi
;;
esac
fi
if [ "$USE_LOCAL_INSTALLER" = true ]; then
if [ -d "installer" ] && [ -f "pyproject.toml" ]; then
echo " [OK] Using local installer from current directory"
rm -rf "$HOME/.pilot/installer"
mkdir -p "$HOME/.pilot/installer"
ln -sf "$(pwd)/installer" "$HOME/.pilot/installer/installer"
ln -sf "$(pwd)/pyproject.toml" "$HOME/.pilot/installer/pyproject.toml"
else
echo " [!!] --local requires running from pilot-shell repo root"
echo " [!!] Missing: installer/ directory or pyproject.toml"
exit 1
fi
else
download_installer
fi
download_pilot_binary
run_installer $INSTALLER_ARGS
if [ "$RESTART_PILOT" = true ]; then
PILOT_BIN="$HOME/.pilot/bin/pilot"
if [ -x "$PILOT_BIN" ]; then
echo ""
if [ "${PILOT_RESTART_BOT_MODE:-}" = "1" ]; then
echo " Restarting Pilot Bot..."
else
echo " Restarting Pilot Shell..."
fi
echo ""
exec "$PILOT_BIN" --skip-update-check
fi
fi