-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall-cli.sh
More file actions
executable file
·306 lines (262 loc) · 8.23 KB
/
install-cli.sh
File metadata and controls
executable file
·306 lines (262 loc) · 8.23 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
#!/bin/bash
#
# Parallel CLI Installer
#
# Installs the standalone parallel-cli (includes bundled Python runtime).
# Automatically detects your platform (macOS/Linux, x64/arm64) and downloads
# the appropriate pre-built binary.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/parallel-web/parallel-web-tools/main/install-cli.sh | bash
#
# Or with a specific version:
# curl -fsSL https://raw.githubusercontent.com/parallel-web/parallel-web-tools/main/install-cli.sh | bash -s -- v0.0.1
#
set -e
VERSION="${1:-latest}"
INSTALL_DIR="${HOME}/.local/share/parallel-cli"
BIN_DIR="${HOME}/.local/bin"
REPO="parallel-web/parallel-web-tools"
BINARY_NAME="parallel-cli"
GITHUB_RELEASES="https://github.com/${REPO}/releases"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
print_status() {
echo -e "${CYAN}==>${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}!${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1" >&2
}
# Check for required dependencies
DOWNLOADER=""
if command -v curl >/dev/null 2>&1; then
DOWNLOADER="curl"
elif command -v wget >/dev/null 2>&1; then
DOWNLOADER="wget"
else
print_error "Either curl or wget is required but neither is installed"
exit 1
fi
# Check for unzip
if ! command -v unzip >/dev/null 2>&1; then
print_error "unzip is required but not installed"
exit 1
fi
# Download function that works with both curl and wget
download() {
local url="$1"
local output="$2"
if [ "$DOWNLOADER" = "curl" ]; then
if [ -n "$output" ]; then
curl -fsSL -o "$output" "$url"
else
curl -fsSL "$url"
fi
elif [ "$DOWNLOADER" = "wget" ]; then
if [ -n "$output" ]; then
wget -q -O "$output" "$url"
else
wget -q -O - "$url"
fi
else
return 1
fi
}
# Detect platform
detect_platform() {
local os arch
case "$(uname -s)" in
Darwin)
os="darwin"
;;
Linux)
os="linux"
;;
MINGW*|MSYS*|CYGWIN*)
os="windows"
;;
*)
print_error "Unsupported operating system: $(uname -s)"
exit 1
;;
esac
case "$(uname -m)" in
x86_64|amd64)
arch="x64"
;;
arm64|aarch64)
arch="arm64"
;;
*)
print_error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
echo "${os}-${arch}"
}
# Get latest version from GitHub releases
get_latest_version() {
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
local version
version=$(download "$api_url" "" 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/' || echo "")
if [ -z "$version" ]; then
print_error "Failed to fetch latest version from GitHub"
print_error "Check: ${GITHUB_RELEASES}"
exit 1
fi
echo "$version"
}
# Setup shell PATH
setup_path() {
local shell_name rc_file
shell_name=$(basename "$SHELL")
case "$shell_name" in
bash)
rc_file="$HOME/.bashrc"
[ -f "$HOME/.bash_profile" ] && rc_file="$HOME/.bash_profile"
;;
zsh)
rc_file="$HOME/.zshrc"
;;
fish)
rc_file="$HOME/.config/fish/config.fish"
;;
*)
print_warning "Unknown shell: $shell_name"
print_warning "Add ${BIN_DIR} to your PATH manually"
return
;;
esac
# Check if already in PATH
if [[ ":$PATH:" == *":${BIN_DIR}:"* ]]; then
return
fi
print_status "Adding ${BIN_DIR} to PATH in ${rc_file}..."
if [ "$shell_name" = "fish" ]; then
echo "set -gx PATH ${BIN_DIR} \$PATH" >> "$rc_file"
else
echo "export PATH=\"${BIN_DIR}:\$PATH\"" >> "$rc_file"
fi
print_warning "Restart your shell or run: source ${rc_file}"
}
# Main
main() {
echo ""
echo "========================================"
echo " Parallel CLI Installer "
echo "========================================"
echo ""
# Detect platform
local platform
platform=$(detect_platform)
print_status "Detected platform: ${platform}"
# Determine version
if [ "$VERSION" = "latest" ]; then
print_status "Fetching latest release..."
VERSION=$(get_latest_version)
fi
print_status "Installing version: ${VERSION}"
# Build download URLs - now downloading a zip archive
local archive_name="${BINARY_NAME}-${platform}.zip"
local archive_url="${GITHUB_RELEASES}/download/${VERSION}/${archive_name}"
local checksum_url="${archive_url}.sha256"
# Create directories
mkdir -p "$BIN_DIR"
local tmp_dir
tmp_dir=$(mktemp -d)
local tmp_archive="${tmp_dir}/${archive_name}"
# Download archive
print_status "Downloading ${archive_name}..."
if ! download "$archive_url" "$tmp_archive" 2>/dev/null; then
print_error "Failed to download archive"
print_error "URL: ${archive_url}"
print_error ""
print_error "This could mean:"
print_error " - The release doesn't exist yet"
print_error " - Your platform (${platform}) isn't supported"
print_error ""
print_error "Check available releases: ${GITHUB_RELEASES}"
rm -rf "$tmp_dir"
exit 1
fi
# Download and verify checksum
print_status "Verifying checksum..."
local checksum_file="${tmp_dir}/checksum"
if download "$checksum_url" "$checksum_file" 2>/dev/null; then
local expected_checksum
expected_checksum=$(cat "$checksum_file")
local actual_checksum
if [ "$(uname -s)" = "Darwin" ]; then
actual_checksum=$(shasum -a 256 "$tmp_archive" | cut -d' ' -f1)
else
actual_checksum=$(sha256sum "$tmp_archive" | cut -d' ' -f1)
fi
if [ "$actual_checksum" != "$expected_checksum" ]; then
print_error "Checksum verification failed!"
print_error "Expected: ${expected_checksum}"
print_error "Got: ${actual_checksum}"
rm -rf "$tmp_dir"
exit 1
fi
print_success "Checksum verified"
else
print_warning "Checksum file not available, skipping verification"
fi
# Remove old installation if exists
if [ -d "$INSTALL_DIR" ]; then
print_status "Removing previous installation..."
rm -rf "$INSTALL_DIR"
fi
# Extract archive
print_status "Extracting archive..."
unzip -q "$tmp_archive" -d "$tmp_dir"
# Move to install directory
mv "${tmp_dir}/parallel-cli" "$INSTALL_DIR"
rm -rf "$tmp_dir"
# Create symlink in bin directory
local symlink_path="${BIN_DIR}/${BINARY_NAME}"
rm -f "$symlink_path"
ln -s "${INSTALL_DIR}/${BINARY_NAME}" "$symlink_path"
print_success "Installed to ${INSTALL_DIR}"
print_success "Symlinked to ${symlink_path}"
# Initialize config with auto-update check enabled
local config_dir="${HOME}/.parallel-cli"
local config_file="${config_dir}/config.json"
if [ ! -f "$config_file" ]; then
mkdir -p "$config_dir"
echo '{"auto_update_check": true}' > "$config_file"
print_status "Auto-update check enabled (disable with: parallel-cli config auto-update-check off)"
fi
# Setup PATH
setup_path
# Verify installation
export PATH="${BIN_DIR}:$PATH"
if command -v "${BINARY_NAME}" >/dev/null 2>&1; then
echo ""
print_success "Installation complete!"
echo ""
"${BINARY_NAME}" --version 2>/dev/null || true
echo ""
echo "Next steps:"
echo " 1. Authenticate: ${BINARY_NAME} login"
echo " 2. Search: ${BINARY_NAME} search \"Parallel Web Systems\""
echo " 3. Extract: ${BINARY_NAME} extract https://parallel.ai"
echo " 4. Deep Research: ${BINARY_NAME} research run \"Detailed report on the latest AI research\""
echo " 5. Enrich: ${BINARY_NAME} enrich run --help"
echo ""
else
print_error "Installation verification failed"
exit 1
fi
}
main "$@"