-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
270 lines (228 loc) · 10.4 KB
/
install.sh
File metadata and controls
270 lines (228 loc) · 10.4 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
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────
# Zilliz CLI Installer
#
# A unified CLI and TUI for managing Zilliz Cloud clusters
# vector database operations.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/zilliztech/zilliz-cli/master/install.sh | bash
#
# Options (via environment variables):
# ZILLIZ_VERSION=v0.1.0 Install a specific version (default: latest)
# ZILLIZ_INSTALL_DIR Override install directory (default: ~/.local/bin)
# ZILLIZ_NO_MODIFY_PATH Set to 1 to skip PATH modification
# ──────────────────────────────────────────────────────────────────────
set -euo pipefail
# ── Configuration ────────────────────────────────────────────────────
PACKAGE_NAME="zilliz-cli" # PyPI package name
BIN_NAME="zilliz" # primary binary name
REPO="zilliztech/zilliz-cli" # GitHub repo
INSTALL_DIR="${ZILLIZ_INSTALL_DIR:-${HOME}/.local/bin}"
REQUESTED_VERSION="${ZILLIZ_VERSION:-latest}"
# ── Logging helpers ──────────────────────────────────────────────────
BOLD='\033[1m'
GREEN='\033[1;32m'
BLUE='\033[1;34m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
RESET='\033[0m'
info() { printf "${BLUE}==>${RESET} ${BOLD}%s${RESET}\n" "$*"; }
success() { printf "${GREEN}==>${RESET} ${BOLD}%s${RESET}\n" "$*"; }
warn() { printf "${YELLOW}Warning:${RESET} %s\n" "$*" >&2; }
error() { printf "${RED}Error:${RESET} %s\n" "$*" >&2; exit 1; }
# ── Detect OS / Arch ─────────────────────────────────────────────────
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "${OS}" in
Linux*) OS="linux" ;;
Darwin*) OS="darwin" ;;
MINGW*|MSYS*|CYGWIN*) OS="windows" ;;
*) error "Unsupported operating system: ${OS}" ;;
esac
case "${ARCH}" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
armv7l) ARCH="armv7" ;;
*) error "Unsupported architecture: ${ARCH}" ;;
esac
}
# ── Check if a command exists ────────────────────────────────────────
has() { command -v "$1" &>/dev/null; }
# ── Uninstall previous Python-based installation ────────────────────
uninstall_python_version() {
local found=0
if has pipx && pipx list 2>/dev/null | grep -q "${PACKAGE_NAME}"; then
info "Found previous Python-based installation (pipx). Removing..."
pipx uninstall "${PACKAGE_NAME}" || true
found=1
fi
if has uv && uv tool list 2>/dev/null | grep -q "${PACKAGE_NAME}"; then
info "Found previous Python-based installation (uv). Removing..."
uv tool uninstall "${PACKAGE_NAME}" || true
found=1
fi
# Check pip-installed version (look for the Python package metadata)
for pip_cmd in pip3 pip; do
if has "${pip_cmd}" && "${pip_cmd}" show "${PACKAGE_NAME}" &>/dev/null; then
info "Found previous Python-based installation (${pip_cmd}). Removing..."
"${pip_cmd}" uninstall -y "${PACKAGE_NAME}" 2>/dev/null || true
found=1
break
fi
done
if [ "${found}" -eq 1 ]; then
success "Previous Python-based installation removed."
fi
}
# ── Build Rust target triple from OS/ARCH ───────────────────────────
get_target_triple() {
case "${OS}-${ARCH}" in
darwin-x86_64) echo "x86_64-apple-darwin" ;;
darwin-aarch64) echo "aarch64-apple-darwin" ;;
linux-x86_64) echo "x86_64-unknown-linux-gnu" ;;
linux-aarch64) echo "aarch64-unknown-linux-gnu" ;;
*) error "No prebuilt binary for ${OS}/${ARCH}" ;;
esac
}
# ══════════════════════════════════════════════════════════════════════
# Install Strategy: Binary (download from GitHub Releases)
# ══════════════════════════════════════════════════════════════════════
install_via_binary() {
# Resolve version tag
local tag="${REQUESTED_VERSION}"
if [ "${tag}" = "latest" ]; then
info "Fetching latest release..."
tag=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | head -1 | cut -d'"' -f4)
[ -n "${tag}" ] || error "Failed to determine latest version"
fi
# Extract version number from tag (e.g. "zilliz-v1.0.1" -> "1.0.1")
local version="${tag}"
version="${version#zilliz-v}"
version="${version#v}"
info "Version: ${version}"
# Build download URL
local target
target=$(get_target_triple)
local archive="${BIN_NAME}-${version}-${target}.tar.gz"
local url="https://github.com/${REPO}/releases/download/${tag}/${archive}"
# Download & verify
TMPDIR_CLEANUP=$(mktemp -d)
local tmpdir="${TMPDIR_CLEANUP}"
trap 'rm -rf "${TMPDIR_CLEANUP}"' EXIT
info "Downloading ${url}..."
curl -fsSL "${url}" -o "${tmpdir}/${archive}"
# Checksum (optional, if sha256sums.txt is published)
local checksums_url="https://github.com/${REPO}/releases/download/${tag}/sha256sums.txt"
if curl -fsSL "${checksums_url}" -o "${tmpdir}/sha256sums.txt" 2>/dev/null; then
info "Verifying checksum..."
if has shasum; then
(cd "${tmpdir}" && shasum -a 256 -c --ignore-missing sha256sums.txt) \
|| error "Checksum verification failed!"
elif has sha256sum; then
(cd "${tmpdir}" && sha256sum -c --ignore-missing sha256sums.txt) \
|| error "Checksum verification failed!"
fi
fi
# Extract & install
info "Extracting to ${INSTALL_DIR}..."
mkdir -p "${INSTALL_DIR}"
tar -xzf "${tmpdir}/${archive}" -C "${tmpdir}"
# Install binary
install -m 755 "${tmpdir}/${BIN_NAME}" "${INSTALL_DIR}/${BIN_NAME}"
# Create zz symlink (short alias for zilliz)
ln -sf "${INSTALL_DIR}/${BIN_NAME}" "${INSTALL_DIR}/zz"
success "Installed ${BIN_NAME} ${version} to ${INSTALL_DIR}/${BIN_NAME}"
}
# ── Ensure INSTALL_DIR is on PATH ────────────────────────────────────
ensure_path() {
if echo "${PATH}" | tr ':' '\n' | grep -qx "${INSTALL_DIR}"; then
return 0
fi
if [ "${ZILLIZ_NO_MODIFY_PATH:-0}" = "1" ]; then
warn "${INSTALL_DIR} is not in your PATH."
warn "Add it manually: export PATH=\"${INSTALL_DIR}:\$PATH\""
return 0
fi
local shell_name
shell_name=$(basename "${SHELL:-bash}")
local profile=""
case "${shell_name}" in
bash)
if [ -f "${HOME}/.bashrc" ]; then
profile="${HOME}/.bashrc"
elif [ -f "${HOME}/.bash_profile" ]; then
profile="${HOME}/.bash_profile"
fi
;;
zsh) profile="${HOME}/.zshrc" ;;
fish) profile="${HOME}/.config/fish/config.fish" ;;
esac
if [ -n "${profile}" ]; then
local path_line
if [ "${shell_name}" = "fish" ]; then
path_line="fish_add_path ${INSTALL_DIR}"
else
path_line="export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
# Avoid duplicate entries
if ! grep -qF "${INSTALL_DIR}" "${profile}" 2>/dev/null; then
printf '\n# Added by Zilliz CLI installer\n%s\n' "${path_line}" >> "${profile}"
info "Added ${INSTALL_DIR} to PATH in ${profile}"
info "Run 'source ${profile}' or open a new terminal to use it."
fi
else
warn "Could not detect shell profile. Add this to your shell config:"
warn " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
}
# ── Uninstall ────────────────────────────────────────────────────────
uninstall() {
info "Uninstalling ${PACKAGE_NAME}..."
# Remove Python-based installations
uninstall_python_version
# Remove binary install and zz symlink
if [ -f "${INSTALL_DIR}/${BIN_NAME}" ]; then
rm -f "${INSTALL_DIR}/${BIN_NAME}"
info "Removed ${INSTALL_DIR}/${BIN_NAME}"
fi
if [ -L "${INSTALL_DIR}/zz" ]; then
rm -f "${INSTALL_DIR}/zz"
info "Removed ${INSTALL_DIR}/zz symlink"
fi
success "Uninstalled ${PACKAGE_NAME}"
exit 0
}
# ── Main ─────────────────────────────────────────────────────────────
main() {
# Handle --uninstall flag
if [ "${1:-}" = "--uninstall" ] || [ "${1:-}" = "uninstall" ]; then
uninstall
fi
printf "\n"
printf "${BOLD} Zilliz CLI Installer${RESET}\n"
printf " Manage Zilliz Cloud from your terminal\n"
printf "\n"
detect_platform
info "Detected platform: ${OS}/${ARCH}"
# Remove previous Python-based installation if present
uninstall_python_version
# Install binary from GitHub Releases
install_via_binary
ensure_path
# Verify installation
printf "\n"
if has "${BIN_NAME}"; then
success "Installation complete!"
info "Run '${BIN_NAME} --help' to get started."
info "Use '${BIN_NAME} login' to authenticate with Zilliz Cloud."
else
success "Installation complete!"
warn "Open a new terminal or run 'source ~/.bashrc' (or ~/.zshrc)"
warn "Then run '${BIN_NAME} --help' to get started."
fi
printf "\n"
}
main "$@"