-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·214 lines (185 loc) · 5.98 KB
/
install.sh
File metadata and controls
executable file
·214 lines (185 loc) · 5.98 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
#!/usr/bin/env bash
# install.sh — Install lean-ctx (download pre-built binary or build from source)
#
# Usage:
# ./install.sh # build from source (requires Rust)
# ./install.sh --download # download pre-built binary (no Rust needed)
# ./install.sh --build-only # build only, don't install
#
# One-liner (no Rust required):
# curl -fsSL https://leanctx.com/install.sh | sh
set -euo pipefail
REPO="yvgude/lean-ctx"
INSTALL_DIR="${LEAN_CTX_INSTALL_DIR:-$HOME/.local/bin}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-install.sh}")" 2>/dev/null && pwd || pwd)"
RUST_DIR="$SCRIPT_DIR/rust"
echo "lean-ctx installer"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
finish() {
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo ""
echo "Warning: $INSTALL_DIR is not in your PATH."
local shell_name
shell_name="$(basename "${SHELL:-bash}" 2>/dev/null || echo bash)"
local rc="$HOME/.bashrc"
case "$shell_name" in
zsh) rc="$HOME/.zshrc" ;;
fish) rc="$HOME/.config/fish/config.fish" ;;
esac
if [[ "$shell_name" == "fish" ]]; then
echo " fish_add_path $INSTALL_DIR"
else
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> $rc && source $rc"
fi
fi
echo ""
echo "Done! Verify with: lean-ctx --version"
}
detect_target() {
local os arch libc
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$arch" in
x86_64) arch="x86_64" ;;
arm64|aarch64) arch="aarch64" ;;
*)
echo "Error: unsupported architecture '$arch'"
echo "Build from source instead: ./install.sh"
exit 1 ;;
esac
case "$os" in
linux)
libc="musl"
if command -v ldd &>/dev/null; then
local glibc_ver
glibc_ver="$(ldd --version 2>&1 | head -1 | grep -oE '[0-9]+\.[0-9]+$' || true)"
if [[ -n "$glibc_ver" ]]; then
local major minor
major="${glibc_ver%%.*}"
minor="${glibc_ver##*.}"
if [[ "$major" -gt 2 ]] || { [[ "$major" -eq 2 ]] && [[ "$minor" -ge 35 ]]; }; then
libc="gnu"
fi
fi
fi
echo "${arch}-unknown-linux-${libc}"
;;
darwin) echo "${arch}-apple-darwin" ;;
*)
echo "Error: unsupported OS '$os'"
echo "Windows: download from https://github.com/${REPO}/releases/latest"
exit 1 ;;
esac
}
verify_checksum() {
local file="$1" expected="$2"
local actual
if command -v sha256sum &>/dev/null; then
actual="$(sha256sum "$file" | cut -d' ' -f1)"
elif command -v shasum &>/dev/null; then
actual="$(shasum -a 256 "$file" | cut -d' ' -f1)"
else
echo "Warning: no sha256sum/shasum found, skipping checksum verification"
return 0
fi
if [[ "$actual" != "$expected" ]]; then
echo "Error: checksum mismatch!"
echo " Expected: $expected"
echo " Got: $actual"
exit 1
fi
echo " Checksum verified ✓"
}
install_download() {
local target
target="$(detect_target)"
echo "Mode: download pre-built binary"
echo "Platform: $target"
echo ""
echo "Fetching latest release..."
local latest
latest="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | head -1 | cut -d'"' -f4)"
if [[ -z "$latest" ]]; then
echo "Error: could not determine latest release."
exit 1
fi
echo "Latest: $latest"
local asset_url="https://github.com/${REPO}/releases/download/${latest}/lean-ctx-${target}.tar.gz"
local sums_url="https://github.com/${REPO}/releases/download/${latest}/SHA256SUMS"
local tmpdir
tmpdir="$(mktemp -d)"
trap 'rm -rf "${tmpdir:-}"' EXIT
echo "Downloading binary..."
if ! curl -fsSL "$asset_url" -o "$tmpdir/lean-ctx.tar.gz"; then
echo "Error: download failed. Check: https://github.com/${REPO}/releases"
exit 1
fi
echo "Downloading checksums..."
if curl -fsSL "$sums_url" -o "$tmpdir/SHA256SUMS" 2>/dev/null; then
local expected
expected="$(grep "lean-ctx-${target}.tar.gz" "$tmpdir/SHA256SUMS" | cut -d' ' -f1)"
if [[ -n "$expected" ]]; then
verify_checksum "$tmpdir/lean-ctx.tar.gz" "$expected"
fi
else
echo " Warning: checksums not available, skipping verification"
fi
tar -xzf "$tmpdir/lean-ctx.tar.gz" -C "$tmpdir"
mkdir -p "$INSTALL_DIR"
install -m755 "$tmpdir/lean-ctx" "$INSTALL_DIR/lean-ctx"
if [[ "$(uname -s)" == "Darwin" ]]; then
xattr -cr "$INSTALL_DIR/lean-ctx" 2>/dev/null || true
codesign --force --sign - "$INSTALL_DIR/lean-ctx" 2>/dev/null || true
fi
echo " Installed: $INSTALL_DIR/lean-ctx"
finish
}
install_from_source() {
if ! command -v cargo &>/dev/null; then
echo "Error: cargo not found. Install Rust: https://rustup.rs"
echo "Or download a pre-built binary: $0 --download"
exit 1
fi
local build_only="${1:-}"
echo "Mode: build from source"
echo ""
echo "Building lean-ctx (release)..."
if [[ -d "$RUST_DIR" ]]; then
(cd "$RUST_DIR" && cargo build --release)
local binary="$RUST_DIR/target/release/lean-ctx"
else
cargo install lean-ctx
echo ""
echo "Installed via cargo install."
return
fi
if [[ ! -x "$binary" ]]; then
echo "Error: build failed — binary not found"
exit 1
fi
echo "Built: $binary"
if [[ "$build_only" == "--build-only" ]]; then
echo "Done (build only)."
return
fi
mkdir -p "$INSTALL_DIR"
ln -sf "$binary" "$INSTALL_DIR/lean-ctx"
echo " Linked: $INSTALL_DIR/lean-ctx -> $binary"
finish
}
case "${1:-}" in
--download) install_download ;;
--build-only) install_from_source --build-only ;;
--help|-h)
echo "Usage: $0 [--download|--build-only|--help]"
echo ""
echo " (no args) Build from source (requires Rust)"
echo " --download Download pre-built binary (no Rust needed)"
echo " --build-only Build only, don't install"
echo ""
echo "Environment:"
echo " LEAN_CTX_INSTALL_DIR Custom install directory (default: ~/.local/bin)"
;;
*) install_from_source ;;
esac