1
#!/usr/bin/env bash
2
set -euo pipefail
3
4
-platform=$(uname -ms)
5
-
6
-# Check for unsupported platforms
7
-case $platform in
8
-'MINGW64'* | 'MSYS'* | 'CYGWIN'*)
9
- echo "Windows installation is not supported yet. Please use WSL or install via npm:"
10
- echo " npm install -g @composio/cli"
11
- exit 1
12
- ;;
13
-esac
4
+COMPOSIO_GITHUB_OWNER=${COMPOSIO_GITHUB_OWNER-"ComposioHQ"}
5
+COMPOSIO_GITHUB_REPO=${COMPOSIO_GITHUB_REPO-"composio"}
6
+COMPOSIO_GITHUB_URL=${COMPOSIO_GITHUB_URL-"https://github.com"}
7
+COMPOSIO_INSTALL_DIR=${COMPOSIO_INSTALL_DIR:-$HOME/.composio}
8
15
-# Reset
16
-Color_Off=''
9
+github_repo="$COMPOSIO_GITHUB_URL/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"
10
18
-# Regular Colors
19
-Red=''
20
-Green=''
21
-Dim='' # White
11
+# --- Colors (only when interactive) ---
12
23
-# Bold
24
-Bold_White=''
25
-Bold_Green=''
13
+Color_Off='' Red='' Green='' Dim='' Bold_White='' Bold_Green=''
14
15
if [[ -t 1 ]]; then
28
- # Reset
29
- Color_Off='\033[0m' # Text Reset
30
-
31
- # Regular Colors
32
- Red='\033[0;31m' # Red
33
- Green='\033[0;32m' # Green
34
- Dim='\033[0;2m' # White
35
-
36
- # Bold
37
- Bold_Green='\033[1;32m' # Bold Green
38
- Bold_White='\033[1m' # Bold White
16
+ Color_Off='\033[0m'
17
+ Red='\033[0;31m'
18
+ Green='\033[0;32m'
19
+ Dim='\033[0;2m'
20
+ Bold_Green='\033[1;32m'
21
+ Bold_White='\033[1m'
22
fi
23
41
-error() {
42
- echo -e "${Red}error${Color_Off}:" "$@" >&2
43
- exit 1
44
-}
45
-
46
-info() {
47
- echo -e "${Dim}$@ ${Color_Off}"
48
-}
24
+error() { echo -e "${Red}error${Color_Off}:" "$@" >&2; exit 1; }
25
+warn() { echo -e "${Red}warning${Color_Off}:" "$@" >&2; }
26
+info() { echo -e "${Dim}$@${Color_Off}"; }
27
+info_bold() { echo -e "${Bold_White}$@${Color_Off}"; }
28
+success() { echo -e "${Green}$@${Color_Off}"; }
29
50
-info_bold() {
51
- echo -e "${Bold_White}$@ ${Color_Off}"
52
-}
53
-
54
-success() {
55
- echo -e "${Green}$@ ${Color_Off}"
30
+tildify() {
31
+ if [[ $1 = $HOME/* ]]; then
32
+ echo "~/${1#$HOME/}"
33
+ else
34
+ echo "$1"
35
+ fi
36
}
37
58
-# Check for required tools
59
-command -v unzip >/dev/null ||
60
- error 'unzip is required to install Composio CLI'
38
+# --- Prerequisites ---
39
62
-command -v curl >/dev/null ||
63
- error 'curl is required to install Composio CLI'
40
+command -v curl >/dev/null || error 'curl is required to install Composio CLI'
41
+command -v unzip >/dev/null || error 'unzip is required to install Composio CLI'
42
+command -v git >/dev/null || error 'git is required to install Composio CLI'
43
44
if [[ $# -gt 1 ]]; then
66
- error 'Too many arguments, only 1 is allowed. You can specify a specific release tag to install. (e.g. "@composio/cli@0.1.24")'
45
+ error 'Too many arguments. Usage: install.sh [version-tag] (e.g. "@composio/cli@0.1.32")'
46
fi
47
69
-# Determine platform and architecture
48
+# --- Platform detection ---
49
+
50
+platform=$(uname -ms)
51
+
52
case $platform in
71
-'Darwin x86_64')
72
- target=darwin-x64
73
- ;;
74
-'Darwin arm64')
75
- target=darwin-aarch64
76
- ;;
77
-'Linux aarch64' | 'Linux arm64')
78
- target=linux-aarch64
79
- ;;
80
-'Linux x86_64' | *)
81
- target=linux-x64
53
+'MINGW64'* | 'MSYS'* | 'CYGWIN'*)
54
+ error 'Windows is not supported. Please use WSL or install via npm: npm install -g @composio/cli'
55
;;
56
esac
57
85
-# Check for musl on Linux
86
-case "$target" in
87
-'linux'*)
88
- if [ -f /etc/alpine-release ]; then
89
- target="$target-musl"
90
- fi
91
- ;;
58
+case $platform in
59
+'Darwin x86_64') target=darwin-x64 ;;
60
+'Darwin arm64') target=darwin-aarch64 ;;
61
+'Linux aarch64' | 'Linux arm64')
62
+ target=linux-aarch64 ;;
63
+'Linux x86_64') target=linux-x64 ;;
64
+*) error "Unsupported platform: $platform" ;;
65
esac
66
94
-# Special handling for Rosetta on macOS
67
+# Rosetta 2 detection on macOS
68
if [[ $target = darwin-x64 ]]; then
96
- # Is this process running in Rosetta?
97
- # redirect stderr to devnull to avoid error message when not running in Rosetta
69
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
70
target=darwin-aarch64
100
- info "Your shell is running in Rosetta 2. Downloading Composio CLI for $target instead"
71
+ info "Your shell is running in Rosetta 2. Downloading for $target instead"
72
fi
73
fi
74
104
-COMPOSIO_GITHUB_OWNER=${COMPOSIO_GITHUB_OWNER-"ComposioHQ"}
105
-COMPOSIO_GITHUB_REPO=${COMPOSIO_GITHUB_REPO-"composio"}
106
-COMPOSIO_GITHUB_URL=${COMPOSIO_GITHUB_URL-"https://github.com"}
107
-github_repo="$COMPOSIO_GITHUB_URL/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"
108
-
109
-exe_name=composio
75
+# --- Version resolution ---
76
111
-# Determine version to install
77
if [[ $# = 0 ]]; then
78
info "Finding latest CLI release..."
114
-
115
- # Get the latest version tag using OS-specific grep patterns
116
- case $platform in
117
- 'Darwin'*)
118
- # BSD/MacOS: Use extended regex with -E
119
- version=$(git ls-remote --tags "$github_repo" \
120
- | awk '{print $2}' \
121
- | sed 's#^refs/tags/##' \
122
- | sed 's#\^{}$##' \
123
- | grep -E "^@composio/cli@\d+\.\d+\.\d+.*" \
124
- | sort -V \
125
- | tail -n1)
126
- ;;
127
- *)
128
- # Unix/Linux: Use Perl-compatible regex with -P
129
- version=$(git ls-remote --tags "$github_repo" \
130
- | awk '{print $2}' \
131
- | sed 's#^refs/tags/##' \
132
- | sed 's#\^{}$##' \
133
- | grep -P "^@composio/cli@\d+\.\d+\.\d+.*" \
134
- | sort -V \
135
- | tail -n1)
136
- ;;
137
- esac
138
-
79
+
80
+ version=$(git ls-remote --tags "$github_repo" "@composio/cli@*" \
81
+ | awk '{print $2}' \
82
+ | sed 's#^refs/tags/##; s#\^{}$##' \
83
+ | sort -V \
84
+ | tail -1)
85
+
86
if [[ -z "$version" ]]; then
87
error "Failed to determine the latest version. Please specify a version manually."
88
fi
142
-
89
+
90
info "Found latest version: $version"
144
-
145
- composio_uri="$github_repo/releases/download/$version/composio-$target.zip"
91
else
92
version=$1
148
- composio_uri="$github_repo/releases/download/$version/composio-$target.zip"
93
fi
94
95
+# --- Download into temp directory ---
96
+
97
+tmpdir="$(mktemp -d)"
98
+trap 'rm -rf "$tmpdir"' EXIT
99
+
100
+archive_name="composio-$target.zip"
101
+archive_url="$github_repo/releases/download/$version/$archive_name"
102
+checksums_url="$github_repo/releases/download/$version/checksums.txt"
103
+
104
info "Installing Composio CLI $version for $target"
105
153
-COMPOSIO_INSTALL_DIR=${COMPOSIO_INSTALL_DIR:-$HOME/.composio}
154
-exe=$COMPOSIO_INSTALL_DIR/composio
106
+info "Downloading..."
107
+curl --fail --location --progress-bar --output "$tmpdir/$archive_name" "$archive_url" ||
108
+ error "Failed to download from \"$archive_url\""
109
+
110
+# --- Checksum verification ---
111
+
112
+if curl --fail --silent --location --output "$tmpdir/checksums.txt" "$checksums_url" 2>/dev/null; then
113
+ expected=$(grep "$archive_name" "$tmpdir/checksums.txt" | awk '{print $1}')
114
156
-if [[ ! -d $COMPOSIO_INSTALL_DIR ]]; then
157
- mkdir -p "$COMPOSIO_INSTALL_DIR" ||
158
- error "Failed to create install directory \"$COMPOSIO_INSTALL_DIR\""
115
+ if [[ -n "$expected" ]]; then
116
+ if command -v sha256sum &>/dev/null; then
117
+ actual=$(sha256sum "$tmpdir/$archive_name" | awk '{print $1}')
118
+ elif command -v shasum &>/dev/null; then
119
+ actual=$(shasum -a 256 "$tmpdir/$archive_name" | awk '{print $1}')
120
+ else
121
+ actual=""
122
+ warn "No SHA-256 utility found — skipping verification"
123
+ fi
124
+
125
+ if [[ -n "$actual" && "$expected" != "$actual" ]]; then
126
+ error "Checksum mismatch for $archive_name\n Expected: $expected\n Actual: $actual"
127
+ fi
128
+
129
+ if [[ -n "$actual" ]]; then
130
+ info "Checksum verified"
131
+ fi
132
+ else
133
+ warn "No checksum entry found for $archive_name — skipping verification"
134
+ fi
135
+else
136
+ info "No checksums.txt in release — skipping verification"
137
fi
138
161
-# Download
162
-info "Downloading Composio CLI..."
163
-curl --fail --location --progress-bar --output "$exe.zip" "$composio_uri" ||
164
- error "Failed to download Composio CLI from \"$composio_uri\""
165
-
166
-# Extract
167
-info "Extracting Composio CLI..."
168
-unzip -oqd "$COMPOSIO_INSTALL_DIR" "$exe.zip" ||
169
- error 'Failed to extract Composio CLI'
170
-
171
-# Move binary to final location
172
-if [[ -f "$COMPOSIO_INSTALL_DIR/composio-$target/$exe_name" ]]; then
173
- mv "$COMPOSIO_INSTALL_DIR/composio-$target/$exe_name" "$exe" ||
174
- error 'Failed to move extracted binary to destination'
175
- rm -r "$COMPOSIO_INSTALL_DIR/composio-$target"
176
-elif [[ -f "$COMPOSIO_INSTALL_DIR/$exe_name" ]]; then
177
- mv "$COMPOSIO_INSTALL_DIR/$exe_name" "$exe" ||
178
- error 'Failed to move extracted binary to destination'
139
+# --- Extract and install ---
140
+
141
+info "Extracting..."
142
+unzip -oqd "$tmpdir" "$tmpdir/$archive_name" ||
143
+ error 'Failed to extract archive'
144
+
145
+mkdir -p "$COMPOSIO_INSTALL_DIR" ||
146
+ error "Failed to create install directory \"$COMPOSIO_INSTALL_DIR\""
147
+
148
+exe="$COMPOSIO_INSTALL_DIR/composio"
149
+
150
+# Handle nested directory structure (composio-<target>/composio)
151
+if [[ -f "$tmpdir/composio-$target/composio" ]]; then
152
+ mv "$tmpdir/composio-$target/composio" "$exe"
153
+elif [[ -f "$tmpdir/composio" ]]; then
154
+ mv "$tmpdir/composio" "$exe"
155
else
156
error 'Binary not found in extracted archive'
157
fi
158
159
chmod +x "$exe" ||
184
- error 'Failed to set permissions on Composio CLI executable'
160
+ error 'Failed to set permissions on executable'
161
186
-rm "$exe.zip"
162
+success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
163
188
-tildify() {
189
- if [[ $1 = $HOME/* ]]; then
190
- local replacement=\~/
191
- echo "${1/$HOME\//$replacement}"
192
- else
193
- echo "$1"
194
- fi
195
-}
164
+# --- Shell configuration ---
165
197
-success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
166
+echo
167
168
refresh_command=''
200
-
201
-tilde_bin_dir=$(tildify "$COMPOSIO_INSTALL_DIR")
169
quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
170
171
if [[ $quoted_install_dir = \"$HOME/* ]]; then
172
quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
173
fi
174
208
-echo
209
-
210
-# Add to shell configuration
175
case $(basename "$SHELL") in
176
fish)
177
commands=(
178
"set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
179
"set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
180
)
217
-
181
fish_config=$HOME/.config/fish/config.fish
219
- tilde_fish_config=$(tildify "$fish_config")
220
-
182
if [[ -w $fish_config ]]; then
222
- {
223
- echo -e '\n# Composio CLI'
224
-
225
- for command in "${commands[@]}"; do
226
- echo "$command"
227
- done
228
- } >>"$fish_config"
229
-
230
- info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_fish_config\""
231
-
232
- refresh_command="source $tilde_fish_config"
183
+ { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
184
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
185
+ refresh_command="source $(tildify "$fish_config")"
186
else
234
- echo "Manually add the directory to $tilde_fish_config (or similar):"
235
-
236
- for command in "${commands[@]}"; do
237
- info_bold " $command"
238
- done
187
+ echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
188
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
189
fi
190
;;
191
zsh)
193
"export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
194
"export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
195
)
246
-
196
zsh_config=$HOME/.zshrc
248
- tilde_zsh_config=$(tildify "$zsh_config")
249
-
250
- # Create .zshrc if it doesn't exist and directory is writable
251
- if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then
252
- touch "$zsh_config"
253
- fi
254
-
197
+ if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
198
if [[ -w $zsh_config ]]; then
256
- {
257
- echo -e '\n# Composio CLI'
258
-
259
- for command in "${commands[@]}"; do
260
- echo "$command"
261
- done
262
- } >>"$zsh_config"
263
-
264
- info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_zsh_config\""
265
-
199
+ { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
200
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
201
refresh_command="exec $SHELL"
202
else
268
- echo "Manually add the directory to $tilde_zsh_config (or similar):"
269
-
270
- for command in "${commands[@]}"; do
271
- info_bold " $command"
272
- done
203
+ echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
204
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
205
fi
206
;;
207
bash)
209
"export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
210
"export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
211
)
280
-
281
- bash_configs=(
282
- "$HOME/.bashrc"
283
- "$HOME/.bash_profile"
284
- )
285
-
212
+ bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
213
if [[ ${XDG_CONFIG_HOME:-} ]]; then
287
- bash_configs+=(
288
- "$XDG_CONFIG_HOME/.bash_profile"
289
- "$XDG_CONFIG_HOME/.bashrc"
290
- "$XDG_CONFIG_HOME/bash_profile"
291
- "$XDG_CONFIG_HOME/bashrc"
292
- )
214
+ bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
215
fi
294
-
216
set_manually=true
217
for bash_config in "${bash_configs[@]}"; do
297
- tilde_bash_config=$(tildify "$bash_config")
298
-
218
if [[ -w $bash_config ]]; then
300
- {
301
- echo -e '\n# Composio CLI'
302
-
303
- for command in "${commands[@]}"; do
304
- echo "$command"
305
- done
306
- } >>"$bash_config"
307
-
308
- info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_bash_config\""
309
-
219
+ { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
220
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
221
refresh_command="source $bash_config"
222
set_manually=false
223
break
224
fi
225
done
315
-
226
if [[ $set_manually = true ]]; then
317
- echo "Manually add the directory to $tilde_bash_config (or similar):"
318
-
319
- for command in "${commands[@]}"; do
320
- info_bold " $command"
321
- done
227
+ echo "Manually add the directory to ~/.bashrc (or similar):"
228
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
229
fi
230
;;
324
-
231
*)
232
echo 'Manually add the directory to ~/.bashrc (or similar):'
233
info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"