forked from dagger/container-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
316 lines (259 loc) · 9.14 KB
/
install.sh
File metadata and controls
316 lines (259 loc) · 9.14 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
#!/usr/bin/env bash
# container-use installer script
# Downloads and installs the appropriate cu binary for your system
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
REPO="dagger/container-use"
BINARY_NAME="cu"
INSTALL_DIR=""
# Helper functions
log_info() {
printf "${BLUE}ℹ️ %s${NC}\n" "$1"
}
log_success() {
printf "${GREEN}✅ %s${NC}\n" "$1"
}
log_warning() {
printf "${YELLOW}⚠️ %s${NC}\n" "$1"
}
log_error() {
printf "${RED}❌ %s${NC}\n" "$1"
}
# Check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check dependencies
check_dependencies() {
log_info "Checking dependencies..."
if ! command_exists docker; then
log_error "Docker is required but not installed."
log_info "Please install Docker from: https://docs.docker.com/get-started/get-docker/"
exit 1
fi
if ! command_exists git; then
log_error "Git is required but not installed."
log_info "Please install Git from: https://git-scm.com/downloads"
exit 1
fi
}
# Detect operating system
detect_os() {
local os
case "$(uname -s)" in
Linux*) os="linux";;
Darwin*) os="darwin";;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
log_error "Windows is not supported"
log_info "container-use uses Unix syscalls and requires Linux or macOS"
exit 1;;
*)
log_error "Unsupported operating system: $(uname -s)"
exit 1;;
esac
echo "$os"
}
# Detect architecture
detect_arch() {
local arch
case "$(uname -m)" in
x86_64|amd64) arch="amd64";;
arm64|aarch64) arch="arm64";;
*)
log_error "Unsupported architecture: $(uname -m)"
exit 1;;
esac
echo "$arch"
}
# Check for existing cu command and warn about conflicts
check_existing_cu() {
local found_binary=$(command -v "$BINARY_NAME" 2>/dev/null || echo "")
if [ -n "$found_binary" ]; then
# Only warn about system paths (user paths could be previous container-use installations)
case "$found_binary" in
/usr/bin/* | /bin/* | /usr/local/bin/*)
log_warning "Existing 'cu' command found at $found_binary"
log_warning "This appears to be a system 'cu' command (likely Taylor UUCP)"
log_warning "After installation, you may need to run 'hash -r' to clear command cache"
log_info "Or use the full path: \$HOME/.local/bin/cu"
;;
esac
log_info "Installation will continue..."
echo ""
fi
}
# Find the best installation directory
find_install_dir() {
local install_dir="${BIN_DIR:-$HOME/.local/bin}"
# Create the directory if it doesn't exist
mkdir -p "$install_dir"
# Check if it's writable
if [ ! -w "$install_dir" ]; then
log_error "$install_dir is not a writable directory"
exit 1
fi
echo "$install_dir"
}
# Get the latest release version
get_latest_version() {
curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}
# Verify checksum of downloaded file
verify_checksum() {
local archive_file="$1"
local archive_name="$2"
local version="$3"
log_info "Verifying checksum..."
# Download checksums file
local checksums_url="https://github.com/$REPO/releases/download/$version/checksums.txt"
local checksums_file="$(dirname "$archive_file")/checksums.txt"
curl -s -L -o "$checksums_file" "$checksums_url"
if [ ! -f "$checksums_file" ]; then
log_error "Failed to download checksums file"
return 1
fi
# Extract expected checksum for our file
local expected_checksum=$(grep "$(basename "$archive_file")" "$checksums_file" | cut -d' ' -f1)
if [ -z "$expected_checksum" ]; then
log_error "Checksum not found for $(basename "$archive_file")"
return 1
fi
# Calculate actual checksum
local actual_checksum
if command_exists sha256sum; then
actual_checksum=$(sha256sum "$archive_file" | cut -d' ' -f1)
elif command_exists shasum; then
actual_checksum=$(shasum -a 256 "$archive_file" | cut -d' ' -f1)
else
log_warning "No SHA256 tool found, skipping checksum verification"
return 0
fi
# Compare checksums
if [ "$actual_checksum" = "$expected_checksum" ]; then
log_success "Checksum verified"
return 0
else
log_error "Checksum verification failed!"
log_error "Expected: $expected_checksum"
log_error "Actual: $actual_checksum"
return 1
fi
}
# Download and extract binary
download_and_install() {
local os="$1"
local arch="$2"
local version="$3"
local install_dir="$4"
local archive_name="container-use_${version}_${os}_${arch}"
local extension="tar.gz"
local download_url="https://github.com/$REPO/releases/download/$version/${archive_name}.${extension}"
local temp_dir=$(mktemp -d)
local archive_file="$temp_dir/${archive_name}.${extension}"
log_info "Downloading $BINARY_NAME $version for $os/$arch..."
curl -L -o "$archive_file" "$download_url"
if [ ! -f "$archive_file" ]; then
log_error "Failed to download $download_url"
exit 1
fi
# Verify checksum
if ! verify_checksum "$archive_file" "$archive_name" "$version"; then
log_error "Checksum verification failed, aborting installation"
exit 1
fi
log_info "Extracting archive..."
tar -xzf "$archive_file" -C "$temp_dir"
local binary_path="$temp_dir/$BINARY_NAME"
if [ ! -f "$binary_path" ]; then
log_error "Binary not found in archive"
exit 1
fi
log_info "Installing to $install_dir..."
mkdir -p "$install_dir"
cp "$binary_path" "$install_dir/"
chmod +x "$install_dir/$BINARY_NAME"
# Clean up
rm -rf "$temp_dir"
log_success "$BINARY_NAME installed successfully!"
}
# Main installation process
main() {
# Handle command line arguments
case "${1:-}" in
-h|--help)
echo "container-use installer"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo ""
echo "This script will:"
echo " 1. Check for Docker installation"
echo " 2. Detect your OS and architecture"
echo " 3. Download the latest container-use binary"
echo " 4. Install it to your PATH"
exit 0
;;
esac
log_info "Starting container-use installation..."
check_dependencies
local os=$(detect_os)
local arch=$(detect_arch)
log_info "Detected platform: $os/$arch"
local version=$(get_latest_version)
if [ -z "$version" ]; then
log_error "Failed to get latest release version"
exit 1
fi
log_info "Latest version: $version"
INSTALL_DIR=$(find_install_dir)
log_info "Installation directory: $INSTALL_DIR"
check_existing_cu
download_and_install "$os" "$arch" "$version" "$INSTALL_DIR"
# Check if install directory is in PATH
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
log_warning "Installation directory $INSTALL_DIR is not in your PATH"
log_info "Add this to your shell profile (.bashrc, .zshrc, etc.):"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
log_info "Then restart your terminal or run: source ~/.bashrc (or your shell's config file)"
fi
# Verify installation
if [ -x "$INSTALL_DIR/$BINARY_NAME" ]; then
log_success "Installation complete!"
# Check if the correct cu command is being found in PATH
local found_binary=$(command -v "$BINARY_NAME" 2>/dev/null || echo "")
if [ "$found_binary" = "$INSTALL_DIR/$BINARY_NAME" ]; then
log_success "$BINARY_NAME is ready to use!"
elif [ -n "$found_binary" ]; then
# Some other cu command is being found
local help_output=$("$found_binary" --help 2>&1 || true)
if echo "$help_output" | grep -q "Taylor UUCP"; then
log_error "Detected Taylor UUCP 'cu' command instead of container-use"
log_info "The system 'cu' command at $found_binary is taking precedence"
log_info "Try running: $INSTALL_DIR/$BINARY_NAME --help"
log_info "Or run 'hash -r' and try again"
log_info "Or add $INSTALL_DIR to the beginning of your PATH"
exit 1
else
log_warning "Different 'cu' command found at $found_binary"
log_info "Try running: $INSTALL_DIR/$BINARY_NAME --help"
log_info "Or run 'hash -r' and try again"
log_info "Or add $INSTALL_DIR to the beginning of your PATH"
fi
else
log_warning "You may need to restart your terminal or update your PATH"
fi
log_info "Run '$BINARY_NAME --help' to get started"
else
log_error "Installation verification failed"
exit 1
fi
}
main "$@"