11#! /usr/bin/env bash
2- # Vapi CLI installation script
3- # Usage: curl -sSL https://vapi.ai/install.sh | bash
2+ set -euo pipefail
43
5- set -e
4+ platform= $( uname -ms )
65
7- # Configuration
8- REPO=" VapiAI/cli"
9- BINARY_NAME=" vapi"
10- INSTALL_DIR=" ${INSTALL_DIR:-/ usr/ local/ bin} "
6+ if [[ ${OS:- } = Windows_NT ]]; then
7+ if [[ $platform != MINGW64* ]]; then
8+ powershell -c " irm vapi.ai/install.ps1|iex"
9+ exit $?
10+ fi
11+ fi
1112
12- # Colors
13- RED=' \033[0;31m'
14- GREEN=' \033[0;32m'
15- YELLOW=' \033[1;33m'
16- NC=' \033[0m' # No Color
13+ # Reset
14+ Color_Off=' '
1715
18- # Helper functions
19- log () {
20- echo -e " ${GREEN} [INFO]${NC} $1 "
21- }
16+ # Regular Colors
17+ Red=' '
18+ Green=' '
19+ Dim=' '
20+
21+ # Bold
22+ Bold_White=' '
23+ Bold_Green=' '
24+
25+ if [[ -t 1 ]]; then
26+ # Reset
27+ Color_Off=' \033[0m'
28+
29+ # Regular Colors
30+ Red=' \033[0;31m'
31+ Green=' \033[0;32m'
32+ Dim=' \033[0;2m'
33+
34+ # Bold
35+ Bold_Green=' \033[1;32m'
36+ Bold_White=' \033[1m'
37+ fi
2238
2339error () {
24- echo -e " ${RED} [ERROR] ${NC} $1 " >&2
40+ echo -e " ${Red} error ${Color_Off} : " " $@ " >&2
2541 exit 1
2642}
2743
28- warn () {
29- echo -e " ${YELLOW} [WARN] ${NC} $1 "
44+ info () {
45+ echo -e " ${Dim} $@ ${Color_Off} "
3046}
3147
32- # Detect OS and architecture
33- detect_platform () {
34- OS=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
35- ARCH=$( uname -m)
36-
37- case " $OS " in
38- darwin) OS=" Darwin" ;;
39- linux) OS=" Linux" ;;
40- mingw* |msys* |cygwin* ) OS=" Windows" ;;
41- * ) error " Unsupported operating system: $OS " ;;
42- esac
43-
44- case " $ARCH " in
45- x86_64) ARCH=" x86_64" ;;
46- amd64) ARCH=" x86_64" ;;
47- aarch64) ARCH=" arm64" ;;
48- arm64) ARCH=" arm64" ;;
49- armv7l) ARCH=" armv7" ;;
50- * ) error " Unsupported architecture: $ARCH " ;;
51- esac
52-
53- PLATFORM=" ${OS} _${ARCH} "
54- log " Detected platform: $PLATFORM "
48+ info_bold () {
49+ echo -e " ${Bold_White} $@ ${Color_Off} "
5550}
5651
57- # Get latest release version
58- get_latest_version () {
59- log " Fetching latest version..."
60- VERSION=$( curl -s " https://api.github.com/repos/$REPO /releases/latest" | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
61-
62- if [ -z " $VERSION " ]; then
63- error " Failed to fetch latest version"
64- fi
65-
66- log " Latest version: $VERSION "
52+ success () {
53+ echo -e " ${Green} $@ ${Color_Off} "
6754}
6855
69- # Download and install
70- install_vapi () {
71- local url=" https://github.com/$REPO /releases/download/$VERSION /${BINARY_NAME} _${PLATFORM} .tar.gz"
72- local tmp_dir=$( mktemp -d)
73-
74- log " Downloading Vapi CLI..."
75- log " URL: $url "
76-
77- if ! curl -sL " $url " -o " $tmp_dir /vapi.tar.gz" ; then
78- error " Failed to download Vapi CLI"
56+ command -v curl > /dev/null ||
57+ error ' curl is required to install vapi'
58+
59+ command -v tar > /dev/null ||
60+ error ' tar is required to install vapi'
61+
62+ case $platform in
63+ ' Darwin x86_64' )
64+ target=Darwin_x86_64
65+ ;;
66+ ' Darwin arm64' )
67+ target=Darwin_arm64
68+ ;;
69+ ' Linux aarch64' | ' Linux arm64' )
70+ target=Linux_arm64
71+ ;;
72+ ' MINGW64' * )
73+ target=Windows_x86_64
74+ ;;
75+ ' Linux x86_64' | * )
76+ target=Linux_x86_64
77+ ;;
78+ esac
79+
80+ GITHUB=${GITHUB-" https://github.com" }
81+ github_repo=" $GITHUB /VapiAI/cli"
82+
83+ # Get latest version
84+ if [[ $# = 0 ]]; then
85+ version=$( curl -s " $github_repo /releases/latest" | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
86+ if [[ -z $version ]]; then
87+ error " Failed to fetch latest version"
7988 fi
80-
81- log " Extracting..."
82- tar -xzf " $tmp_dir /vapi.tar.gz" -C " $tmp_dir "
83-
84- # Check if we need sudo
85- if [ -w " $INSTALL_DIR " ]; then
86- mv " $tmp_dir /$BINARY_NAME " " $INSTALL_DIR /"
89+ vapi_uri=" $github_repo /releases/download/$version /vapi_$target .tar.gz"
90+ else
91+ vapi_uri=" $github_repo /releases/download/$1 /vapi_$target .tar.gz"
92+ fi
93+
94+ install_env=VAPI_INSTALL
95+ bin_env=\$ $install_env /bin
96+
97+ install_dir=${! install_env:- $HOME / .vapi}
98+ bin_dir=$install_dir /bin
99+ exe=$bin_dir /vapi
100+
101+ if [[ ! -d $bin_dir ]]; then
102+ mkdir -p " $bin_dir " ||
103+ error " Failed to create install directory \" $bin_dir \" "
104+ fi
105+
106+ curl --fail --location --progress-bar --output " $exe .tar.gz" " $vapi_uri " ||
107+ error " Failed to download vapi from \" $vapi_uri \" "
108+
109+ tar -xzf " $exe .tar.gz" -C " $bin_dir " ||
110+ error ' Failed to extract vapi'
111+
112+ # Handle different possible binary names
113+ if [[ -f " $bin_dir /vapi.exe" ]]; then
114+ mv " $bin_dir /vapi.exe" " $exe "
115+ elif [[ -f " $bin_dir /vapi" ]]; then
116+ mv " $bin_dir /vapi" " $exe "
117+ else
118+ error ' Failed to find vapi binary in extracted files'
119+ fi
120+
121+ chmod +x " $exe " ||
122+ error ' Failed to set permissions on vapi executable'
123+
124+ rm " $exe .tar.gz"
125+
126+ tildify () {
127+ if [[ $1 = $HOME /* ]]; then
128+ local replacement=\~ /
129+ echo " ${1/ $HOME \/ / $replacement } "
87130 else
88- log " Installing to $INSTALL_DIR (requires sudo)..."
89- sudo mv " $tmp_dir /$BINARY_NAME " " $INSTALL_DIR /"
131+ echo " $1 "
90132 fi
91-
92- # Make executable
93- chmod +x " $INSTALL_DIR /$BINARY_NAME "
94-
95- # Cleanup
96- rm -rf " $tmp_dir "
97-
98- log " Vapi CLI installed successfully!"
99133}
100134
101- # Verify installation
102- verify_installation () {
103- if command -v vapi & > /dev/null; then
104- log " Verification: $( vapi --version) "
105- echo " "
106- log " Installation complete! 🎉"
107- echo " "
108- echo " Get started with:"
109- echo " vapi login"
110- echo " vapi --help"
135+ success " vapi was installed successfully to $Bold_Green $( tildify " $exe " ) "
136+
137+ if command -v vapi > /dev/null; then
138+ echo " Run 'vapi --help' to get started"
139+ exit
140+ fi
141+
142+ refresh_command=' '
143+
144+ tilde_bin_dir=$( tildify " $bin_dir " )
145+ quoted_install_dir=\" ${install_dir// \" / \\\" } \"
146+
147+ if [[ $quoted_install_dir = \" $HOME /* ]]; then
148+ quoted_install_dir=${quoted_install_dir/ $HOME \/ / \$ HOME/ }
149+ fi
150+
151+ echo
152+
153+ case $( basename " $SHELL " ) in
154+ fish)
155+ commands=(
156+ " set --export $install_env $quoted_install_dir "
157+ " set --export PATH $bin_env \$ PATH"
158+ )
159+
160+ fish_config=$HOME /.config/fish/config.fish
161+ tilde_fish_config=$( tildify " $fish_config " )
162+
163+ if [[ -w $fish_config ]]; then
164+ {
165+ echo -e ' \n# vapi'
166+ for command in " ${commands[@]} " ; do
167+ echo " $command "
168+ done
169+ } >> " $fish_config "
170+
171+ info " Added \" $tilde_bin_dir \" to \$ PATH in \" $tilde_fish_config \" "
172+ refresh_command=" source $tilde_fish_config "
111173 else
112- warn " Vapi CLI was installed but not found in PATH"
113- warn " You may need to add $INSTALL_DIR to your PATH"
114- warn " Or restart your terminal"
174+ echo " Manually add the directory to $tilde_fish_config (or similar):"
175+ for command in " ${commands[@]} " ; do
176+ info_bold " $command "
177+ done
115178 fi
116- }
179+ ;;
180+ zsh)
181+ commands=(
182+ " export $install_env =$quoted_install_dir "
183+ " export PATH=\" $bin_env :\$ PATH\" "
184+ )
117185
118- # Main installation flow
119- main () {
120- echo " ==================================="
121- echo " Vapi CLI Installer"
122- echo " ==================================="
123- echo " "
124-
125- detect_platform
126- get_latest_version
127- install_vapi
128- verify_installation
129- }
186+ zsh_config=$HOME /.zshrc
187+ tilde_zsh_config=$( tildify " $zsh_config " )
188+
189+ if [[ -w $zsh_config ]]; then
190+ {
191+ echo -e ' \n# vapi'
192+ for command in " ${commands[@]} " ; do
193+ echo " $command "
194+ done
195+ } >> " $zsh_config "
196+
197+ info " Added \" $tilde_bin_dir \" to \$ PATH in \" $tilde_zsh_config \" "
198+ refresh_command=" exec $SHELL "
199+ else
200+ echo " Manually add the directory to $tilde_zsh_config (or similar):"
201+ for command in " ${commands[@]} " ; do
202+ info_bold " $command "
203+ done
204+ fi
205+ ;;
206+ bash)
207+ commands=(
208+ " export $install_env =$quoted_install_dir "
209+ " export PATH=\" $bin_env :\$ PATH\" "
210+ )
211+
212+ bash_configs=(
213+ " $HOME /.bashrc"
214+ " $HOME /.bash_profile"
215+ )
216+
217+ if [[ ${XDG_CONFIG_HOME:- } ]]; then
218+ bash_configs+=(
219+ " $XDG_CONFIG_HOME /.bash_profile"
220+ " $XDG_CONFIG_HOME /.bashrc"
221+ " $XDG_CONFIG_HOME /bash_profile"
222+ " $XDG_CONFIG_HOME /bashrc"
223+ )
224+ fi
225+
226+ set_manually=true
227+ for bash_config in " ${bash_configs[@]} " ; do
228+ tilde_bash_config=$( tildify " $bash_config " )
229+
230+ if [[ -w $bash_config ]]; then
231+ {
232+ echo -e ' \n# vapi'
233+ for command in " ${commands[@]} " ; do
234+ echo " $command "
235+ done
236+ } >> " $bash_config "
237+
238+ info " Added \" $tilde_bin_dir \" to \$ PATH in \" $tilde_bash_config \" "
239+ refresh_command=" source $bash_config "
240+ set_manually=false
241+ break
242+ fi
243+ done
244+
245+ if [[ $set_manually = true ]]; then
246+ echo " Manually add the directory to $tilde_bash_config (or similar):"
247+ for command in " ${commands[@]} " ; do
248+ info_bold " $command "
249+ done
250+ fi
251+ ;;
252+ * )
253+ echo ' Manually add the directory to ~/.bashrc (or similar):'
254+ info_bold " export $install_env =$quoted_install_dir "
255+ info_bold " export PATH=\" $bin_env :\$ PATH\" "
256+ ;;
257+ esac
258+
259+ echo
260+ info " To get started, run:"
261+ echo
262+
263+ if [[ $refresh_command ]]; then
264+ info_bold " $refresh_command "
265+ fi
130266
131- # Run main function
132- main " $@ "
267+ info_bold " vapi --help"
0 commit comments