|
1 | | -#!/bin/bash |
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
2 | 3 |
|
3 | | -# Function to print error messages in red |
4 | | -error() { |
5 | | - echo -e "\033[0;31merror:\033[0m $1" >&2 |
6 | | - exit 1 |
7 | | -} |
| 4 | +# [Initialize color codes and helper functions as in bun.sh] |
8 | 5 |
|
9 | | -# Function to print information in dim color |
10 | | -info() { |
11 | | - echo -e "\033[0;2m$1\033[0m" |
12 | | -} |
| 6 | +# Check for bun |
| 7 | +command -v bun >/dev/null || |
| 8 | + error 'bun is required to run aitdd. Please install bun first.' |
13 | 9 |
|
14 | | -# Function to install bun |
15 | | -install_bun() { |
16 | | - info "Installing bun..." |
17 | | - curl -fsSL https://bun.sh/install | bash |
18 | | -} |
| 10 | +# Define the GitHub repository URL |
| 11 | +github_repo="https://github.com/di-sukharev/AI-TDD" |
19 | 12 |
|
20 | | -# Check for bun and install if not present |
21 | | -if ! command -v bun &> /dev/null; then |
22 | | - install_bun |
23 | | -else |
24 | | - info "bun is already installed. Good. Continue." |
25 | | -fi |
| 13 | +# Construct the download URL for your CLI |
| 14 | +# Modify this URL to point to the specific release or directory containing cli.ts |
| 15 | +aitdd_uri="$github_repo/releases/latest/download/out.zip" |
26 | 16 |
|
27 | | -# Define installation directory |
28 | | -BIN_DIR="$HOME/.local/bin" |
29 | | -mkdir -p "$BIN_DIR" |
| 17 | +# Define the installation directory |
| 18 | +install_dir=${HOME}/.aitdd |
| 19 | +bin_dir=$install_dir/bin |
| 20 | +exe=$bin_dir/aitdd |
30 | 21 |
|
31 | | -# Create a symbolic link to the CLI tool |
32 | | -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) |
33 | | -CLI_FILE="$SCRIPT_DIR/cli.ts" |
34 | | -ln -sf "$CLI_FILE" "$BIN_DIR/aitdd" |
| 22 | +# Create the installation directory if it doesn't exist |
| 23 | +mkdir -p "$bin_dir" || |
| 24 | + error "Failed to create install directory \"$bin_dir\"" |
35 | 25 |
|
36 | | -# Detect the shell and update the corresponding configuration file |
37 | | -SHELL_NAME=$(basename "$SHELL") |
38 | | -case "$SHELL_NAME" in |
39 | | - bash) |
40 | | - SHELL_CONFIG="$HOME/.bashrc" |
41 | | - ;; |
42 | | - zsh) |
43 | | - SHELL_CONFIG="$HOME/.zshrc" |
44 | | - ;; |
45 | | - fish) |
46 | | - SHELL_CONFIG="$HOME/.config/fish/config.fish" |
47 | | - ;; |
48 | | - *) |
49 | | - SHELL_CONFIG="" |
50 | | - ;; |
51 | | -esac |
| 26 | +# Download and extract your CLI files |
| 27 | +curl --fail --location --output "$exe.zip" "$aitdd_uri" || |
| 28 | + error "Failed to download aitdd from \"$aitdd_uri\"" |
52 | 29 |
|
53 | | -# Update PATH in the user's shell configuration file |
54 | | -if [[ -n $SHELL_CONFIG && -w $SHELL_CONFIG ]]; then |
55 | | - if ! grep -q "$BIN_DIR" "$SHELL_CONFIG"; then |
56 | | - if [[ "$SHELL_NAME" == "fish" ]]; then |
57 | | - echo "set -gx PATH \"$BIN_DIR\" \$PATH" >> "$SHELL_CONFIG" |
58 | | - else |
59 | | - echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$SHELL_CONFIG" |
60 | | - fi |
61 | | - info "Added $BIN_DIR to PATH in $SHELL_CONFIG" |
62 | | - fi |
63 | | -else |
64 | | - info "Could not update PATH automatically. Please add $BIN_DIR to your PATH manually." |
65 | | -fi |
| 30 | +unzip -oqd "$install_dir" "$exe.zip" || |
| 31 | + error 'Failed to extract aitdd' |
66 | 32 |
|
67 | | -# Refresh environment (this won't affect the parent shell) |
68 | | -export PATH="$BIN_DIR:$PATH" |
| 33 | +# Create the aitdd wrapper command |
| 34 | +cat <<EOF >"$exe" |
| 35 | +#!/usr/bin/env bash |
| 36 | +set -euo pipefail |
| 37 | +bun $install_dir/src/cli.ts "\$@" |
| 38 | +EOF |
69 | 39 |
|
70 | | -# Check if the tool is available in the PATH |
71 | | -if command -v aitdd &> /dev/null; then |
72 | | - info "aitdd tool installed successfully and is available in your PATH." |
73 | | -else |
74 | | - info "Installation complete, but the aitdd tool is not in your PATH. Please restart your shell or source your shell configuration file." |
75 | | -fi |
| 40 | +# Make the wrapper executable |
| 41 | +chmod +x "$exe" || |
| 42 | + error 'Failed to set permissions on aitdd executable' |
| 43 | + |
| 44 | +# [Optional: Provide instructions for adding $bin_dir to PATH] |
| 45 | + |
| 46 | +# Success message |
| 47 | +success "aitdd was installed successfully" |
0 commit comments