-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·400 lines (332 loc) · 9.75 KB
/
install.sh
File metadata and controls
executable file
·400 lines (332 loc) · 9.75 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
#!/bin/bash
set -e
# Configuration
REPO="aurabx/runbeam-cli"
BINARY_NAME="runbeam"
GITHUB_API="https://api.github.com/repos"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
log_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
log_success() {
echo -e "${GREEN}✓${NC} $1"
}
log_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
log_error() {
echo -e "${RED}✗${NC} $1"
}
# Detect OS and architecture
detect_platform() {
local os
local arch
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Darwin)
case "$arch" in
arm64|aarch64)
TARGET="aarch64-apple-darwin"
;;
x86_64)
TARGET="x86_64-apple-darwin"
;;
*)
log_error "Unsupported macOS architecture: $arch"
exit 1
;;
esac
;;
Linux)
case "$arch" in
x86_64)
TARGET="x86_64-unknown-linux-musl"
;;
aarch64|arm64)
TARGET="aarch64-unknown-linux-musl"
;;
*)
log_error "Unsupported Linux architecture: $arch"
exit 1
;;
esac
;;
MINGW64_NT*|MSYS_NT*)
TARGET="x86_64-pc-windows-msvc"
;;
*)
log_error "Unsupported OS: $os"
exit 1
;;
esac
log_info "Detected platform: $TARGET"
}
# Get the latest release version
get_latest_release() {
log_info "Fetching latest release information..."
local response
response=$(curl -s "${GITHUB_API}/${REPO}/releases/latest")
if echo "$response" | grep -q "Not Found"; then
log_error "Repository not found or has no releases"
exit 1
fi
VERSION=$(echo "$response" | grep '"tag_name"' | head -1 | cut -d'"' -f4)
if [ -z "$VERSION" ]; then
log_error "Failed to determine latest version"
exit 1
fi
log_info "Latest version: $VERSION"
}
# Construct download URL
get_download_url() {
# Determine file extension based on target
case "$TARGET" in
*-windows-*)
EXTENSION="zip"
;;
*)
EXTENSION="tar.gz"
;;
esac
FILENAME="${BINARY_NAME}-${TARGET}.${EXTENSION}"
CHECKSUM_FILE="${BINARY_NAME}-${TARGET}.sha256"
# Use releases URL directly instead of API for actual downloads
URL="https://github.com/${REPO}/releases/download/${VERSION}/${FILENAME}"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${VERSION}/${CHECKSUM_FILE}"
}
# Download file with fallback
download_file() {
local url
local output
url=$1
output=$2
log_info "Downloading from: $url"
# Try curl first (show errors)
if ! curl -fsSL "$url" -o "$output"; then
# Try with wget as fallback
if command -v wget &> /dev/null; then
log_info "curl failed, trying wget..."
if ! wget -q "$url" -O "$output"; then
log_error "Failed to download from $url"
rm -f "$output"
return 1
fi
else
log_error "Failed to download from $url (wget not available as fallback)"
return 1
fi
fi
return 0
}
# Verify checksum
verify_checksum() {
local file
file=$1
log_info "Verifying checksum..."
# Download checksum file
if ! download_file "$CHECKSUM_URL" "$TMP_DIR/$CHECKSUM_FILE"; then
log_warning "Could not download checksum file, skipping verification"
return 0
fi
# Strip directory prefixes from checksum file (for compatibility with old releases)
sed -i.bak 's|.*/||' "$TMP_DIR/$CHECKSUM_FILE" 2>/dev/null || \
sed -i '' 's|.*/||' "$TMP_DIR/$CHECKSUM_FILE" 2>/dev/null
# Verify
if command -v sha256sum &> /dev/null; then
cd "$TMP_DIR"
if ! sha256sum -c "$CHECKSUM_FILE" > /dev/null 2>&1; then
log_error "Checksum verification failed"
return 1
fi
elif command -v shasum &> /dev/null; then
cd "$TMP_DIR"
if ! shasum -a 256 -c "$CHECKSUM_FILE" > /dev/null 2>&1; then
log_error "Checksum verification failed"
return 1
fi
else
log_warning "sha256sum/shasum not found, skipping checksum verification"
fi
log_success "Checksum verified"
return 0
}
# Extract archive
extract_archive() {
local file
local dest
file=$1
dest=$2
log_info "Extracting archive..."
case "$TARGET" in
*-windows-*)
if command -v unzip &> /dev/null; then
unzip -q "$file" -d "$dest"
else
log_error "unzip command not found"
return 1
fi
;;
*)
if ! tar -xzf "$file" -C "$dest"; then
log_error "Failed to extract archive"
return 1
fi
;;
esac
log_success "Archive extracted"
}
# Find install directory
find_install_dir() {
# Try ~/.local/bin first (user-wide, no sudo needed)
if [ -d "$HOME/.local/bin" ]; then
INSTALL_DIR="$HOME/.local/bin"
SUDO=""
return 0
fi
# Try /usr/local/bin (system-wide, may need sudo)
if [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
SUDO=""
return 0
fi
# If /usr/local/bin not writable, try with sudo
if command -v sudo &> /dev/null; then
INSTALL_DIR="/usr/local/bin"
SUDO="sudo"
return 0
fi
# Fallback to home directory
INSTALL_DIR="$HOME/bin"
SUDO=""
if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
fi
}
# Install binary
install_binary() {
local binary_path
binary_path=$1
log_info "Installing to $INSTALL_DIR..."
if [ ! -f "$binary_path" ]; then
log_error "Binary not found at $binary_path"
return 1
fi
# Make executable
chmod +x "$binary_path"
# Copy to install directory
if [ -n "$SUDO" ]; then
if ! $SUDO cp "$binary_path" "$INSTALL_DIR/$BINARY_NAME"; then
log_error "Failed to install binary"
return 1
fi
else
if ! cp "$binary_path" "$INSTALL_DIR/$BINARY_NAME"; then
log_error "Failed to install binary"
return 1
fi
fi
log_success "Binary installed to $INSTALL_DIR/$BINARY_NAME"
}
# Verify installation
verify_installation() {
log_info "Verifying installation..."
if ! command -v "$BINARY_NAME" &> /dev/null; then
log_warning "$BINARY_NAME not in PATH. You may need to add $INSTALL_DIR to your PATH."
# Check if it exists at least
if [ ! -f "$INSTALL_DIR/$BINARY_NAME" ]; then
log_error "Installation failed"
return 1
fi
# Try executing directly
if ! "$INSTALL_DIR/$BINARY_NAME" --version &> /dev/null; then
log_error "Binary exists but failed to execute"
return 1
fi
else
# Get version
VERSION_OUTPUT=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")
log_success "Installation successful!"
log_info "Version: $VERSION_OUTPUT"
fi
}
# Update PATH if needed
suggest_path_update() {
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
log_warning "Add $INSTALL_DIR to your PATH to run 'runbeam' from anywhere"
case "${SHELL##*/}" in
zsh)
log_info "Add to ~/.zshrc: export PATH=\"$INSTALL_DIR:\$PATH\""
;;
bash)
log_info "Add to ~/.bashrc: export PATH=\"$INSTALL_DIR:\$PATH\""
;;
*)
log_info "Add to your shell config: export PATH=\"$INSTALL_DIR:\$PATH\""
;;
esac
fi
}
# Cleanup
cleanup() {
if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then
rm -rf "$TMP_DIR"
fi
}
# Main installation flow
main() {
log_info "Installing $BINARY_NAME from $REPO..."
# Create temp directory
TMP_DIR=""
TMP_DIR=$(mktemp -d)
trap cleanup EXIT
# Detect platform
detect_platform
# Get latest release
get_latest_release
# Construct URLs
get_download_url
# Download archive
if ! download_file "$URL" "$TMP_DIR/$FILENAME"; then
log_error "Installation failed"
exit 1
fi
log_success "Download complete"
# Verify checksum
if ! verify_checksum "$TMP_DIR/$FILENAME" "$TMP_DIR/$CHECKSUM_FILE"; then
log_error "Checksum verification failed. Installation aborted."
exit 1
fi
# Extract archive
if ! extract_archive "$TMP_DIR/$FILENAME" "$TMP_DIR"; then
log_error "Installation failed"
exit 1
fi
# Find binary in extracted files
EXTRACTED_BINARY=$(find "$TMP_DIR" -name "$BINARY_NAME" -o -name "$BINARY_NAME.exe" 2>/dev/null | head -1)
if [ -z "$EXTRACTED_BINARY" ]; then
log_error "Could not find binary in extracted archive"
exit 1
fi
# Find install directory
find_install_dir
# Install binary
if ! install_binary "$EXTRACTED_BINARY"; then
log_error "Installation failed"
exit 1
fi
# Verify installation
verify_installation
# Suggest PATH update if needed
suggest_path_update
log_success "Installation complete!"
log_info "Run '$BINARY_NAME --help' to get started"
}
# Run main function
main "$@"