-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·414 lines (368 loc) · 13.5 KB
/
install.sh
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#!/bin/bash
set -e
if [[ -t 1 ]]; then
tty_escape() { printf "\033[%sm" "$1"; }
else
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_blue="$(tty_mkbold 34)"
tty_red="$(tty_mkbold 31)"
tty_bold="$(tty_mkbold 39)"
tty_reset="$(tty_escape 0)"
tty_cyan="$(tty_mkbold 36)"
tty_underline="$(tty_escape 4)"
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$1"
}
url() {
printf "${tty_cyan}${tty_underline}%s${tty_reset}" "$1"
}
warn() {
printf "${tty_red}Warning${tty_reset}: %s\n" "$1" >&2
}
abort() {
printf "${tty_red}Error${tty_reset}: %s\n" "$1" >&2
exit 1
}
success() {
ohai "Installation complete! Run 'agentuity --help' to get started."
ohai "For more information, visit: $(url "https://agentuity.dev")"
exit 0
}
OS="$(uname -s)"
ARCH="$(uname -m)"
if [[ "$ARCH" == "x86_64" ]]; then
ARCH="x86_64"
elif [[ "$ARCH" == "amd64" ]]; then
ARCH="x86_64"
elif [[ "$ARCH" == "arm64" ]]; then
ARCH="arm64"
elif [[ "$ARCH" == "aarch64" ]]; then
ARCH="arm64"
else
abort "Unsupported architecture: $ARCH"
fi
if [[ "$OS" == "Darwin" ]]; then
OS="Darwin"
EXTENSION="tar.gz"
if [[ -d "$HOME/.local/bin" ]] && [[ -w "$HOME/.local/bin" ]]; then
INSTALL_DIR="$HOME/.local/bin"
elif [[ -d "$HOME/bin" ]] && [[ -w "$HOME/bin" ]]; then
INSTALL_DIR="$HOME/bin"
else
INSTALL_DIR="/usr/local/bin"
fi
elif [[ "$OS" == "Linux" ]]; then
OS="Linux"
EXTENSION="tar.gz"
if [[ -d "$HOME/.local/bin" ]] && [[ -w "$HOME/.local/bin" ]]; then
INSTALL_DIR="$HOME/.local/bin"
elif [[ -d "$HOME/bin" ]] && [[ -w "$HOME/bin" ]]; then
INSTALL_DIR="$HOME/bin"
else
INSTALL_DIR="/usr/local/bin"
fi
elif [[ "$OS" == "MINGW"* ]] || [[ "$OS" == "MSYS"* ]] || [[ "$OS" == "CYGWIN"* ]]; then
OS="Windows"
EXTENSION="msi"
INSTALL_DIR="$HOME/bin"
else
abort "Unsupported operating system: $OS"
fi
VERSION="latest"
INSTALL_PATH="$INSTALL_DIR"
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--version)
VERSION="$2"
shift 2
;;
-d|--dir)
INSTALL_PATH="$2"
shift 2
;;
--no-brew)
NO_BREW=true
shift
;;
-h|--help)
echo "Usage: install.sh [options]"
echo "Options:"
echo " -v, --version VERSION Install specific version"
echo " -d, --dir DIRECTORY Install to specific directory"
if [[ "$OS" == "Darwin" ]]; then
echo " --no-brew Skip Homebrew installation on macOS"
fi
echo " -h, --help Show this help message"
exit 0
;;
*)
warn "Unknown option: $1"
shift
;;
esac
done
if [[ ! -d "$INSTALL_PATH" ]]; then
ohai "Creating install directory: $INSTALL_PATH"
mkdir -p "$INSTALL_PATH" 2>/dev/null || true # Don't abort if mkdir fails
fi
if [[ "$OS" == "Darwin" ]] && command -v brew >/dev/null 2>&1 && [[ "$NO_BREW" != "true" ]]; then
ohai "Homebrew detected! Installing Agentuity CLI using Homebrew..."
if [[ "$VERSION" != "latest" ]]; then
ohai "Installing Agentuity CLI version $VERSION using Homebrew..."
if [[ -z "$VERSION" ]]; then
abort "Version is empty. This should not happen."
fi
VERSION="${VERSION#v}"
ohai "Using Homebrew formula: agentuity/tap/agentuity@$VERSION"
brew install "agentuity/tap/agentuity@$VERSION"
else
ohai "Installing latest Agentuity CLI version using Homebrew..."
brew install -q agentuity/tap/agentuity
fi
if command -v agentuity >/dev/null 2>&1; then
success
else
abort "Homebrew installation failed. Please try again or use manual installation."
fi
fi
if [[ ! -d "$INSTALL_PATH" ]] || [[ ! -w "$INSTALL_PATH" ]]; then
if [[ "$INSTALL_PATH" == "/usr/local/bin" ]]; then
ohai "No write permission to $INSTALL_PATH. Trying alternative locations..."
if [[ -d "$HOME/.local/bin" ]] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then
if [[ -w "$HOME/.local/bin" ]]; then
ohai "Using $HOME/.local/bin instead"
INSTALL_PATH="$HOME/.local/bin"
fi
elif [[ -d "$HOME/bin" ]] || mkdir -p "$HOME/bin" 2>/dev/null; then
if [[ -w "$HOME/bin" ]]; then
ohai "Using $HOME/bin instead"
INSTALL_PATH="$HOME/bin"
fi
else
abort "Could not find or create a writable installation directory. Try running with sudo or specify a different directory with --dir."
fi
else
abort "No write permission to $INSTALL_PATH. Try running with sudo or specify a different directory with --dir."
fi
fi
TMP_DIR="$(mktemp -d)"
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
if [[ "$VERSION" == "latest" ]]; then
ohai "Fetching latest release information..."
RELEASE_URL="https://agentuity.sh/release/cli"
VERSION=$(curl -s $RELEASE_URL | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ -z "$VERSION" ]]; then
abort "Failed to fetch latest version information"
fi
fi
VERSION="${VERSION#v}"
if [[ "$OS" == "Windows" ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
DOWNLOAD_FILENAME="agentuity-x64.msi"
elif [[ "$ARCH" == "arm64" ]]; then
DOWNLOAD_FILENAME="agentuity-arm64.msi"
else
DOWNLOAD_FILENAME="agentuity-x86.msi"
fi
else
DOWNLOAD_FILENAME="agentuity_${OS}_${ARCH}.${EXTENSION}"
fi
DOWNLOAD_URL="https://github.com/agentuity/cli/releases/download/v${VERSION}/${DOWNLOAD_FILENAME}"
CHECKSUMS_URL="https://github.com/agentuity/cli/releases/download/v${VERSION}/checksums.txt"
ohai "Downloading Agentuity CLI v${VERSION} for ${OS}/${ARCH}..."
curl -L --progress-bar "$DOWNLOAD_URL" -o "$TMP_DIR/$DOWNLOAD_FILENAME" || abort "Failed to download from $DOWNLOAD_URL"
if [[ "$OS" != "Windows" ]]; then
ohai "Downloading checksums for verification..."
if ! curl -L --silent "$CHECKSUMS_URL" -o "$TMP_DIR/checksums.txt"; then
warn "Failed to download checksums file. Skipping verification."
else
ohai "Verifying checksum..."
if command -v sha256sum >/dev/null 2>&1; then
CHECKSUM_TOOL="sha256sum"
elif command -v shasum >/dev/null 2>&1; then
CHECKSUM_TOOL="shasum -a 256"
else
warn "Neither sha256sum nor shasum found. Skipping checksum verification."
CHECKSUM_TOOL=""
fi
if [[ -n "$CHECKSUM_TOOL" ]]; then
cd "$TMP_DIR"
COMPUTED_CHECKSUM=$($CHECKSUM_TOOL "$DOWNLOAD_FILENAME" | cut -d ' ' -f 1)
EXPECTED_CHECKSUM=$(grep "$DOWNLOAD_FILENAME" checksums.txt | cut -d ' ' -f 1)
if [[ -z "$EXPECTED_CHECKSUM" ]]; then
warn "Checksum for $DOWNLOAD_FILENAME not found in checksums.txt. Skipping verification."
elif [[ "$COMPUTED_CHECKSUM" != "$EXPECTED_CHECKSUM" ]]; then
abort "Checksum verification failed. Expected: $EXPECTED_CHECKSUM, Got: $COMPUTED_CHECKSUM"
else
ohai "Checksum verification passed!"
fi
cd - > /dev/null
fi
fi
fi
ohai "Processing download..."
if [[ "$OS" == "Windows" ]]; then
ohai "Downloaded Windows MSI installer to $TMP_DIR/$DOWNLOAD_FILENAME"
if [[ -n "${CI}" || -n "${GITHUB_ACTIONS}" || -n "${NONINTERACTIVE}" ]]; then
warn "Non-interactive environment detected, skipping automatic MSI installation"
cp "$TMP_DIR/$DOWNLOAD_FILENAME" "$HOME/" || abort "Failed to copy MSI to $HOME/"
ohai "MSI installer copied to $HOME/$DOWNLOAD_FILENAME"
ohai "To install manually, run the MSI installer at:"
echo " $HOME/$DOWNLOAD_FILENAME"
exit 0
fi
ohai "Attempting to run MSI installer automatically..."
if command -v msiexec >/dev/null 2>&1; then
ohai "Running installer with msiexec..."
msiexec /i "$TMP_DIR/$DOWNLOAD_FILENAME" /qn /norestart
INSTALL_STATUS=$?
if [[ $INSTALL_STATUS -eq 0 ]]; then
ohai "Installation completed successfully!"
exit 0
else
warn "Automatic installation failed with status: $INSTALL_STATUS"
fi
else
warn "msiexec not found, cannot run installer automatically"
fi
cp "$TMP_DIR/$DOWNLOAD_FILENAME" "$HOME/" || abort "Failed to copy MSI to $HOME/"
ohai "MSI installer copied to $HOME/$DOWNLOAD_FILENAME"
ohai "To install manually, run the MSI installer at:"
echo " $HOME/$DOWNLOAD_FILENAME"
exit 0
elif [[ "$EXTENSION" == "tar.gz" ]]; then
ohai "Extracting..."
tar -xzf "$TMP_DIR/$DOWNLOAD_FILENAME" -C "$TMP_DIR" || abort "Failed to extract archive"
elif [[ "$EXTENSION" == "zip" ]]; then
ohai "Extracting..."
unzip -q "$TMP_DIR/$DOWNLOAD_FILENAME" -d "$TMP_DIR" || abort "Failed to extract archive"
else
abort "Unknown archive format: $EXTENSION"
fi
ohai "Installing to $INSTALL_PATH..."
if [[ -f "$TMP_DIR/agentuity" ]]; then
if [[ "$OS" == "Darwin" ]] && [[ -f "$INSTALL_PATH/agentuity" ]]; then
ohai "Removing existing binary to avoid macOS quarantine issues..."
rm -f "$INSTALL_PATH/agentuity" || abort "Failed to remove existing binary from $INSTALL_PATH"
fi
cp "$TMP_DIR/agentuity" "$INSTALL_PATH/" || abort "Failed to copy binary to $INSTALL_PATH"
chmod +x "$INSTALL_PATH/agentuity" || abort "Failed to make binary executable"
else
abort "Binary not found in extracted archive"
fi
if command -v "$INSTALL_PATH/agentuity" >/dev/null 2>&1; then
ohai "Successfully installed Agentuity CLI to $INSTALL_PATH/agentuity"
else
abort "Installation verification failed"
fi
if [[ ":$PATH:" != *":$INSTALL_PATH:"* ]]; then
ohai "Adding $INSTALL_PATH to your PATH..."
SHELL_CONFIG=""
case "$SHELL" in
*/bash*)
SHELL_CONFIG="$HOME/.bashrc"
if [[ -f "$HOME/.bash_profile" ]]; then
SHELL_CONFIG="$HOME/.bash_profile"
fi
;;
*/zsh*)
SHELL_CONFIG="$HOME/.zshrc"
;;
*/fish*)
SHELL_CONFIG="$HOME/.config/fish/config.fish"
;;
esac
if [[ -n "$SHELL_CONFIG" ]] && [[ -w "$SHELL_CONFIG" ]]; then
echo "export PATH=\"\$PATH:$INSTALL_PATH\"" >> "$SHELL_CONFIG"
ohai "Added $INSTALL_PATH to PATH in $SHELL_CONFIG"
export PATH="$PATH:$INSTALL_PATH"
else
warn "$INSTALL_PATH is not in your PATH. You may need to add it manually to use the agentuity command."
case "$SHELL" in
*/bash*)
echo " echo 'export PATH=\"\$PATH:$INSTALL_PATH\"' >> ~/.bashrc"
;;
*/zsh*)
echo " echo 'export PATH=\"\$PATH:$INSTALL_PATH\"' >> ~/.zshrc"
;;
*/fish*)
echo " echo 'set -gx PATH \$PATH $INSTALL_PATH' >> ~/.config/fish/config.fish"
;;
*)
echo " Add $INSTALL_PATH to your PATH"
;;
esac
fi
fi
ohai "Setting up shell completions..."
if command -v "$INSTALL_PATH/agentuity" >/dev/null 2>&1; then
COMPLETION_DIR=""
case "$OS" in
"Darwin")
if [[ -d "/usr/local/etc/bash_completion.d" ]]; then
BASH_COMPLETION_DIR="/usr/local/etc/bash_completion.d"
if [[ -w "$BASH_COMPLETION_DIR" ]]; then
ohai "Generating bash completion script..."
"$INSTALL_PATH/agentuity" completion bash > "$BASH_COMPLETION_DIR/agentuity"
ohai "Bash completion installed to $BASH_COMPLETION_DIR/agentuity"
else
warn "No write permission to $BASH_COMPLETION_DIR. Skipping bash completion installation."
fi
fi
if [[ -d "/usr/local/share/zsh/site-functions" ]]; then
ZSH_COMPLETION_DIR="/usr/local/share/zsh/site-functions"
if [[ -w "$ZSH_COMPLETION_DIR" ]]; then
ohai "Generating zsh completion script..."
"$INSTALL_PATH/agentuity" completion zsh > "$ZSH_COMPLETION_DIR/_agentuity"
ohai "Zsh completion installed to $ZSH_COMPLETION_DIR/_agentuity"
else
warn "No write permission to $ZSH_COMPLETION_DIR. Skipping zsh completion installation."
fi
fi
;;
"Linux")
if [[ -d "/etc/bash_completion.d" ]]; then
BASH_COMPLETION_DIR="/etc/bash_completion.d"
if [[ -w "$BASH_COMPLETION_DIR" ]]; then
ohai "Generating bash completion script..."
"$INSTALL_PATH/agentuity" completion bash > "$BASH_COMPLETION_DIR/agentuity"
ohai "Bash completion installed to $BASH_COMPLETION_DIR/agentuity"
else
warn "No write permission to $BASH_COMPLETION_DIR. Skipping bash completion installation."
ohai "You can manually install bash completion with:"
echo " $INSTALL_PATH/agentuity completion bash > ~/.bash_completion"
fi
fi
if [[ -d "/usr/share/zsh/vendor-completions" ]]; then
ZSH_COMPLETION_DIR="/usr/share/zsh/vendor-completions"
if [[ -w "$ZSH_COMPLETION_DIR" ]]; then
ohai "Generating zsh completion script..."
"$INSTALL_PATH/agentuity" completion zsh > "$ZSH_COMPLETION_DIR/_agentuity"
ohai "Zsh completion installed to $ZSH_COMPLETION_DIR/_agentuity"
else
warn "No write permission to $ZSH_COMPLETION_DIR. Skipping zsh completion installation."
ohai "You can manually install zsh completion with:"
echo " mkdir -p ~/.zsh/completion"
echo " $INSTALL_PATH/agentuity completion zsh > ~/.zsh/completion/_agentuity"
echo " echo 'fpath=(~/.zsh/completion \$fpath)' >> ~/.zshrc"
echo " echo 'autoload -U compinit && compinit' >> ~/.zshrc"
fi
fi
;;
"Windows")
ohai "You can manually install PowerShell completion with:"
echo " $INSTALL_PATH/agentuity completion powershell > agentuity.ps1"
echo " Move agentuity.ps1 to a directory in your PowerShell module path"
;;
esac
ohai "To manually set up shell completions, run:"
echo " For bash: $INSTALL_PATH/agentuity completion bash > /path/to/bash_completion.d/agentuity"
echo " For zsh: $INSTALL_PATH/agentuity completion zsh > /path/to/zsh/site-functions/_agentuity"
echo " For fish: $INSTALL_PATH/agentuity completion fish > ~/.config/fish/completions/agentuity.fish"
fi
success