-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·323 lines (264 loc) · 11.1 KB
/
install.sh
File metadata and controls
executable file
·323 lines (264 loc) · 11.1 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
#!/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_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
github_repo="$COMPOSIO_GITHUB_URL/$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'
command -v git >/dev/null || error 'git is required to install Composio CLI'
if [[ $# -gt 1 ]]; then
error 'Too many arguments. Usage: install.sh [version-tag] (e.g. "@composio/cli@0.1.32")'
fi
# --- 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
# --- Version resolution ---
if [[ $# = 0 ]]; then
info "Finding latest CLI release..."
version=$(git ls-remote --tags "$github_repo" "@composio/cli@*" \
| awk '{print $2}' \
| sed 's#^refs/tags/##; s#\^{}$##' \
| sort -V \
| tail -1)
if [[ -z "$version" ]]; then
error "Failed to determine the latest version. Please specify a version manually."
fi
info "Found latest version: $version"
else
version=$1
fi
# --- Download into temp directory ---
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
archive_name="composio-$target.zip"
archive_url="$github_repo/releases/download/$version/$archive_name"
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"
echo
info "To get started, run:"
echo
if [[ ${refresh_command:-} ]]; then
info_bold " $refresh_command"
fi
info_bold " composio --help"
info_bold " composio login"