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
337 lines (271 loc) · 8.37 KB
/
install.sh
File metadata and controls
337 lines (271 loc) · 8.37 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
#!/usr/bin/env bash
set -euo pipefail
platform=$(uname -ms)
# Check for unsupported platforms
case $platform in
'MINGW64'* | 'MSYS'* | 'CYGWIN'*)
echo "Windows installation is not supported yet. Please use WSL or install via npm:"
echo " npm install -g @composio/cli"
exit 1
;;
esac
# Reset
Color_Off=''
# Regular Colors
Red=''
Green=''
Dim='' # White
# Bold
Bold_White=''
Bold_Green=''
if [[ -t 1 ]]; then
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Dim='\033[0;2m' # White
# Bold
Bold_Green='\033[1;32m' # Bold Green
Bold_White='\033[1m' # Bold White
fi
error() {
echo -e "${Red}error${Color_Off}:" "$@" >&2
exit 1
}
info() {
echo -e "${Dim}$@ ${Color_Off}"
}
info_bold() {
echo -e "${Bold_White}$@ ${Color_Off}"
}
success() {
echo -e "${Green}$@ ${Color_Off}"
}
# Check for required tools
command -v unzip >/dev/null ||
error 'unzip is required to install Composio CLI'
command -v curl >/dev/null ||
error 'curl is required to install Composio CLI'
if [[ $# -gt 1 ]]; then
error 'Too many arguments, only 1 is allowed. You can specify a specific version to install. (e.g. "v0.1.24")'
fi
# Determine platform and architecture
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
;;
esac
# Check for musl on Linux
case "$target" in
'linux'*)
if [ -f /etc/alpine-release ]; then
target="$target-musl"
fi
;;
esac
# Special handling for Rosetta on macOS
if [[ $target = darwin-x64 ]]; then
# Is this process running in Rosetta?
# redirect stderr to devnull to avoid error message when not running in Rosetta
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
target=darwin-aarch64
info "Your shell is running in Rosetta 2. Downloading Composio CLI for $target instead"
fi
fi
COMPOSIO_GITHUB_OWNER=${COMPOSIO_GITHUB_OWNER-"ComposioHQ"}
COMPOSIO_GITHUB_REPO=${COMPOSIO_GITHUB_REPO-"composio"}
COMPOSIO_GITHUB_URL=${COMPOSIO_GITHUB_URL-"https://github.com"}
github_repo="$COMPOSIO_GITHUB_URL/$COMPOSIO_GITHUB_OWNER/$COMPOSIO_GITHUB_REPO"
exe_name=composio
# Determine version to install
if [[ $# = 0 ]]; then
info "Finding latest CLI release..."
# Get the latest version tag using OS-specific grep patterns
case $platform in
'Darwin'*)
# BSD/MacOS: Use extended regex with -E
version=$(git ls-remote --tags "$github_repo" \
| awk -F'/' '{print $3}' \
| grep -E "^v\d+\.\d+\.\d+.*" \
| sort -V \
| tail -n1)
;;
*)
# Unix/Linux: Use Perl-compatible regex with -P
version=$(git ls-remote --tags "$github_repo" \
| awk -F'/' '{print $3}' \
| grep -P "^v\d+\.\d+\.\d+.*" \
| sort -V \
| tail -n1)
;;
esac
if [[ -z "$version" ]]; then
error "Failed to determine the latest version. Please specify a version manually."
fi
info "Found latest version: $version"
composio_uri="$github_repo/releases/download/$version/composio-$target.zip"
else
version=$1
composio_uri="$github_repo/releases/download/$version/composio-$target.zip"
fi
info "Installing Composio CLI $version for $target"
COMPOSIO_INSTALL_DIR=${COMPOSIO_INSTALL_DIR:-$HOME/.composio}
exe=$COMPOSIO_INSTALL_DIR/composio
if [[ ! -d $COMPOSIO_INSTALL_DIR ]]; then
mkdir -p "$COMPOSIO_INSTALL_DIR" ||
error "Failed to create install directory \"$COMPOSIO_INSTALL_DIR\""
fi
# Download
info "Downloading Composio CLI..."
curl --fail --location --progress-bar --output "$exe.zip" "$composio_uri" ||
error "Failed to download Composio CLI from \"$composio_uri\""
# Extract
info "Extracting Composio CLI..."
unzip -oqd "$COMPOSIO_INSTALL_DIR" "$exe.zip" ||
error 'Failed to extract Composio CLI'
# Move binary to final location
if [[ -f "$COMPOSIO_INSTALL_DIR/composio-$target/$exe_name" ]]; then
mv "$COMPOSIO_INSTALL_DIR/composio-$target/$exe_name" "$exe" ||
error 'Failed to move extracted binary to destination'
rm -r "$COMPOSIO_INSTALL_DIR/composio-$target"
elif [[ -f "$COMPOSIO_INSTALL_DIR/$exe_name" ]]; then
mv "$COMPOSIO_INSTALL_DIR/$exe_name" "$exe" ||
error 'Failed to move extracted binary to destination'
else
error 'Binary not found in extracted archive'
fi
chmod +x "$exe" ||
error 'Failed to set permissions on Composio CLI executable'
rm "$exe.zip"
tildify() {
if [[ $1 = $HOME/* ]]; then
local replacement=\~/
echo "${1/$HOME\//$replacement}"
else
echo "$1"
fi
}
success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
refresh_command=''
tilde_bin_dir=$(tildify "$COMPOSIO_INSTALL_DIR")
quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
if [[ $quoted_install_dir = \"$HOME/* ]]; then
quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
fi
echo
# Add to shell configuration
case $(basename "$SHELL") 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
tilde_fish_config=$(tildify "$fish_config")
if [[ -w $fish_config ]]; then
{
echo -e '\n# Composio CLI'
for command in "${commands[@]}"; do
echo "$command"
done
} >>"$fish_config"
info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_fish_config\""
refresh_command="source $tilde_fish_config"
else
echo "Manually add the directory to $tilde_fish_config (or similar):"
for command in "${commands[@]}"; do
info_bold " $command"
done
fi
;;
zsh)
commands=(
"export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
"export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
)
zsh_config=$HOME/.zshrc
tilde_zsh_config=$(tildify "$zsh_config")
# Create .zshrc if it doesn't exist and directory is writable
if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then
touch "$zsh_config"
fi
if [[ -w $zsh_config ]]; then
{
echo -e '\n# Composio CLI'
for command in "${commands[@]}"; do
echo "$command"
done
} >>"$zsh_config"
info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_zsh_config\""
refresh_command="exec $SHELL"
else
echo "Manually add the directory to $tilde_zsh_config (or similar):"
for command in "${commands[@]}"; do
info_bold " $command"
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
tilde_bash_config=$(tildify "$bash_config")
if [[ -w $bash_config ]]; then
{
echo -e '\n# Composio CLI'
for command in "${commands[@]}"; do
echo "$command"
done
} >>"$bash_config"
info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_bash_config\""
refresh_command="source $bash_config"
set_manually=false
break
fi
done
if [[ $set_manually = true ]]; then
echo "Manually add the directory to $tilde_bash_config (or similar):"
for command in "${commands[@]}"; do
info_bold " $command"
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
echo
info "To get started, run:"
echo
if [[ $refresh_command ]]; then
info_bold " $refresh_command"
fi
info_bold " composio --help"
info_bold " composio login"