-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·198 lines (162 loc) · 4.88 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·198 lines (162 loc) · 4.88 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
#!/bin/bash
set -e
REPO="rodd-oss/aist"
AIST_INSTALL="$HOME/.aist"
BIN_DIR="$AIST_INSTALL/bin"
CLI_NAME="aist"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Print functions
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Detect OS and architecture
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux)
PLATFORM="linux"
;;
darwin)
PLATFORM="osx"
;;
*)
print_error "Unsupported operating system: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64)
ARCH="x64"
;;
arm64|aarch64)
ARCH="arm64"
;;
*)
print_error "Unsupported architecture: $ARCH"
exit 1
;;
esac
RUNTIME="${PLATFORM}-${ARCH}"
print_info "Detected platform: $RUNTIME"
}
# Get latest release version
get_latest_version() {
print_info "Fetching latest release..."
LATEST_URL=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_URL" ]; then
print_error "Failed to fetch latest release"
exit 1
fi
VERSION="$LATEST_URL"
print_info "Latest version: $VERSION"
}
# Download and install
download_and_install() {
local version=$1
local runtime=$2
# Remove 'v' prefix if present for URL
local version_no_v="${version#v}"
FILENAME="${CLI_NAME}-${runtime}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${version}/${FILENAME}"
TEMP_DIR=$(mktemp -d)
print_info "Downloading ${CLI_NAME} ${version} for ${runtime}..."
if ! curl -sL "$DOWNLOAD_URL" -o "${TEMP_DIR}/${FILENAME}"; then
print_error "Failed to download from: $DOWNLOAD_URL"
rm -rf "$TEMP_DIR"
exit 1
fi
print_info "Extracting..."
tar -xzf "${TEMP_DIR}/${FILENAME}" -C "$TEMP_DIR"
if [ ! -f "${TEMP_DIR}/${CLI_NAME}" ]; then
print_error "Binary not found in archive"
rm -rf "$TEMP_DIR"
exit 1
fi
chmod +x "${TEMP_DIR}/${CLI_NAME}"
# Ensure install directory exists
mkdir -p "$BIN_DIR"
# Install to bin directory
mv "${TEMP_DIR}/${CLI_NAME}" "$BIN_DIR/"
rm -rf "$TEMP_DIR"
print_info "${CLI_NAME} ${version} installed successfully to $BIN_DIR"
}
# Update shell configuration
update_shell_config() {
local shell_name=$(basename "$SHELL")
local config_file=""
local export_cmd="export AIST_INSTALL=\"$AIST_INSTALL\""
local path_cmd="export PATH=\"\$AIST_INSTALL/bin:\$PATH\""
case "$shell_name" in
bash)
if [ -f "$HOME/.bashrc" ]; then
config_file="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
config_file="$HOME/.bash_profile"
fi
;;
zsh)
config_file="$HOME/.zshrc"
;;
fish)
config_file="$HOME/.config/fish/config.fish"
export_cmd="set -gx AIST_INSTALL \"$AIST_INSTALL\""
path_cmd="set -gx PATH \"\$AIST_INSTALL/bin\" \$PATH"
;;
esac
if [ -n "$config_file" ]; then
# Ensure the directory exists
mkdir -p "$(dirname "$config_file")"
# Create file if it doesn't exist
touch "$config_file"
if ! grep -q "AIST_INSTALL" "$config_file" 2>/dev/null; then
print_info "Adding AIST_INSTALL to $config_file..."
echo -e "\n# aist" >> "$config_file"
echo "$export_cmd" >> "$config_file"
echo "$path_cmd" >> "$config_file"
print_info "Please restart your terminal or run: source $config_file"
fi
else
print_warning "Could not automatically update shell config. Please add the following to your shell profile:"
echo " $export_cmd"
echo " $path_cmd"
fi
}
# Verify installation
verify_installation() {
local binary="$BIN_DIR/$CLI_NAME"
if [ -f "$binary" ]; then
print_info "Installation verified at $binary"
"$binary" --version 2>/dev/null || print_warning "Could not get version"
else
print_error "Installation failed - binary not found in $BIN_DIR"
exit 1
fi
}
# Main
main() {
print_info "Installing ${CLI_NAME} CLI..."
# Allow custom version via argument
if [ $# -ge 1 ]; then
VERSION="$1"
print_info "Using specified version: $VERSION"
else
get_latest_version
fi
detect_platform
download_and_install "$VERSION" "$RUNTIME"
update_shell_config
verify_installation
print_info "Installation complete! Run '${CLI_NAME} --help' to get started."
}
main "$@"