-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·428 lines (365 loc) · 12.2 KB
/
install.sh
File metadata and controls
executable file
·428 lines (365 loc) · 12.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
#!/usr/bin/env bash
set -euo pipefail
# Show error location on failure
trap 'error "Installation failed at line $LINENO."' ERR
# VibeCoding Installer
# Downloads and installs the latest release from GitHub
#
# Supports non-root installation to ~/.vibecoding/bin
#
# Repository: https://github.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
}
# Detect OS and architecture
detect_platform() {
local os arch
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
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)
# .bashrc is most common; .bash_profile for login shells on macOS
if [ -f "${HOME}/.bashrc" ]; then
echo "${HOME}/.bashrc"
elif [ -f "${HOME}/.bash_profile" ]; then
echo "${HOME}/.bash_profile"
else
if [ "$(uname -s)" = "Darwin" ]; 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)
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() {
# If already in 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
local config_file
config_file=$(detect_shell_config)
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() {
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 ""
if command -v "$BINARY_NAME" &> /dev/null; then
local installed_version
installed_version=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")
success "Installation complete!"
echo ""
echo " Version: ${installed_version}"
echo ""
echo " Config directory: ${config_dir}"
echo " - Settings file : ${config_dir}/settings.json"
echo ""
echo " Get started:"
echo " ${BINARY_NAME} --help"
echo ""
else
success "Installation complete!"
echo ""
echo " Binary installed to:"
echo " ${INSTALL_DIR}/${BINARY_NAME}"
echo ""
echo " Config directory: ${config_dir}"
echo " - Settings file : ${config_dir}/settings.json"
echo ""
echo " To use right now:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo " ${BINARY_NAME} --help"
echo ""
fi
}
main "$@"