-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·218 lines (185 loc) · 6.98 KB
/
install.sh
File metadata and controls
executable file
·218 lines (185 loc) · 6.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
215
216
217
218
#!/bin/bash
# LLMKube Installation Script
# Usage: curl -sSL https://raw.githubusercontent.com/defilantech/LLMKube/main/install.sh | bash
#
# Options (via environment variables):
# LLMKUBE_VERSION - Install specific version (default: latest)
# LLMKUBE_INSTALL_DIR - Installation directory (default: /usr/local/bin)
# LLMKUBE_NO_SUDO - Set to 1 to skip sudo (for user-local installs)
# LLMKUBE_SKIP_CHECKSUM - Set to 1 to skip sha256 verification (NOT recommended)
set -e
REPO="defilantech/LLMKube"
BINARY_NAME="llmkube" # binary installed into $INSTALL_DIR
ARCHIVE_PREFIX="LLMKube" # tarball filename prefix emitted by goreleaser
INSTALL_DIR="${LLMKUBE_INSTALL_DIR:-/usr/local/bin}"
# 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
detect_os() {
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$OS" in
linux*) OS="linux" ;;
darwin*) OS="darwin" ;;
mingw*|msys*|cygwin*) OS="windows" ;;
*) error "Unsupported operating system: $OS" ;;
esac
echo "$OS"
}
# Detect architecture
detect_arch() {
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
echo "$ARCH"
}
# Get latest version from GitHub API
get_latest_version() {
if command -v curl &> /dev/null; then
curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
elif command -v wget &> /dev/null; then
wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
else
error "curl or wget is required to download llmkube"
fi
}
# Compute sha256 of a file, using whichever tool is available on this host.
compute_sha256() {
local file="$1"
if command -v sha256sum &> /dev/null; then
sha256sum "$file" | awk '{print $1}'
elif command -v shasum &> /dev/null; then
shasum -a 256 "$file" | awk '{print $1}'
else
error "Neither sha256sum nor shasum is available; cannot verify integrity. Install one, or set LLMKUBE_SKIP_CHECKSUM=1 to bypass (NOT recommended)."
fi
}
# Fetch the release checksums.txt and verify the downloaded archive matches.
# Aborts on any failure unless LLMKUBE_SKIP_CHECKSUM=1 is set.
verify_checksum() {
local archive="$1"
local filename="$2"
local checksums_url="$3"
local tmp_dir="$4"
if [[ "${LLMKUBE_SKIP_CHECKSUM:-0}" == "1" ]]; then
warn "LLMKUBE_SKIP_CHECKSUM=1 — skipping integrity verification. Not recommended for production."
return 0
fi
info "Fetching checksums.txt..."
if command -v curl &> /dev/null; then
curl -fsSL "$checksums_url" -o "$tmp_dir/checksums.txt" \
|| error "Failed to fetch checksums.txt from $checksums_url. Set LLMKUBE_SKIP_CHECKSUM=1 to bypass (NOT recommended)."
else
wget -q "$checksums_url" -O "$tmp_dir/checksums.txt" \
|| error "Failed to fetch checksums.txt from $checksums_url. Set LLMKUBE_SKIP_CHECKSUM=1 to bypass (NOT recommended)."
fi
local expected
expected=$(awk -v fname="$filename" '$2 == fname { print $1 }' "$tmp_dir/checksums.txt")
if [[ -z "$expected" ]]; then
error "No checksum entry for $filename in checksums.txt. Set LLMKUBE_SKIP_CHECKSUM=1 to bypass (NOT recommended)."
fi
local actual
actual=$(compute_sha256 "$archive")
if [[ "$actual" != "$expected" ]]; then
error "Checksum mismatch for $filename
expected: $expected
actual: $actual
Refusing to install a binary that does not match its published checksum."
fi
info "Checksum verified (sha256: ${actual:0:12}…)"
}
# Download and install
download_and_install() {
local version="$1"
local os="$2"
local arch="$3"
# Remove 'v' prefix for filename
local version_num="${version#v}"
# Construct download URL (archive name follows goreleaser's "{{ .ProjectName }}_..."
# template, which resolves to "LLMKube_..." for this project.)
local filename="${ARCHIVE_PREFIX}_${version_num}_${os}_${arch}.tar.gz"
local url="https://github.com/${REPO}/releases/download/${version}/${filename}"
local checksums_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
info "Downloading llmkube ${version} for ${os}/${arch}..."
# Create temp directory
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
# Download (use -f so HTTP 4xx/5xx fail fast instead of silently saving an error page)
if command -v curl &> /dev/null; then
curl -fsSL "$url" -o "$tmp_dir/llmkube.tar.gz" || error "Failed to download from $url"
else
wget -q "$url" -O "$tmp_dir/llmkube.tar.gz" || error "Failed to download from $url"
fi
# Verify checksum before unpacking any untrusted bytes
verify_checksum "$tmp_dir/llmkube.tar.gz" "$filename" "$checksums_url" "$tmp_dir"
# Extract
info "Extracting..."
tar -xzf "$tmp_dir/llmkube.tar.gz" -C "$tmp_dir"
# Install
info "Installing to ${INSTALL_DIR}..."
if [[ -w "$INSTALL_DIR" ]] || [[ "${LLMKUBE_NO_SUDO:-0}" == "1" ]]; then
mv "$tmp_dir/$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
sudo mv "$tmp_dir/$BINARY_NAME" "$INSTALL_DIR/"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
}
# Verify installation
verify_installation() {
if command -v llmkube &> /dev/null; then
info "Installation successful!"
echo ""
llmkube version
echo ""
info "Run 'llmkube --help' to get started"
else
warn "Installation complete, but 'llmkube' not found in PATH"
warn "You may need to add ${INSTALL_DIR} to your PATH"
fi
}
# Main
main() {
echo ""
echo " _ _ __ __ _ __ _ "
echo " | | | | | \/ | |/ / | | "
echo " | | | | | \ / | ' / _ _| |__ ___ "
echo " | | | | | |\/| | < | | | | '_ \ / _ \\"
echo " | |___| |___| | | | . \| |_| | |_) | __/"
echo " |_____|_____|_| |_|_|\_\\\\__,_|_.__/ \___|"
echo ""
echo " GPU-accelerated LLM inference on Kubernetes"
echo ""
# Check for Homebrew on macOS
local os=$(detect_os)
if [[ "$os" == "darwin" ]] && command -v brew &> /dev/null; then
warn "Homebrew detected! Consider using: brew install defilantech/tap/llmkube"
echo ""
fi
local arch=$(detect_arch)
local version="${LLMKUBE_VERSION:-$(get_latest_version)}"
if [[ -z "$version" ]]; then
error "Failed to determine latest version. Set LLMKUBE_VERSION manually."
fi
info "Detected: ${os}/${arch}"
info "Version: ${version}"
echo ""
download_and_install "$version" "$os" "$arch"
verify_installation
}
main "$@"