@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
sh 78 lines 2.8 KB
Raw
1 #!/bin/sh
2 set -eu
3
4 requested_shell() { printf '%s\n' fish; }
5
6 error() {
7 printf 'error: %s\n' "$*" >&2
8 exit 1
9 }
10 is_true() { case ${1:-} in 1 | true) return 0 ;; *) return 1 ;; esac }
11 debug() { if is_true "${COMPOSIO_DEBUG:-}"; then printf '+ %s\n' "$*" >&2; fi; }
12
13 url_authority() {
14 printf '%s\n' "$1" | sed -e 's#^[a-zA-Z][a-zA-Z0-9+.-]*://##' -e 's#[/?#].*$##'
15 }
16
17 is_allowed_http_authority() {
18 case $1 in
19 localhost | localhost:* | 127.0.0.1 | 127.0.0.1:* | '[::1]' | '[::1]':*) return 0 ;;
20 esac
21 if [ -n "${COMPOSIO_INSTALL_ALLOW_HTTP_HOST:-}" ]; then
22 case $1 in "$COMPOSIO_INSTALL_ALLOW_HTTP_HOST" | "$COMPOSIO_INSTALL_ALLOW_HTTP_HOST":*) return 0 ;; esac
23 fi
24 return 1
25 }
26
27 validate_url() {
28 variant_url=$1
29 case $variant_url in *[![:print:]]* | *[[:space:]]*) return 1 ;; esac
30 variant_authority=$(url_authority "$variant_url")
31 [ -n "$variant_authority" ] || return 1
32 case $variant_authority in *@*) return 1 ;; esac
33 case $variant_url in
34 https://*) return 0 ;;
35 http://*) is_allowed_http_authority "$variant_authority" ;;
36 *) return 1 ;;
37 esac
38 }
39
40 download_installer() {
41 variant_url=$1
42 variant_output=$2
43 validate_url "$variant_url" || error "Refusing unsafe installer URL \"$variant_url\""
44 debug "curl GET $variant_url -> $variant_output"
45 case $variant_url in
46 https://*) curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --output "$variant_output" "$variant_url" ;;
47 http://*) curl --fail --silent --show-error --location --proto '=http,https' --proto-redir '=https' --output "$variant_output" "$variant_url" ;;
48 esac
49 }
50
51 cleanup() { [ -z "${variant_tmpdir:-}" ] || [ ! -d "$variant_tmpdir" ] || rm -rf "$variant_tmpdir"; }
52
53 cleanup_on_signal() {
54 cleanup_signal=$1
55 trap - 0 1 2 3 15
56 cleanup || :
57 exit $((128 + cleanup_signal))
58 }
59
60 main() {
61 variant_shell=$(requested_shell)
62 # Internal test override. User-facing docs intentionally omit this variable.
63 variant_script_url=${COMPOSIO_INSTALL_SCRIPT_URL:-https://raw.githubusercontent.com/ComposioHQ/composio/refs/heads/next/install.sh}
64 variant_tmpdir=$(mktemp -d) || error 'Failed to create a temporary directory'
65 debug "temporary directory: $variant_tmpdir"
66 trap cleanup 0
67 trap 'cleanup_on_signal 1' 1
68 trap 'cleanup_on_signal 2' 2
69 trap 'cleanup_on_signal 3' 3
70 trap 'cleanup_on_signal 15' 15
71 download_installer "$variant_script_url" "$variant_tmpdir/install.sh" || error 'Failed to download the base installer'
72 [ -s "$variant_tmpdir/install.sh" ] || error 'Downloaded base installer is empty'
73
74 # The explicit override wins over any inherited COMPOSIO_INSTALL_SHELL, so the route stays authoritative.
75 COMPOSIO_INSTALL_SHELL="$variant_shell" sh "$variant_tmpdir/install.sh" "$@"
76 }
77
78 main "$@"