-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
382 lines (313 loc) · 10.1 KB
/
install.sh
File metadata and controls
382 lines (313 loc) · 10.1 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
#!/bin/bash
set -e
# Bashlet installer script
# Usage: curl -fsSL https://raw.githubusercontent.com/ServiceWeave/bashlet/main/install.sh | bash
REPO="ServiceWeave/bashlet"
INSTALL_DIR="${BASHLET_INSTALL_DIR:-$HOME/.local/bin}"
GITHUB_API="https://api.github.com"
# Firecracker version to install
FIRECRACKER_VERSION="v1.10.1"
# Wasmer version to install
WASMER_VERSION="v5.0.4"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}[INFO]${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
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux)
os="linux"
;;
darwin)
os="darwin"
;;
mingw*|msys*|cygwin*)
os="windows"
;;
*)
error "Unsupported operating system: $os"
;;
esac
case "$arch" in
x86_64|amd64)
arch="x86_64"
;;
aarch64|arm64)
arch="aarch64"
;;
*)
error "Unsupported architecture: $arch"
;;
esac
echo "${os}-${arch}"
}
# Get the latest release version
get_latest_version() {
local version
version=$(curl -sL "${GITHUB_API}/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$version" ]; then
error "Failed to get latest version. Check your internet connection."
fi
echo "$version"
}
# Download and install bashlet
install_bashlet() {
local platform version binary_name download_url temp_dir
platform=$(detect_platform)
version="${1:-$(get_latest_version)}"
info "Installing bashlet $version for $platform..."
# Construct binary name
case "$platform" in
windows-*)
binary_name="bashlet-${platform}.exe"
;;
*)
binary_name="bashlet-${platform}"
;;
esac
download_url="https://github.com/${REPO}/releases/download/${version}/${binary_name}"
# Create install directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Create temporary directory
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
info "Downloading from $download_url..."
if ! curl -fsSL "$download_url" -o "$temp_dir/bashlet"; then
error "Failed to download bashlet. The release might not exist for your platform."
fi
# Make executable
chmod +x "$temp_dir/bashlet"
# Move to install directory
mv "$temp_dir/bashlet" "$INSTALL_DIR/bashlet"
info "Installed bashlet to $INSTALL_DIR/bashlet"
# Check if install directory is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
warn "$INSTALL_DIR is not in your PATH."
echo ""
echo "Add this to your shell profile (.bashrc, .zshrc, etc.):"
echo ""
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo ""
fi
# Verify installation
if command -v bashlet &> /dev/null || [ -x "$INSTALL_DIR/bashlet" ]; then
info "Installation complete!"
echo ""
"$INSTALL_DIR/bashlet" --version
echo ""
echo "Get started:"
echo " bashlet --help"
echo " bashlet exec --mount ./src:/workspace \"ls -la\""
else
warn "bashlet was installed but may not be in your PATH yet."
fi
}
# Install Firecracker on Linux
install_firecracker() {
local platform arch download_url temp_dir
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
# Only install on Linux
if [ "$platform" != "linux" ]; then
info "Firecracker is only available on Linux. Skipping Firecracker installation."
return 0
fi
# Check if Firecracker is already installed
if command -v firecracker &> /dev/null; then
local current_version
current_version=$(firecracker --version 2>/dev/null | head -n1 | awk '{print $2}')
info "Firecracker is already installed (version: $current_version)"
return 0
fi
# Check if already installed in our install dir
if [ -x "$INSTALL_DIR/firecracker" ]; then
info "Firecracker is already installed at $INSTALL_DIR/firecracker"
return 0
fi
arch=$(uname -m)
case "$arch" in
x86_64|amd64)
arch="x86_64"
;;
aarch64|arm64)
arch="aarch64"
;;
*)
warn "Firecracker is not available for architecture: $arch"
return 0
;;
esac
info "Installing Firecracker ${FIRECRACKER_VERSION} for ${arch}..."
download_url="https://github.com/firecracker-microvm/firecracker/releases/download/${FIRECRACKER_VERSION}/firecracker-${FIRECRACKER_VERSION}-${arch}"
# Create temporary directory
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
info "Downloading from $download_url..."
if ! curl -fsSL "$download_url" -o "$temp_dir/firecracker"; then
warn "Failed to download Firecracker. It will be downloaded automatically at runtime if needed."
return 0
fi
# Make executable
chmod +x "$temp_dir/firecracker"
# Move to install directory
mv "$temp_dir/firecracker" "$INSTALL_DIR/firecracker"
info "Installed Firecracker to $INSTALL_DIR/firecracker"
# Check KVM availability
if [ -e "/dev/kvm" ]; then
info "KVM is available. Firecracker backend is ready to use."
else
warn "KVM is not available (/dev/kvm not found)."
echo ""
echo "To use the Firecracker backend, ensure:"
echo " 1. You're running on a system with hardware virtualization support"
echo " 2. KVM kernel module is loaded: sudo modprobe kvm"
echo " 3. You have access to /dev/kvm: sudo usermod -aG kvm \$USER"
echo ""
fi
}
# Install Wasmer
install_wasmer() {
local os arch download_url temp_dir archive_name
# Check if Wasmer is already installed in our install dir
if [ -x "$INSTALL_DIR/wasmer" ]; then
local current_version
current_version=$("$INSTALL_DIR/wasmer" --version 2>/dev/null | awk '{print $2}')
info "Wasmer is already installed at $INSTALL_DIR/wasmer (version: $current_version)"
return 0
fi
# Check if Wasmer is already in PATH
if command -v wasmer &> /dev/null; then
local current_version
current_version=$(wasmer --version 2>/dev/null | awk '{print $2}')
info "Wasmer is already installed (version: $current_version)"
return 0
fi
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
# Map OS names
case "$os" in
linux)
os="linux"
;;
darwin)
os="darwin"
;;
mingw*|msys*|cygwin*)
os="windows"
;;
*)
warn "Wasmer installation not supported for OS: $os"
echo "Install manually: curl https://get.wasmer.io -sSfL | sh"
return 0
;;
esac
# Map architecture names
case "$arch" in
x86_64|amd64)
arch="amd64"
;;
aarch64|arm64)
arch="arm64"
;;
*)
warn "Wasmer is not available for architecture: $arch"
return 0
;;
esac
info "Installing Wasmer ${WASMER_VERSION} for ${os}-${arch}..."
# Construct download URL
# Wasmer releases: wasmer-linux-amd64.tar.gz, wasmer-darwin-arm64.tar.gz, etc.
archive_name="wasmer-${os}-${arch}.tar.gz"
download_url="https://github.com/wasmerio/wasmer/releases/download/${WASMER_VERSION}/${archive_name}"
# Create temporary directory
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
info "Downloading from $download_url..."
if ! curl -fsSL "$download_url" -o "$temp_dir/$archive_name"; then
warn "Failed to download Wasmer."
echo "Install manually: curl https://get.wasmer.io -sSfL | sh"
return 0
fi
# Extract the archive
info "Extracting Wasmer..."
if ! tar -xzf "$temp_dir/$archive_name" -C "$temp_dir"; then
warn "Failed to extract Wasmer archive."
return 0
fi
# The archive contains a 'bin' directory with wasmer binary
if [ -f "$temp_dir/bin/wasmer" ]; then
chmod +x "$temp_dir/bin/wasmer"
mv "$temp_dir/bin/wasmer" "$INSTALL_DIR/wasmer"
info "Installed Wasmer to $INSTALL_DIR/wasmer"
elif [ -f "$temp_dir/wasmer" ]; then
chmod +x "$temp_dir/wasmer"
mv "$temp_dir/wasmer" "$INSTALL_DIR/wasmer"
info "Installed Wasmer to $INSTALL_DIR/wasmer"
else
warn "Could not find wasmer binary in archive."
echo "Install manually: curl https://get.wasmer.io -sSfL | sh"
return 0
fi
# Verify installation
if [ -x "$INSTALL_DIR/wasmer" ]; then
local installed_version
installed_version=$("$INSTALL_DIR/wasmer" --version 2>/dev/null | awk '{print $2}')
info "Wasmer $installed_version installed successfully."
fi
}
# Show help
show_help() {
cat << EOF
Bashlet Installer
Usage:
curl -fsSL https://raw.githubusercontent.com/ServiceWeave/bashlet/main/install.sh | bash
# Or with a specific version:
curl -fsSL https://raw.githubusercontent.com/ServiceWeave/bashlet/main/install.sh | bash -s -- v0.1.0
Options:
-h, --help Show this help message
-v, --version Install a specific version (e.g., v0.1.0)
Environment Variables:
BASHLET_INSTALL_DIR Installation directory (default: ~/.local/bin)
EOF
}
# Parse arguments
main() {
local version=""
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-v|--version)
version="$2"
shift 2
;;
v*)
version="$1"
shift
;;
*)
error "Unknown option: $1"
;;
esac
done
install_bashlet "$version"
install_wasmer
install_firecracker
}
main "$@"