-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·490 lines (426 loc) · 13.7 KB
/
install.sh
File metadata and controls
executable file
·490 lines (426 loc) · 13.7 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
#!/bin/bash
##
# KolosalCode Universal Installer
# Automatically detects OS and installs the appropriate package
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/KolosalAI/kolosal-cli/main/install.sh | bash
# or
# wget -qO- https://raw.githubusercontent.com/KolosalAI/kolosal-cli/main/install.sh | bash
##
set -e
# Version to install
VERSION="${VERSION:-0.1.3}"
PACKAGE_VERSION="0.1.3"
# GitHub release URLs
GITHUB_REPO="KolosalAI/kolosal-cli"
MACOS_PKG_URL="https://github.com/KolosalAI/kolosal-cli/releases/download/v0.1.2/KolosalCode-macos-signed.pkg"
LINUX_DEB_URL="https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/kolosal-code_${PACKAGE_VERSION}_amd64.deb"
LINUX_RPM_URL="https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/kolosal-code-${PACKAGE_VERSION}.x86_64.rpm"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Print functions
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_header() {
echo ""
echo -e "${BOLD}$1${NC}"
echo "================================"
}
# Detect OS
detect_os() {
local os_name=""
local os_arch=""
# Detect OS type
case "$(uname -s)" in
Darwin*)
os_name="macos"
;;
Linux*)
os_name="linux"
;;
*)
print_error "Unsupported operating system: $(uname -s)"
print_info "KolosalCode currently supports macOS and Linux"
exit 1
;;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64)
os_arch="amd64"
;;
arm64|aarch64)
os_arch="arm64"
;;
*)
print_warning "Unsupported architecture: $(uname -m)"
print_info "Attempting to install anyway..."
os_arch="amd64"
;;
esac
echo "${os_name}:${os_arch}"
}
# Check if running as root (for Linux)
check_root() {
if [ "$EUID" -ne 0 ] && [ "$1" = "linux" ]; then
print_error "This script must be run with sudo on Linux"
echo ""
echo "Please run:"
echo " curl -fsSL https://raw.githubusercontent.com/${GITHUB_REPO}/main/install.sh | sudo bash"
echo ""
echo "Or download and run manually:"
echo " wget https://raw.githubusercontent.com/${GITHUB_REPO}/main/install.sh"
echo " sudo bash install.sh"
exit 1
fi
}
# Download file
download_file() {
local url="$1"
local output="$2"
print_info "Downloading from: $url"
# Try curl first, then wget
if command -v curl &> /dev/null; then
curl -fsSL -o "$output" "$url" || {
print_error "Download failed"
return 1
}
elif command -v wget &> /dev/null; then
wget -q -O "$output" "$url" || {
print_error "Download failed"
return 1
}
else
print_error "Neither curl nor wget is available"
print_info "Please install curl or wget and try again"
return 1
fi
print_success "Download complete"
}
# Install on macOS
install_macos() {
print_header "Installing KolosalCode on macOS"
local tmp_dir=$(mktemp -d)
local pkg_file="${tmp_dir}/KolosalCode.pkg"
# Download the package
if ! download_file "$MACOS_PKG_URL" "$pkg_file"; then
print_error "Failed to download macOS package"
rm -rf "$tmp_dir"
exit 1
fi
# Verify the download
if [ ! -f "$pkg_file" ]; then
print_error "Package file not found after download"
rm -rf "$tmp_dir"
exit 1
fi
print_info "Package size: $(du -h "$pkg_file" | cut -f1)"
# Check signature
print_info "Verifying package signature..."
if pkgutil --check-signature "$pkg_file" &> /dev/null; then
print_success "Package signature verified"
else
print_warning "Package signature could not be verified"
print_info "This might happen if the package is not notarized"
read -p "Continue with installation? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Installation cancelled"
rm -rf "$tmp_dir"
exit 0
fi
fi
# Install the package
print_info "Installing KolosalCode..."
print_info "You may be prompted for your password"
if sudo installer -pkg "$pkg_file" -target /; then
print_success "Installation complete!"
else
print_error "Installation failed"
rm -rf "$tmp_dir"
exit 1
fi
# Clean up
rm -rf "$tmp_dir"
# Verify installation
if command -v kolosal &> /dev/null; then
print_success "KolosalCode is now installed"
echo ""
print_info "Installed version: $(kolosal --version 2>&1 | head -1)"
print_info "Installed location: $(which kolosal)"
else
print_warning "Installation completed but 'kolosal' command not found in PATH"
print_info "You may need to add /usr/local/bin to your PATH"
print_info "Or restart your terminal"
fi
}
# Install .deb package (Debian/Ubuntu-based systems)
install_deb() {
local tmp_dir=$(mktemp -d)
local deb_file="${tmp_dir}/kolosal-code.deb"
# Download the package
if ! download_file "$LINUX_DEB_URL" "$deb_file"; then
print_error "Failed to download .deb package"
rm -rf "$tmp_dir"
exit 1
fi
# Verify the download
if [ ! -f "$deb_file" ]; then
print_error "Package file not found after download"
rm -rf "$tmp_dir"
exit 1
fi
print_info "Package size: $(du -h "$deb_file" | cut -f1)"
# Install the package
print_info "Installing KolosalCode..."
if dpkg -i "$deb_file" 2>&1 | tee /tmp/kolosal-install.log; then
print_success "Installation complete!"
else
print_warning "Installation had some warnings"
# Try to fix dependencies
print_info "Attempting to fix dependencies..."
if apt-get install -f -y; then
print_success "Dependencies fixed"
else
print_error "Could not fix dependencies automatically"
print_info "Please run: sudo apt-get install -f"
fi
fi
# Clean up
rm -rf "$tmp_dir"
}
# Install .rpm package (Red Hat/Fedora/CentOS-based systems)
install_rpm() {
local tmp_dir=$(mktemp -d)
local rpm_file="${tmp_dir}/kolosal-code.rpm"
# Download the package
if ! download_file "$LINUX_RPM_URL" "$rpm_file"; then
print_error "Failed to download .rpm package"
rm -rf "$tmp_dir"
exit 1
fi
# Verify the download
if [ ! -f "$rpm_file" ]; then
print_error "Package file not found after download"
rm -rf "$tmp_dir"
exit 1
fi
print_info "Package size: $(du -h "$rpm_file" | cut -f1)"
# Install the package
print_info "Installing KolosalCode..."
# Detect package manager
if command -v dnf &> /dev/null; then
# Fedora/RHEL 8+
if dnf install -y "$rpm_file" 2>&1 | tee /tmp/kolosal-install.log; then
print_success "Installation complete!"
else
print_error "Installation failed"
rm -rf "$tmp_dir"
exit 1
fi
elif command -v yum &> /dev/null; then
# CentOS/RHEL 7
if yum install -y "$rpm_file" 2>&1 | tee /tmp/kolosal-install.log; then
print_success "Installation complete!"
else
print_error "Installation failed"
rm -rf "$tmp_dir"
exit 1
fi
elif command -v zypper &> /dev/null; then
# OpenSUSE
if zypper install -y "$rpm_file" 2>&1 | tee /tmp/kolosal-install.log; then
print_success "Installation complete!"
else
print_error "Installation failed"
rm -rf "$tmp_dir"
exit 1
fi
else
# Fallback to rpm command
if rpm -ivh "$rpm_file" 2>&1 | tee /tmp/kolosal-install.log; then
print_success "Installation complete!"
else
print_error "Installation failed"
rm -rf "$tmp_dir"
exit 1
fi
fi
# Clean up
rm -rf "$tmp_dir"
}
# Install on Linux
install_linux() {
print_header "Installing KolosalCode on Linux"
# Detect Linux distribution
local distro=""
local distro_like=""
if [ -f /etc/os-release ]; then
. /etc/os-release
distro="$ID"
distro_like="$ID_LIKE"
elif [ -f /etc/debian_version ]; then
distro="debian"
distro_like="debian"
elif [ -f /etc/redhat-release ]; then
distro="rhel"
distro_like="rhel fedora"
else
print_warning "Could not detect Linux distribution"
distro="unknown"
fi
print_info "Detected distribution: $distro"
# Determine package format based on distribution
local use_rpm=false
# Check for RPM-based distributions
if [[ "$distro" == "rhel" || "$distro" == "centos" || "$distro" == "fedora" ||
"$distro" == "rocky" || "$distro" == "alma" || "$distro" == "almalinux" ||
"$distro" == "opensuse" || "$distro" == "opensuse-leap" || "$distro" == "opensuse-tumbleweed" ||
"$distro" == "sles" || "$distro" == "amzn" || "$distro" == "ol" ]]; then
use_rpm=true
elif [[ "$distro_like" == *"rhel"* || "$distro_like" == *"fedora"* || "$distro_like" == *"suse"* ]]; then
use_rpm=true
fi
# Check for DEB-based distributions
local use_deb=false
if [[ "$distro" == "debian" || "$distro" == "ubuntu" || "$distro" == "linuxmint" ||
"$distro" == "pop" || "$distro" == "elementary" || "$distro" == "kali" ||
"$distro" == "raspbian" || "$distro" == "zorin" ]]; then
use_deb=true
elif [[ "$distro_like" == *"debian"* || "$distro_like" == *"ubuntu"* ]]; then
use_deb=true
fi
# Install based on package format
if [ "$use_deb" = true ]; then
print_info "Using .deb package format"
install_deb
elif [ "$use_rpm" = true ]; then
print_info "Using .rpm package format"
install_rpm
else
print_error "Could not determine package format for distribution: $distro"
print_info "Supported formats:"
print_info " - .deb for Debian/Ubuntu-based systems"
print_info " - .rpm for Red Hat/Fedora/CentOS-based systems"
print_info ""
print_info "Download packages manually from:"
print_info " .deb: $LINUX_DEB_URL"
print_info " .rpm: $LINUX_RPM_URL"
exit 1
fi
# Verify installation
if command -v kolosal &> /dev/null; then
print_success "KolosalCode is now installed"
echo ""
print_info "Installed version: $(kolosal --version 2>&1 | head -1)"
print_info "Installed location: $(which kolosal)"
else
print_warning "Installation completed but 'kolosal' command not found in PATH"
print_info "Try running: hash -r"
print_info "Or restart your terminal"
fi
}
# Show usage instructions
show_usage() {
echo ""
print_header "Quick Start"
echo ""
echo "Try running:"
echo -e " ${BOLD}kolosal --help${NC}"
echo ""
echo "To check the version:"
echo -e " ${BOLD}kolosal --version${NC}"
echo ""
echo "For more information, visit:"
echo " https://github.com/${GITHUB_REPO}"
echo ""
}
# Uninstall function (for reference)
show_uninstall_info() {
echo ""
print_header "Uninstallation"
echo ""
if [ "$(uname -s)" = "Darwin" ]; then
echo "To uninstall on macOS:"
echo " sudo rm -rf /usr/local/kolosal-app"
echo " sudo rm /usr/local/bin/kolosal"
else
echo "To uninstall on Linux:"
echo " # For Debian/Ubuntu (.deb):"
echo " sudo apt remove kolosal-code"
echo " # or"
echo " sudo dpkg -r kolosal-code"
echo ""
echo " # For Red Hat/Fedora/CentOS (.rpm):"
echo " sudo dnf remove kolosal-code"
echo " # or"
echo " sudo yum remove kolosal-code"
echo " # or"
echo " sudo rpm -e kolosal-code"
fi
echo ""
}
# Main installation flow
main() {
print_header "KolosalCode Installer v${VERSION}"
echo ""
# Detect OS and architecture
print_info "Detecting operating system..."
local os_info=$(detect_os)
local os_name=$(echo "$os_info" | cut -d: -f1)
local os_arch=$(echo "$os_info" | cut -d: -f2)
print_success "Detected: $os_name ($os_arch)"
echo ""
# Check if already installed
if command -v kolosal &> /dev/null; then
local current_version=$(kolosal --version 2>&1 | head -1)
print_warning "KolosalCode is already installed"
print_info "Current version: $current_version"
echo ""
read -p "Do you want to reinstall/upgrade? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Installation cancelled"
exit 0
fi
fi
# Install based on OS
case "$os_name" in
macos)
install_macos
;;
linux)
check_root "$os_name"
install_linux
;;
*)
print_error "Unsupported OS: $os_name"
exit 1
;;
esac
# Show usage instructions
show_usage
# Show uninstall info
if [ "${SHOW_UNINSTALL_INFO:-0}" = "1" ]; then
show_uninstall_info
fi
print_success "Installation completed successfully!"
}
# Run main function
main "$@"