-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·700 lines (613 loc) · 21.8 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·700 lines (613 loc) · 21.8 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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
#!/usr/bin/env bash
set -euo pipefail
# Show error location on failure
trap 'error "Installation failed at line $LINENO."' ERR
# VibeCoding Installer
# Progressive and agile vibe-coding tool. No need to re-deploy Claw/Hermes;
# everything is packed into a single file.
# 主打渐进式、敏捷开发体验的 VibeCoding 工具,整体打包为单个文件,开箱即用,
# 无需重复搭建部署 Claude Code、codex、Claw、Hermes 环境。
#
# Downloads and installs the latest release from GitHub
#
# Supports non-root installation to ~/.vibecoding/bin
#
# Repository: https://github.com/startvibecoding/vibecoding
# Gitee: https://gitee.com/startvibecoding/vibecoding
# Author: zhenruyan
# Blog: https://pkold.com
REPO="startvibecoding/vibecoding"
BINARY_NAME="vibecoding"
# User-level install directory (no root required)
USER_INSTALL_DIR="${HOME}/.vibecoding/bin"
# Default install directory: auto-detect based on write permission
# Priority: INSTALL_DIR env > writable /usr/local/bin > ~/.vibecoding/bin
if [ -n "${INSTALL_DIR:-}" ]; then
: # User explicitly set INSTALL_DIR
elif [ -w "/usr/local/bin" ] || [ -w "/usr/local" ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="$USER_INSTALL_DIR"
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Show help
show_help() {
echo ""
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ VibeCoding Installer ║"
echo "║ https://github.com/startvibecoding/vibecoding ║"
echo "║ Author: zhenruyan | pkold.com ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""
echo "Usage: install.sh [OPTIONS]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -u, --uninstall Uninstall VibeCoding"
echo " -d, --dir DIR Install to DIR (default: auto-detect)"
echo ""
echo "Environment variables:"
echo " INSTALL_DIR Install directory (same as -d)"
echo ""
echo "Examples:"
echo " # Install (default)"
echo " curl -fsSL https://gitee.com/startvibecoding/vibecoding/raw/main/install.sh | bash"
echo ""
echo " # Install to custom directory"
echo " curl -fsSL https://gitee.com/startvibecoding/vibecoding/raw/main/install.sh | bash -s -- -d ~/.local/bin"
echo ""
echo " # Uninstall"
echo " curl -fsSL https://gitee.com/startvibecoding/vibecoding/raw/main/install.sh | bash -s -- --uninstall"
echo ""
echo " # Or download and run"
echo " ./install.sh --uninstall"
echo ""
}
# Uninstall VibeCoding
uninstall() {
echo ""
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ VibeCoding Uninstaller ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""
# Find vibecoding binary
local binary_path=""
local found_paths=()
# Check common install locations
for dir in "/usr/local/bin" "$USER_INSTALL_DIR" "$HOME/.local/bin"; do
if [ -f "$dir/$BINARY_NAME" ]; then
found_paths+=("$dir/$BINARY_NAME")
fi
done
# Also check PATH
if command -v "$BINARY_NAME" &> /dev/null; then
local which_path
which_path=$(which "$BINARY_NAME" 2>/dev/null || true)
if [ -n "$which_path" ] && [[ ! " ${found_paths[*]} " =~ " ${which_path} " ]]; then
found_paths+=("$which_path")
fi
fi
if [ ${#found_paths[@]} -eq 0 ]; then
warn "VibeCoding not found in common locations"
echo ""
echo "Checked locations:"
echo " - /usr/local/bin/$BINARY_NAME"
echo " - $USER_INSTALL_DIR/$BINARY_NAME"
echo " - $HOME/.local/bin/$BINARY_NAME"
echo ""
echo "If installed elsewhere, remove it manually:"
echo " rm <path>/$BINARY_NAME"
echo ""
return 0
fi
# Show found installations
info "Found VibeCoding installations:"
echo ""
for p in "${found_paths[@]}"; do
echo " - $p"
done
echo ""
# Ask for confirmation
local answer
read -rp "Remove all installations? [y/N] " answer
answer="${answer:-N}"
if [[ ! "$answer" =~ ^[Yy]$ ]]; then
info "Uninstall cancelled"
return 0
fi
# Remove binaries
echo ""
for p in "${found_paths[@]}"; do
if [ -f "$p" ]; then
if [ -w "$(dirname "$p")" ]; then
rm -f "$p"
success "Removed: $p"
else
info "Need sudo to remove: $p"
sudo rm -f "$p" && success "Removed: $p" || warn "Failed to remove: $p"
fi
fi
done
# Ask about config and sessions
echo ""
local config_dir="${HOME}/.vibecoding"
if [ -d "$config_dir" ]; then
info "Config directory: $config_dir"
echo ""
read -rp "Remove config directory ($config_dir)? [y/N] " answer
answer="${answer:-N}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
rm -rf "$config_dir"
success "Removed: $config_dir"
else
info "Kept: $config_dir"
fi
fi
# Ask about project .vibe directory
echo ""
local project_vibe="./.vibe"
if [ -d "$project_vibe" ]; then
info "Project config found: $project_vibe"
read -rp "Remove project config ($project_vibe)? [y/N] " answer
answer="${answer:-N}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
rm -rf "$project_vibe"
success "Removed: $project_vibe"
else
info "Kept: $project_vibe"
fi
fi
# Clean PATH entries
echo ""
info "Checking shell config for PATH entries..."
local config_file
config_file=$(detect_shell_config)
if [ -f "$config_file" ] && grep -q "\.vibecoding/bin" "$config_file" 2>/dev/null; then
info "Found PATH entry in: $config_file"
read -rp "Remove PATH entry from $config_file? [y/N] " answer
answer="${answer:-N}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
# Remove VibeCoding PATH entry (works for bash/zsh)
sed -i.bak '/# VibeCoding/,+1d' "$config_file"
rm -f "${config_file}.bak"
success "Removed PATH entry from $config_file"
fi
fi
# Uninstall npm package if installed via npm
echo ""
if command -v npm &> /dev/null; then
local npm_global
npm_global=$(npm root -g 2>/dev/null || true)
if [ -n "$npm_global" ] && [ -d "$npm_global/vibecoding-installer" ]; then
info "Found npm global installation"
read -rp "Uninstall npm package (vibecoding-installer)? [y/N] " answer
answer="${answer:-N}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
npm uninstall -g vibecoding-installer && success "Uninstalled npm package" || warn "Failed to uninstall npm package"
fi
fi
fi
echo ""
success "Uninstall complete!"
echo ""
echo " Thank you for using VibeCoding! 🙏"
echo ""
echo " If you have any feedback, please visit:"
echo " - GitHub: https://github.com/startvibecoding/vibecoding"
echo " - Gitee: https://gitee.com/startvibecoding/vibecoding"
echo ""
}
# Detect OS and architecture
detect_platform() {
local os arch
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
FreeBSD*) os="freebsd" ;;
CYGWIN*|MINGW*|MSYS*) os="windows" ;;
*) error "Unsupported OS: $(uname -s)" ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
armv7l|armhf) arch="arm" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
echo "${os}/${arch}"
}
# Get latest release version from GitHub
get_latest_version() {
local version
version=$(curl -sL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$version" ]; then
error "Failed to fetch latest version from GitHub"
fi
echo "$version"
}
# Download file
download() {
local url="$1"
local dest="$2"
info "Downloading: ${url}"
if command -v curl &> /dev/null; then
curl -sL -o "$dest" "$url"
elif command -v wget &> /dev/null; then
wget -qO "$dest" "$url"
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Verify checksum
verify_checksum() {
local file="$1"
local checksum_file="$2"
if [ ! -f "$checksum_file" ]; then
warn "Checksum file not found, skipping verification"
return 0
fi
local expected
expected=$(grep "$(basename "$file")" "$checksum_file" | awk '{print $1}' || true)
if [ -z "$expected" ]; then
warn "Checksum not found for $(basename "$file")"
return 0
fi
local actual
if command -v sha256sum &> /dev/null; then
actual=$(sha256sum "$file" | awk '{print $1}')
elif command -v shasum &> /dev/null; then
actual=$(shasum -a 256 "$file" | awk '{print $1}')
else
warn "No sha256sum or shasum found, skipping verification"
return 0
fi
if [ "$actual" != "$expected" ]; then
error "Checksum mismatch: expected ${expected}, got ${actual}"
fi
success "Checksum verified"
}
# Install binary (no sudo for user-level install)
install_binary() {
local binary_path="$1"
# Create install directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
info "Creating install directory: ${INSTALL_DIR}"
mkdir -p "$INSTALL_DIR" || error "Failed to create ${INSTALL_DIR}. Check permissions."
fi
# Install binary
mv "$binary_path" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
success "Installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
}
# Detect user's shell and config file
detect_shell_config() {
local shell_name
shell_name="$(basename "${SHELL:-bash}")"
case "$shell_name" in
zsh)
# Prefer .zshenv for PATH (loaded by all zsh modes)
if [ -f "${HOME}/.zshenv" ]; then
echo "${HOME}/.zshenv"
elif [ -f "${HOME}/.zshrc" ]; then
echo "${HOME}/.zshrc"
else
echo "${HOME}/.zshenv"
fi
;;
bash)
# macOS uses login shells by default, so .bash_profile takes precedence
if [ "$(uname -s)" = "Darwin" ]; then
if [ -f "${HOME}/.bash_profile" ]; then
echo "${HOME}/.bash_profile"
elif [ -f "${HOME}/.bashrc" ]; then
echo "${HOME}/.bashrc"
else
echo "${HOME}/.bash_profile"
fi
else
if [ -f "${HOME}/.bashrc" ]; then
echo "${HOME}/.bashrc"
elif [ -f "${HOME}/.bash_profile" ]; then
echo "${HOME}/.bash_profile"
else
echo "${HOME}/.bashrc"
fi
fi
;;
fish)
echo "${HOME}/.config/fish/config.fish"
;;
*)
echo "${HOME}/.profile"
;;
esac
}
# Add INSTALL_DIR to PATH in shell config
add_to_path() {
local config_file="$1"
local config_dir
config_dir="$(dirname "$config_file")"
# Create config directory if needed (e.g. ~/.config/fish/)
if [ ! -d "$config_dir" ]; then
mkdir -p "$config_dir"
fi
# Create config file if it doesn't exist
if [ ! -f "$config_file" ]; then
touch "$config_file"
fi
# Check if already in PATH config
if grep -q "\.vibecoding/bin" "$config_file" 2>/dev/null; then
info "PATH already configured in ${config_file}"
return 0
fi
local shell_name
shell_name="$(basename "${SHELL:-bash}")"
local path_line
case "$shell_name" in
fish)
# Single-quote $PATH to prevent bash from expanding it
path_line="set -gx PATH ${INSTALL_DIR} "'$PATH'
;;
*)
path_line="export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
echo "" >> "$config_file"
echo "# VibeCoding" >> "$config_file"
echo "$path_line" >> "$config_file"
success "Added ${INSTALL_DIR} to PATH in ${config_file}"
}
# Check if installed directory is in PATH
check_path() {
local config_file
config_file=$(detect_shell_config)
# First check if already configured in shell config file
if [ -f "$config_file" ] && grep -q "\.vibecoding/bin" "$config_file" 2>/dev/null; then
# Already in config, but check if it's in current session too
if echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
return 0
fi
info "PATH already configured in ${config_file} but not active in current session"
warn "Run: source ${config_file}"
return 0
fi
# If already in current PATH, nothing to do
if echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
return 0
fi
# For user-level install, auto-add to shell config
if [ "$INSTALL_DIR" = "$USER_INSTALL_DIR" ]; then
echo ""
info "Detected shell: $(basename "${SHELL:-bash}")"
info "Shell config: ${config_file}"
echo ""
# Ask user (default yes)
local answer
read -rp "Add ${INSTALL_DIR} to PATH automatically? [Y/n] " answer
answer="${answer:-Y}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
add_to_path "$config_file"
echo ""
warn "Run this to apply immediately:"
echo ""
local shell_name
shell_name="$(basename "${SHELL:-bash}")"
case "$shell_name" in
fish)
echo -e " ${CYAN}source ${config_file}${NC}"
;;
*)
echo -e " ${CYAN}source ${config_file}${NC}"
;;
esac
echo ""
else
warn "${INSTALL_DIR} is not in your PATH"
echo ""
echo "Add it manually to your shell configuration:"
echo ""
echo -e " ${CYAN}# bash/zsh:${NC}"
echo -e " ${CYAN}export PATH=\"${INSTALL_DIR}:\$PATH\"${NC}"
echo ""
echo -e " ${CYAN}# fish:${NC}"
echo -e " ${CYAN}set -gx PATH ${INSTALL_DIR} \$PATH${NC}"
echo ""
fi
else
# System install dir not in PATH (unusual)
warn "${INSTALL_DIR} is not in your PATH"
echo ""
echo "Add it to your shell configuration:"
echo ""
echo " For bash/zsh:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
echo " For fish:"
echo " set -gx PATH ${INSTALL_DIR} \$PATH"
echo ""
fi
}
# Main installation
main_install() {
echo ""
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ VibeCoding Installer ║"
echo "║ https://github.com/startvibecoding/vibecoding ║"
echo "║ Author: zhenruyan | pkold.com ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""
# Show install mode
if [ "$INSTALL_DIR" = "$USER_INSTALL_DIR" ]; then
info "Install mode: user-level (no root required)"
else
info "Install mode: system-level"
fi
info "Install directory: ${INSTALL_DIR}"
echo ""
# Detect platform
local platform
platform=$(detect_platform)
local os="${platform%/*}"
local arch="${platform#*/}"
info "Detected platform: ${os}/${arch}"
# Get latest version
local version
version=$(get_latest_version)
info "Latest version: ${version}"
# Construct download URL
local archive_name
local version_num="${version#v}"
if [ "$os" = "windows" ]; then
archive_name="${BINARY_NAME}-${version_num}-${os}-${arch}.zip"
else
archive_name="${BINARY_NAME}-${version_num}-${os}-${arch}.tar.gz"
fi
local download_url="https://github.com/${REPO}/releases/download/${version}/${archive_name}"
local checksum_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
# Create temp directory
local tmp_dir
tmp_dir=$(mktemp -d)
trap "rm -rf ${tmp_dir}" EXIT
# Download archive
local archive_path="${tmp_dir}/${archive_name}"
download "$download_url" "$archive_path"
# Download and verify checksum
local checksum_path="${tmp_dir}/checksums.txt"
download "$checksum_url" "$checksum_path" 2>/dev/null || true
verify_checksum "$archive_path" "$checksum_path"
# Extract archive
info "Extracting archive..."
local binary_path="${tmp_dir}/${BINARY_NAME}"
if [ "$os" = "windows" ]; then
if command -v unzip &> /dev/null; then
unzip -q "$archive_path" -d "$tmp_dir"
else
error "unzip not found. Please install unzip."
fi
binary_path="${tmp_dir}/${BINARY_NAME}.exe"
else
tar -xzf "$archive_path" -C "$tmp_dir"
fi
if [ ! -f "$binary_path" ]; then
error "Binary not found in archive"
fi
# Install binary (no sudo needed for user-level)
install_binary "$binary_path"
# Check PATH and offer to configure
check_path
# Determine config directory based on platform
local config_dir
case "$(uname -s)" in
Darwin*|Linux*)
config_dir="${HOME}/.vibecoding"
;;
*)
config_dir="${HOME}/.vibecoding"
;;
esac
# Verify installation
echo ""
success "Installation complete!"
echo ""
echo " Install directory: ${INSTALL_DIR}/${BINARY_NAME}"
echo " Config directory : ${config_dir}"
echo " - Settings file: ${config_dir}/settings.json"
echo ""
if command -v "$BINARY_NAME" &> /dev/null; then
local installed_version
installed_version=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")
echo " Version: ${installed_version}"
echo ""
echo " Get started:"
echo " ${BINARY_NAME} --help"
echo ""
else
warn "'${BINARY_NAME}' is not found in your current PATH."
echo ""
echo " Add it to your PATH manually:"
echo ""
local shell_name
shell_name="$(basename "${SHELL:-bash}")"
case "$shell_name" in
fish)
echo -e " ${CYAN}# Fish${NC}"
echo -e " ${CYAN}set -gx PATH ${INSTALL_DIR} \$PATH${NC}"
echo -e " ${CYAN}# Or add to ~/.config/fish/config.fish:${NC}"
echo -e " ${CYAN}set -gx PATH ${INSTALL_DIR} \$PATH${NC}"
;;
zsh)
echo -e " ${CYAN}# Zsh${NC}"
echo -e " ${CYAN}export PATH=\"${INSTALL_DIR}:\$PATH\"${NC}"
echo -e " ${CYAN}# Or add to ~/.zshenv:${NC}"
echo -e " ${CYAN}echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.zshenv${NC}"
;;
bash)
echo -e " ${CYAN}# Bash${NC}"
echo -e " ${CYAN}export PATH=\"${INSTALL_DIR}:\$PATH\"${NC}"
if [ "$(uname -s)" = "Darwin" ]; then
echo -e " ${CYAN}# Or add to ~/.bash_profile:${NC}"
echo -e " ${CYAN}echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.bash_profile${NC}"
else
echo -e " ${CYAN}# Or add to ~/.bashrc:${NC}"
echo -e " ${CYAN}echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.bashrc${NC}"
fi
;;
*)
echo -e " ${CYAN}export PATH=\"${INSTALL_DIR}:\$PATH\"${NC}"
echo -e " ${CYAN}# Add the above line to your shell config file${NC}"
;;
esac
echo ""
fi
}
# Parse arguments
ACTION="install"
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-u|--uninstall)
ACTION="uninstall"
shift
;;
-d|--dir)
if [ -z "${2:-}" ]; then
error "Option $1 requires an argument"
fi
INSTALL_DIR="$2"
shift 2
;;
*)
error "Unknown option: $1\nUse --help for usage information"
;;
esac
done
# Execute action
case "$ACTION" in
install)
main_install
;;
uninstall)
uninstall
;;
esac