forked from ComposioHQ/composio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·415 lines (344 loc) · 14 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·415 lines (344 loc) · 14 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
#!/usr/bin/env bash
set -euo pipefail
COMPOSIO_GITHUB_OWNER=${COMPOSIO_GITHUB_OWNER-"ComposioHQ"}
COMPOSIO_GITHUB_REPO=${COMPOSIO_GITHUB_REPO-"composio"}
COMPOSIO_GITHUB_URL=${COMPOSIO_GITHUB_URL-"https://github.com"}
COMPOSIO_GITHUB_API_BASE_URL=${COMPOSIO_GITHUB_API_BASE_URL:-}
COMPOSIO_INSTALL_DIR=${COMPOSIO_INSTALL_DIR:-$HOME/.composio}
# --- Input validation ---
# Only allow HTTPS URLs for the download source.
if [[ ! "$COMPOSIO_GITHUB_URL" =~ ^https:// ]]; then
echo "error: COMPOSIO_GITHUB_URL must start with https:// (got \"$COMPOSIO_GITHUB_URL\")" >&2
exit 1
fi
# Owner and repo must be safe identifiers (alphanumeric, hyphens, underscores, dots).
if [[ ! "$COMPOSIO_GITHUB_OWNER" =~ ^[a-zA-Z0-9._-]+$ ]]; then
echo "error: COMPOSIO_GITHUB_OWNER contains invalid characters (got \"$COMPOSIO_GITHUB_OWNER\")" >&2
exit 1
fi
if [[ ! "$COMPOSIO_GITHUB_REPO" =~ ^[a-zA-Z0-9._-]+$ ]]; then
echo "error: COMPOSIO_GITHUB_REPO contains invalid characters (got \"$COMPOSIO_GITHUB_REPO\")" >&2
exit 1
fi
if [[ -n "$COMPOSIO_GITHUB_API_BASE_URL" && ! "$COMPOSIO_GITHUB_API_BASE_URL" =~ ^https:// ]]; then
echo "error: COMPOSIO_GITHUB_API_BASE_URL must start with https:// (got \"$COMPOSIO_GITHUB_API_BASE_URL\")" >&2
exit 1
fi
github_repo="$COMPOSIO_GITHUB_URL/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"
if [[ -n "$COMPOSIO_GITHUB_API_BASE_URL" ]]; then
github_api_base="${COMPOSIO_GITHUB_API_BASE_URL%/}"
elif [[ "$COMPOSIO_GITHUB_URL" = "https://github.com" ]]; then
github_api_base="https://api.github.com"
else
github_api_base="${COMPOSIO_GITHUB_URL%/}/api/v3"
fi
github_api_repo="$github_api_base/repos/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"
# --- Colors (only when interactive) ---
Color_Off='' Red='' Green='' Dim='' Bold_White='' Bold_Green=''
if [[ -t 1 ]]; then
Color_Off='\033[0m'
Red='\033[0;31m'
Green='\033[0;32m'
Dim='\033[0;2m'
Bold_Green='\033[1;32m'
Bold_White='\033[1m'
fi
error() { echo -e "${Red}error${Color_Off}:" "$@" >&2; exit 1; }
warn() { echo -e "${Red}warning${Color_Off}:" "$@" >&2; }
info() { echo -e "${Dim}$*${Color_Off}"; }
info_bold() { echo -e "${Bold_White}$*${Color_Off}"; }
success() { echo -e "${Green}$*${Color_Off}"; }
tildify() {
if [[ $1 = $HOME/* ]]; then
echo "~/${1#$HOME/}"
else
echo "$1"
fi
}
# --- Prerequisites ---
command -v curl >/dev/null || error 'curl is required to install Composio CLI'
command -v unzip >/dev/null || error 'unzip is required to install Composio CLI'
install_agent=false
version_arg=""
while [[ $# -gt 0 ]]; do
case "$1" in
--agent)
install_agent=true
shift
;;
-h|--help)
echo 'Usage: install.sh [--agent] [version-tag] (e.g. "@composio/cli@0.1.32")'
echo ' --agent After installing, sign up/log in as a Composio agent.'
exit 0
;;
--*)
error "Unknown option: $1"
;;
*)
if [[ -n "$version_arg" ]]; then
error 'Too many arguments. Usage: install.sh [--agent] [version-tag] (e.g. "@composio/cli@0.1.32")'
fi
version_arg=$1
shift
;;
esac
done
# --- Platform detection ---
platform=$(uname -ms)
case $platform in
'MINGW64'* | 'MSYS'* | 'CYGWIN'*)
error 'Windows is not supported. Please use WSL or install via npm: npm install -g @composio/cli'
;;
esac
case $platform in
'Darwin x86_64') target=darwin-x64 ;;
'Darwin arm64') target=darwin-aarch64 ;;
'Linux aarch64' | 'Linux arm64')
target=linux-aarch64 ;;
'Linux x86_64') target=linux-x64 ;;
*) error "Unsupported platform: $platform" ;;
esac
# Rosetta 2 detection on macOS
if [[ $target = darwin-x64 ]]; then
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
target=darwin-aarch64
info "Your shell is running in Rosetta 2. Downloading for $target instead"
fi
fi
archive_name="composio-$target.zip"
resolve_latest_cli_release() {
local page release_json release_line
for page in 1 2 3 4 5; do
release_json=$(curl --fail --silent --location "$github_api_repo/releases?per_page=100&page=$page") || return 1
release_line=$(printf '%s\n' "$release_json" \
| sed 's/"tag_name"/\
"tag_name"/g; s/"browser_download_url"/\
"browser_download_url"/g' \
| awk -v asset_name="$archive_name" '
BEGIN {
tag = ""
stable_cli_release = "^@composio/cli@[0-9]+\\.[0-9]+\\.[0-9]+$"
}
/"tag_name":[[:space:]]*"/ {
tag = $0
sub(/^.*"tag_name":[[:space:]]*"/, "", tag)
sub(/".*$/, "", tag)
if (tag !~ stable_cli_release) {
tag = ""
}
}
tag != "" && /"browser_download_url":[[:space:]]*"/ && index($0, "/" asset_name "\"") > 0 {
url = $0
sub(/^.*"browser_download_url":[[:space:]]*"/, "", url)
sub(/".*$/, "", url)
print tag "\t" url
exit
}
')
if [[ -n "$release_line" ]]; then
printf '%s\n' "$release_line"
return 0
fi
if ! printf '%s\n' "$release_json" | grep -q '"tag_name"'; then
break
fi
done
return 1
}
# --- Version resolution ---
if [[ -z "$version_arg" ]]; then
info "Finding latest CLI release..."
latest_release=$(resolve_latest_cli_release) ||
error "Failed to determine the latest CLI release with a $archive_name asset. Please specify a version manually."
version=${latest_release%%$'\t'*}
archive_url=${latest_release#*$'\t'}
info "Found latest version: $version"
else
version=$version_arg
archive_url="$github_repo/releases/download/$version/$archive_name"
fi
# --- Download into temp directory ---
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
checksums_url="$github_repo/releases/download/$version/checksums.txt"
info "Installing Composio CLI $version for $target"
info "Downloading..."
curl --fail --location --progress-bar --output "$tmpdir/$archive_name" "$archive_url" ||
error "Failed to download from \"$archive_url\""
# --- Checksum verification ---
if curl --fail --silent --location --output "$tmpdir/checksums.txt" "$checksums_url" 2>/dev/null; then
expected=$(grep "$archive_name" "$tmpdir/checksums.txt" | awk '{print $1}')
if [[ -n "$expected" ]]; then
if command -v sha256sum &>/dev/null; then
actual=$(sha256sum "$tmpdir/$archive_name" | awk '{print $1}')
elif command -v shasum &>/dev/null; then
actual=$(shasum -a 256 "$tmpdir/$archive_name" | awk '{print $1}')
else
actual=""
warn "No SHA-256 utility found — skipping verification"
fi
if [[ -n "$actual" && "$expected" != "$actual" ]]; then
error "Checksum mismatch for $archive_name\n Expected: $expected\n Actual: $actual"
fi
if [[ -n "$actual" ]]; then
info "Checksum verified"
fi
else
warn "No checksum entry found for $archive_name — skipping verification"
fi
else
info "No checksums.txt in release — skipping verification"
fi
# --- Extract and install ---
info "Extracting..."
unzip -oqd "$tmpdir" "$tmpdir/$archive_name" ||
error 'Failed to extract archive'
mkdir -p "$COMPOSIO_INSTALL_DIR" ||
error "Failed to create install directory \"$COMPOSIO_INSTALL_DIR\""
exe="$COMPOSIO_INSTALL_DIR/composio"
release_tag_file="$COMPOSIO_INSTALL_DIR/release-tag.txt"
install_bundle_support_files() {
local source_dir="$1"
local installed_count=0
while IFS= read -r -d '' source_path; do
local relative_path=${source_path#"$source_dir"/}
local target_path="$COMPOSIO_INSTALL_DIR/$relative_path"
mkdir -p "$(dirname "$target_path")" ||
error "Failed to create support file directory \"$(dirname "$target_path")\""
mv "$source_path" "$target_path" ||
error "Failed to install support file \"$relative_path\""
installed_count=$((installed_count + 1))
done < <(find "$source_dir" -mindepth 1 -type f ! -path "$source_dir/composio" -print0)
if (( installed_count == 0 )); then
warn "This release archive does not include any bundled support files beyond the main binary. Some CLI features may be unavailable in this version."
fi
}
# Handle nested directory structure (composio-<target>/composio)
if [[ -f "$tmpdir/composio-$target/composio" ]]; then
mv "$tmpdir/composio-$target/composio" "$exe"
install_bundle_support_files "$tmpdir/composio-$target"
elif [[ -f "$tmpdir/composio" ]]; then
mv "$tmpdir/composio" "$exe"
install_bundle_support_files "$tmpdir"
else
error 'Binary not found in extracted archive'
fi
chmod +x "$exe" ||
error 'Failed to set permissions on executable'
printf '%s\n' "$version" > "$release_tag_file" ||
error "Failed to write install metadata to \"$release_tag_file\""
success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
# --- Shell integration (PATH + completions) ---
# Delegate to the CLI's own install command, which handles:
# - Idempotent PATH setup in the correct rc file
# - Shell completions installation
# If the binary can't run (e.g. missing runtime), fall back to inline setup.
echo
install_err=$(mktemp)
if COMPOSIO_INSTALL_DIR="$COMPOSIO_INSTALL_DIR" "$exe" install 2>"$install_err"; then
cat "$install_err" >&2 # Show CLI's TerminalUI output on success
else
info "Setting up shell integration..."
refresh_command=''
quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
if [[ $quoted_install_dir = \"$HOME/* ]]; then
quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
fi
shell_name=$(basename "${SHELL:-}")
marker='# Composio CLI'
case $shell_name in
fish)
commands=(
"set --export COMPOSIO_INSTALL_DIR \"$COMPOSIO_INSTALL_DIR\""
"set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH"
)
fish_config=$HOME/.config/fish/config.fish
if [[ -w $fish_config ]] || [[ -w $(dirname "$fish_config") ]]; then
mkdir -p "$(dirname "$fish_config")"
if ! grep -qxF "$marker" "$fish_config" 2>/dev/null; then
{ echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
else
info "PATH already configured in \"$(tildify "$fish_config")\""
fi
refresh_command="source $(tildify "$fish_config")"
else
echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
for cmd in "${commands[@]}"; do info_bold " $cmd"; done
fi
;;
zsh)
commands=(
"export COMPOSIO_INSTALL_DIR=\"$COMPOSIO_INSTALL_DIR\""
"export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
)
zsh_config=$HOME/.zshrc
if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
if [[ -w $zsh_config ]]; then
if ! grep -qxF "$marker" "$zsh_config" 2>/dev/null; then
{ echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
else
info "PATH already configured in \"$(tildify "$zsh_config")\""
fi
refresh_command="source $(tildify "$zsh_config")"
else
echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
for cmd in "${commands[@]}"; do info_bold " $cmd"; done
fi
;;
bash)
commands=(
"export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
"export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
)
bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
if [[ ${XDG_CONFIG_HOME:-} ]]; then
bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
fi
set_manually=true
for bash_config in "${bash_configs[@]}"; do
if [[ -w $bash_config ]]; then
if ! grep -qxF "$marker" "$bash_config" 2>/dev/null; then
{ echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
else
info "PATH already configured in \"$(tildify "$bash_config")\""
fi
refresh_command="source $bash_config"
set_manually=false
break
fi
done
if [[ $set_manually = true ]]; then
echo "Manually add the directory to ~/.bashrc (or similar):"
for cmd in "${commands[@]}"; do info_bold " $cmd"; done
fi
;;
*)
echo 'Manually add the directory to ~/.bashrc (or similar):'
info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
;;
esac
fi
rm -f "$install_err"
if [[ $install_agent = true ]]; then
echo
info "Setting up Composio agent login..."
if ! "$exe" login --agent --no-skill-install; then
error 'Failed to sign up/log in as a Composio agent. If this CLI is already signed in as a regular user, run `composio logout` and then `composio signup` or `composio agent login <composio_agent_key>`.'
fi
fi
echo
info "To get started, run:"
echo
if [[ ${refresh_command:-} ]]; then
info_bold " $refresh_command"
fi
info_bold " composio --help"
if [[ $install_agent = true ]]; then
info_bold " composio agent whoami"
else
info_bold " composio login"
fi