-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·655 lines (553 loc) · 17.6 KB
/
install.sh
File metadata and controls
executable file
·655 lines (553 loc) · 17.6 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
#!/bin/sh
# Moltis installer script
# https://www.moltis.org/
#
# Usage:
# curl -fsSL https://www.moltis.org/install.sh | sh
#
# Or with options:
# curl -fsSL https://www.moltis.org/install.sh | sh -s -- --no-homebrew
# curl -fsSL https://www.moltis.org/install.sh | sh -s -- --method=binary
# curl -fsSL https://www.moltis.org/install.sh | sh -s -- --version=0.1.3
set -e
GITHUB_REPO="moltis-org/moltis"
HOMEBREW_TAP="moltis-org/tap"
BINARY_NAME="moltis"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
# Default options
USE_HOMEBREW=true
PREFERRED_METHOD=""
VERSION=""
# Colors (disabled if not a terminal)
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
BLUE=''
BOLD=''
NC=''
fi
info() {
printf "${BLUE}==>${NC} ${BOLD}%s${NC}\n" "$1"
}
success() {
printf "${GREEN}==>${NC} ${BOLD}%s${NC}\n" "$1"
}
warn() {
printf "${YELLOW}Warning:${NC} %s\n" "$1" >&2
}
error() {
printf "${RED}Error:${NC} %s\n" "$1" >&2
exit 1
}
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
--no-homebrew)
USE_HOMEBREW=false
;;
--method=*)
PREFERRED_METHOD="${1#*=}"
;;
--version=*)
VERSION="${1#*=}"
;;
-h|--help)
cat <<EOF
Moltis installer
Usage:
install.sh [OPTIONS]
Options:
--no-homebrew Skip Homebrew even if available (macOS)
--method=METHOD Force installation method: homebrew, binary, deb, rpm, arch, appimage, snap, source
--version=VERSION Install a specific version (default: latest)
-h, --help Show this help message
Environment variables:
INSTALL_DIR Binary installation directory (default: ~/.local/bin)
Examples:
curl -fsSL https://www.moltis.org/install.sh | sh
curl -fsSL https://www.moltis.org/install.sh | sh -s -- --method=binary
curl -fsSL https://www.moltis.org/install.sh | sh -s -- --version=0.1.3
EOF
exit 0
;;
*)
warn "Unknown option: $1"
;;
esac
shift
done
detect_os() {
OS="$(uname -s)"
case "$OS" in
Darwin)
echo "macos"
;;
Linux)
echo "linux"
;;
MINGW*|MSYS*|CYGWIN*)
echo "windows"
;;
*)
echo "unknown"
;;
esac
}
detect_arch() {
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64)
echo "x86_64"
;;
aarch64|arm64)
echo "aarch64"
;;
armv7l)
echo "armv7"
;;
i386|i686)
echo "i686"
;;
*)
echo "$ARCH"
;;
esac
}
detect_linux_distro() {
if [ -f /etc/os-release ]; then
# shellcheck disable=SC1091
. /etc/os-release
echo "$ID"
elif [ -f /etc/debian_version ]; then
echo "debian"
elif [ -f /etc/redhat-release ]; then
echo "rhel"
elif [ -f /etc/arch-release ]; then
echo "arch"
else
echo "unknown"
fi
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
get_latest_version() {
# Extract tag_name, stripping optional leading "v" prefix.
if command_exists curl; then
curl -fsSL "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"tag_name": *"v?([^"]+)".*/\1/'
elif command_exists wget; then
wget -qO- "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"tag_name": *"v?([^"]+)".*/\1/'
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Return the GitHub release tag for a given version.
# Date-based versions (YYYYMMDD.NN) are bare tags; semver gets a "v" prefix.
release_tag() {
v="$1"
case "$v" in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*)
echo "$v" ;;
*)
echo "v$v" ;;
esac
}
download() {
url="$1"
dest="$2"
if command_exists curl; then
curl -fsSL "$url" -o "$dest"
elif command_exists wget; then
wget -q "$url" -O "$dest"
else
error "Neither curl nor wget found. Please install one of them."
fi
}
verify_checksum() {
file="$1"
expected_sha256="$2"
if command_exists sha256sum; then
actual=$(sha256sum "$file" | cut -d' ' -f1)
elif command_exists shasum; then
actual=$(shasum -a 256 "$file" | cut -d' ' -f1)
else
warn "Cannot verify checksum (sha256sum/shasum not found)"
return 0
fi
if [ "$actual" != "$expected_sha256" ]; then
error "Checksum verification failed!\nExpected: $expected_sha256\nActual: $actual"
fi
}
ensure_install_dir() {
if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
fi
}
install_shared_assets() {
source_dir="$1"
if [ ! -d "$source_dir" ]; then
return 0
fi
share_dir="$HOME/.moltis/share"
mkdir -p "$share_dir"
cp -R "$source_dir"/. "$share_dir"/
info "Installed shared assets to $share_dir"
}
add_to_path_instructions() {
shell_name=$(basename "$SHELL")
case "$shell_name" in
bash)
rc_file="$HOME/.bashrc"
;;
zsh)
rc_file="$HOME/.zshrc"
;;
fish)
rc_file="$HOME/.config/fish/config.fish"
;;
*)
rc_file="$HOME/.profile"
;;
esac
# Check if already in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*)
return
;;
esac
printf "\n"
warn "$INSTALL_DIR is not in your PATH."
printf "Add it by running:\n\n"
if [ "$shell_name" = "fish" ]; then
printf " ${BOLD}fish_add_path %s${NC}\n\n" "$INSTALL_DIR"
else
printf " ${BOLD}echo 'export PATH=\"%s:\$PATH\"' >> %s${NC}\n\n" "$INSTALL_DIR" "$rc_file"
fi
printf "Then restart your shell or run:\n"
printf " ${BOLD}source %s${NC}\n" "$rc_file"
}
# Installation methods
install_homebrew() {
info "Installing via Homebrew..."
if ! command_exists brew; then
error "Homebrew not found. Install it from https://brew.sh/"
fi
brew tap "$HOMEBREW_TAP" 2>/dev/null || true
brew install moltis
success "Moltis installed via Homebrew"
}
install_binary() {
os="$1"
arch="$2"
version="$3"
# Determine target triple
case "$os" in
macos)
target="${arch}-apple-darwin"
;;
linux)
target="${arch}-unknown-linux-gnu"
;;
*)
error "Unsupported OS for binary installation: $os"
;;
esac
tag=$(release_tag "$version")
tarball="${BINARY_NAME}-${version}-${target}.tar.gz"
url="https://github.com/${GITHUB_REPO}/releases/download/${tag}/${tarball}"
checksum_url="${url}.sha256"
info "Downloading ${BINARY_NAME} v${version} for ${target}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
download "$url" "$tmpdir/$tarball" || error "Failed to download $tarball. Check if a release exists for your platform."
# Verify checksum
if download "$checksum_url" "$tmpdir/checksum.sha256" 2>/dev/null; then
expected_sha=$(cut -d' ' -f1 "$tmpdir/checksum.sha256")
verify_checksum "$tmpdir/$tarball" "$expected_sha"
info "Checksum verified"
else
warn "Could not download checksum file, skipping verification"
fi
# Extract and install
tar -xzf "$tmpdir/$tarball" -C "$tmpdir"
ensure_install_dir
mv "$tmpdir/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
if [ -d "$tmpdir/share/moltis" ]; then
install_shared_assets "$tmpdir/share/moltis"
elif [ -d "$tmpdir/share/web" ] && [ -d "$tmpdir/share/wasm" ]; then
install_shared_assets "$tmpdir/share"
fi
success "Moltis installed to $INSTALL_DIR/$BINARY_NAME"
add_to_path_instructions
}
install_deb() {
arch="$1"
version="$2"
case "$arch" in
x86_64) deb_arch="amd64" ;;
aarch64) deb_arch="arm64" ;;
*) error "Unsupported architecture for .deb: $arch" ;;
esac
# Package naming: moltis_VERSION_ARCH.deb (cargo-deb with --deb-version, no revision)
tag=$(release_tag "$version")
deb_file="moltis_${version}_${deb_arch}.deb"
url="https://github.com/${GITHUB_REPO}/releases/download/${tag}/${deb_file}"
info "Downloading ${deb_file}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
download "$url" "$tmpdir/$deb_file" || error "Failed to download $deb_file"
info "Installing .deb package (requires sudo)..."
sudo dpkg -i "$tmpdir/$deb_file" || sudo apt-get install -f -y
success "Moltis installed via .deb package"
}
install_rpm() {
arch="$1"
version="$2"
case "$arch" in
x86_64) rpm_arch="x86_64" ;;
aarch64) rpm_arch="aarch64" ;;
*) error "Unsupported architecture for .rpm: $arch" ;;
esac
# Package naming: moltis-VERSION-1.ARCH.rpm
tag=$(release_tag "$version")
rpm_file="moltis-${version}-1.${rpm_arch}.rpm"
url="https://github.com/${GITHUB_REPO}/releases/download/${tag}/${rpm_file}"
info "Downloading ${rpm_file}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
download "$url" "$tmpdir/$rpm_file" || error "Failed to download $rpm_file"
info "Installing .rpm package (requires sudo)..."
if command_exists dnf; then
sudo dnf install -y "$tmpdir/$rpm_file"
elif command_exists yum; then
sudo yum install -y "$tmpdir/$rpm_file"
else
sudo rpm -i "$tmpdir/$rpm_file"
fi
success "Moltis installed via .rpm package"
}
install_arch() {
arch="$1"
version="$2"
tag=$(release_tag "$version")
pkg_file="moltis-${version}-1-${arch}.pkg.tar.zst"
url="https://github.com/${GITHUB_REPO}/releases/download/${tag}/${pkg_file}"
info "Downloading ${pkg_file}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
download "$url" "$tmpdir/$pkg_file" || error "Failed to download $pkg_file"
info "Installing Arch package (requires sudo)..."
sudo pacman -U --noconfirm "$tmpdir/$pkg_file"
success "Moltis installed via Arch package"
}
install_appimage() {
os="$1"
arch="$2"
version="$3"
if [ "$os" != "linux" ]; then
error "AppImage installation is only supported on Linux"
fi
case "$arch" in
x86_64|aarch64)
;;
*)
error "Unsupported architecture for AppImage: $arch"
;;
esac
tag=$(release_tag "$version")
appimage_file="moltis-${version}-${arch}.AppImage"
url="https://github.com/${GITHUB_REPO}/releases/download/${tag}/${appimage_file}"
checksum_url="${url}.sha256"
info "Downloading ${appimage_file}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
download "$url" "$tmpdir/$appimage_file" || error "Failed to download $appimage_file"
if download "$checksum_url" "$tmpdir/checksum.sha256" 2>/dev/null; then
expected_sha=$(cut -d' ' -f1 "$tmpdir/checksum.sha256")
verify_checksum "$tmpdir/$appimage_file" "$expected_sha"
info "Checksum verified"
else
warn "Could not download checksum file, skipping verification"
fi
ensure_install_dir
mv "$tmpdir/$appimage_file" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
success "Moltis AppImage installed to $INSTALL_DIR/$BINARY_NAME"
add_to_path_instructions
}
install_snap() {
info "Installing via Snap..."
if ! command_exists snap; then
error "Snap not found. Install it first: https://snapcraft.io/docs/installing-snapd"
fi
sudo snap install moltis
success "Moltis installed via Snap"
}
install_from_source() {
warn "Building from source. This may take several minutes..."
if ! command_exists cargo; then
info "Rust not found. Installing via rustup..."
if command_exists curl; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
else
wget -qO- https://sh.rustup.rs | sh -s -- -y
fi
# shellcheck disable=SC1091
. "$HOME/.cargo/env"
fi
if ! command_exists git; then
error "Git is required to build from source. Please install it first."
fi
version="$1"
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
info "Cloning repository..."
tag=$(release_tag "$version")
git clone --depth 1 --branch "$tag" "https://github.com/${GITHUB_REPO}.git" "$tmpdir/moltis"
cd "$tmpdir/moltis"
info "Building WASM tool components..."
rustup target add wasm32-wasip2
cargo build --target wasm32-wasip2 -p moltis-wasm-calc -p moltis-wasm-web-fetch -p moltis-wasm-web-search --release
info "Building release binary..."
cargo build --release
ensure_install_dir
cp "target/release/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
SHARE_STAGING="$tmpdir/moltis-share"
mkdir -p "$SHARE_STAGING/web" "$SHARE_STAGING/wasm"
cp -R "crates/web/src/assets/." "$SHARE_STAGING/web/"
cp "target/wasm32-wasip2/release/moltis_wasm_calc.wasm" "$SHARE_STAGING/wasm/"
cp "target/wasm32-wasip2/release/moltis_wasm_web_fetch.wasm" "$SHARE_STAGING/wasm/"
cp "target/wasm32-wasip2/release/moltis_wasm_web_search.wasm" "$SHARE_STAGING/wasm/"
install_shared_assets "$SHARE_STAGING"
success "Moltis built and installed to $INSTALL_DIR/$BINARY_NAME"
add_to_path_instructions
}
# Main installation logic
main() {
printf "\n"
printf " ${BOLD}Moltis Installer${NC}\n"
printf " Personal AI gateway - one binary, multiple LLM providers\n"
printf "\n"
OS=$(detect_os)
ARCH=$(detect_arch)
info "Detected: $OS ($ARCH)"
if [ "$OS" = "windows" ]; then
error "Windows is not supported by this installer. Please download the binary manually from:\nhttps://github.com/${GITHUB_REPO}/releases"
fi
if [ "$OS" = "unknown" ]; then
error "Unsupported operating system: $(uname -s)"
fi
# Get version
if [ -z "$VERSION" ]; then
info "Fetching latest version..."
VERSION=$(get_latest_version)
if [ -z "$VERSION" ]; then
error "Failed to determine latest version"
fi
fi
info "Version: $VERSION"
# Determine installation method
if [ -n "$PREFERRED_METHOD" ]; then
case "$PREFERRED_METHOD" in
homebrew)
install_homebrew
;;
binary)
install_binary "$OS" "$ARCH" "$VERSION"
;;
deb)
install_deb "$ARCH" "$VERSION"
;;
rpm)
install_rpm "$ARCH" "$VERSION"
;;
arch)
install_arch "$ARCH" "$VERSION"
;;
appimage)
install_appimage "$OS" "$ARCH" "$VERSION"
;;
snap)
install_snap
;;
source)
install_from_source "$VERSION"
;;
*)
error "Unknown installation method: $PREFERRED_METHOD"
;;
esac
elif [ "$OS" = "macos" ]; then
# macOS: prefer Homebrew, fall back to binary
if [ "$USE_HOMEBREW" = true ] && command_exists brew; then
install_homebrew
else
install_binary "$OS" "$ARCH" "$VERSION"
fi
elif [ "$OS" = "linux" ]; then
# Linux: detect distro and use appropriate package manager
DISTRO=$(detect_linux_distro)
case "$DISTRO" in
ubuntu|debian|linuxmint|pop|elementary|zorin)
if command_exists apt-get; then
install_deb "$ARCH" "$VERSION"
else
install_binary "$OS" "$ARCH" "$VERSION"
fi
;;
fedora|rhel|centos|rocky|alma|ol)
if command_exists dnf || command_exists yum; then
install_rpm "$ARCH" "$VERSION"
else
install_binary "$OS" "$ARCH" "$VERSION"
fi
;;
arch|manjaro|endeavouros|garuda)
if command_exists pacman; then
install_arch "$ARCH" "$VERSION"
else
install_binary "$OS" "$ARCH" "$VERSION"
fi
;;
*)
# Unknown distro: try binary, offer source as fallback
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "aarch64" ]; then
install_binary "$OS" "$ARCH" "$VERSION"
else
warn "No pre-built binary available for $ARCH architecture."
info "Falling back to building from source..."
install_from_source "$VERSION"
fi
;;
esac
fi
# Verify installation
if command_exists "$BINARY_NAME"; then
installed_version=$("$BINARY_NAME" --version 2>/dev/null | head -1 || echo "unknown")
printf "\n"
success "Installation complete!"
printf " ${BOLD}%s${NC}\n" "$installed_version"
printf "\n"
printf "Get started:\n"
printf " ${BOLD}moltis${NC} # Start the gateway\n"
printf " ${BOLD}moltis --help${NC} # Show help\n"
printf "\n"
printf "Documentation: ${BLUE}https://www.moltis.org/${NC}\n"
elif [ -x "$INSTALL_DIR/$BINARY_NAME" ]; then
printf "\n"
success "Installation complete!"
printf "\n"
add_to_path_instructions
fi
}
main