forked from smtg-ai/claude-squad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
320 lines (279 loc) · 10.6 KB
/
install.sh
File metadata and controls
320 lines (279 loc) · 10.6 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
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
#!/usr/bin/env bash
set -e
setup_shell_and_path() {
BIN_DIR=${BIN_DIR:-$HOME/.local/bin}
case $SHELL in
*/zsh)
PROFILE=$HOME/.zshrc
;;
*/bash)
PROFILE=$HOME/.bashrc
;;
*/fish)
PROFILE=$HOME/.config/fish/config.fish
;;
*/ash)
PROFILE=$HOME/.profile
;;
*)
echo "could not detect shell, manually add ${BIN_DIR} to your PATH."
exit 1
esac
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then
echo >> "$PROFILE" && echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$PROFILE"
fi
}
detect_platform_and_arch() {
PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
if [[ "$PLATFORM" == mingw*_nt* ]]; then
PLATFORM="windows"
fi
ARCHITECTURE="$(uname -m)"
if [ "${ARCHITECTURE}" = "x86_64" ]; then
# Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCHITECTURE="arm64" # Rosetta.
else
ARCHITECTURE="amd64" # Intel.
fi
elif [ "${ARCHITECTURE}" = "arm64" ] || [ "${ARCHITECTURE}" = "aarch64" ]; then
ARCHITECTURE="arm64" # Arm.
else
ARCHITECTURE="amd64" # Amd.
fi
if [[ "$PLATFORM" == "windows" ]]; then
ARCHIVE_EXT=".zip"
EXTENSION=".exe"
else
ARCHIVE_EXT=".tar.gz"
EXTENSION=""
fi
}
get_latest_version() {
# Get latest version from GitHub API, including prereleases
API_RESPONSE=$(curl -sS "https://api.github.com/repos/smtg-ai/claude-squad/releases")
if [ $? -ne 0 ]; then
echo "Failed to connect to GitHub API"
exit 1
fi
if echo "$API_RESPONSE" | grep -q "Not Found"; then
echo "No releases found in the repository"
exit 1
fi
# Get the first release (latest) from the array
LATEST_VERSION=$(echo "$API_RESPONSE" | grep -m1 '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/^v//')
if [ -z "$LATEST_VERSION" ]; then
echo "Failed to parse version from GitHub API response:"
echo "$API_RESPONSE" | grep -v "upload_url" # Filter out long upload_url line
exit 1
fi
echo "$LATEST_VERSION"
}
download_release() {
local version=$1
local binary_url=$2
local archive_name=$3
local tmp_dir=$4
echo "Downloading binary from $binary_url"
DOWNLOAD_OUTPUT=$(curl -sS -L -f -w '%{http_code}' "$binary_url" -o "${tmp_dir}/${archive_name}" 2>&1)
HTTP_CODE=$?
if [ $HTTP_CODE -ne 0 ]; then
echo "Error: Failed to download release asset"
echo "This could be because:"
echo "1. The release ${version} doesn't have assets uploaded yet"
echo "2. The asset for ${PLATFORM}_${ARCHITECTURE} wasn't built"
echo "3. The asset name format has changed"
echo ""
echo "Expected asset name: ${archive_name}"
echo "URL attempted: ${binary_url}"
if [ "$version" == "latest" ]; then
echo ""
echo "Tip: Try installing a specific version instead of 'latest'"
echo "Available versions:"
echo "$API_RESPONSE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/^v//'
fi
rm -rf "$tmp_dir"
exit 1
fi
}
extract_and_install() {
local tmp_dir=$1
local archive_name=$2
local bin_dir=$3
local extension=$4
if [[ "$PLATFORM" == "windows" ]]; then
if ! unzip -t "${tmp_dir}/${archive_name}" > /dev/null 2>&1; then
echo "Error: Downloaded file is not a valid zip archive"
rm -rf "$tmp_dir"
exit 1
fi
ensure unzip "${tmp_dir}/${archive_name}" -d "$tmp_dir"
else
if ! tar tzf "${tmp_dir}/${archive_name}" > /dev/null 2>&1; then
echo "Error: Downloaded file is not a valid tar.gz archive"
rm -rf "$tmp_dir"
exit 1
fi
ensure tar xzf "${tmp_dir}/${archive_name}" -C "$tmp_dir"
fi
if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
fi
# Remove existing binary if upgrading
if [ "$UPGRADE_MODE" = true ] && [ -f "$bin_dir/$INSTALL_NAME${extension}" ]; then
echo "Removing previous installation from $bin_dir/$INSTALL_NAME${extension}"
rm -f "$bin_dir/$INSTALL_NAME${extension}"
fi
# Install binary with desired name
mv "${tmp_dir}/claude-squad${extension}" "$bin_dir/$INSTALL_NAME${extension}"
rm -rf "$tmp_dir"
if [ ! -f "$bin_dir/$INSTALL_NAME${extension}" ]; then
echo "Installation failed, could not find $bin_dir/$INSTALL_NAME${extension}"
exit 1
fi
chmod +x "$bin_dir/$INSTALL_NAME${extension}"
echo ""
if [ "$UPGRADE_MODE" = true ]; then
echo "Successfully upgraded '$INSTALL_NAME' to:"
else
echo "Installed as '$INSTALL_NAME':"
fi
echo "$("$bin_dir/$INSTALL_NAME${extension}" version)"
}
check_command_exists() {
if command -v "$INSTALL_NAME" &> /dev/null; then
EXISTING_PATH=$(which "$INSTALL_NAME")
echo "Found existing installation of '$INSTALL_NAME' at $EXISTING_PATH"
echo "Will upgrade to the latest version"
UPGRADE_MODE=true
else
UPGRADE_MODE=false
fi
}
check_and_install_dependencies() {
echo "Checking for required dependencies..."
# Check for tmux
if ! command -v tmux &> /dev/null; then
echo "tmux is not installed. Installing tmux..."
if [[ "$PLATFORM" == "darwin" ]]; then
# macOS
if command -v brew &> /dev/null; then
ensure brew install tmux
else
echo "Homebrew is not installed. Please install Homebrew first to install tmux."
echo "Visit https://brew.sh for installation instructions."
exit 1
fi
elif [[ "$PLATFORM" == "linux" ]]; then
# Linux
if command -v apt-get &> /dev/null; then
ensure sudo apt-get update
ensure sudo apt-get install -y tmux
elif command -v dnf &> /dev/null; then
ensure sudo dnf install -y tmux
elif command -v yum &> /dev/null; then
ensure sudo yum install -y tmux
elif command -v pacman &> /dev/null; then
ensure sudo pacman -S --noconfirm tmux
else
echo "Could not determine package manager. Please install tmux manually."
exit 1
fi
elif [[ "$PLATFORM" == "windows" ]]; then
echo "For Windows, please install tmux via WSL or another method."
exit 1
fi
echo "tmux installed successfully."
else
echo "tmux is already installed."
fi
# Check for GitHub CLI (gh)
if ! command -v gh &> /dev/null; then
echo "GitHub CLI (gh) is not installed. Installing GitHub CLI..."
if [[ "$PLATFORM" == "darwin" ]]; then
# macOS
if command -v brew &> /dev/null; then
ensure brew install gh
else
echo "Homebrew is not installed. Please install Homebrew first to install GitHub CLI."
echo "Visit https://brew.sh for installation instructions."
exit 1
fi
elif [[ "$PLATFORM" == "linux" ]]; then
# Linux
if command -v apt-get &> /dev/null; then
echo "Installing GitHub CLI on Debian/Ubuntu..."
ensure curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
ensure sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
ensure echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
ensure sudo apt-get update
ensure sudo apt-get install -y gh
elif command -v dnf &> /dev/null; then
ensure sudo dnf install -y 'dnf-command(config-manager)'
ensure sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
ensure sudo dnf install -y gh
elif command -v yum &> /dev/null; then
ensure sudo yum install -y yum-utils
ensure sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
ensure sudo yum install -y gh
elif command -v pacman &> /dev/null; then
ensure sudo pacman -S --noconfirm github-cli
else
echo "Could not determine package manager. Please install GitHub CLI manually."
echo "Visit https://github.com/cli/cli#installation for installation instructions."
exit 1
fi
elif [[ "$PLATFORM" == "windows" ]]; then
echo "For Windows, please install GitHub CLI manually."
echo "Visit https://github.com/cli/cli#installation for installation instructions."
exit 1
fi
echo "GitHub CLI (gh) installed successfully."
else
echo "GitHub CLI (gh) is already installed."
fi
echo "All dependencies are installed."
}
main() {
# Parse command line arguments
INSTALL_NAME="cs"
UPGRADE_MODE=false
while [[ $# -gt 0 ]]; do
case $1 in
--name)
INSTALL_NAME="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: install.sh [--name <n>]"
exit 1
;;
esac
done
check_command_exists
detect_platform_and_arch
check_and_install_dependencies
setup_shell_and_path
VERSION=${VERSION:-"latest"}
if [[ "$VERSION" == "latest" ]]; then
VERSION=$(get_latest_version)
fi
RELEASE_URL="https://github.com/smtg-ai/claude-squad/releases/download/v${VERSION}"
ARCHIVE_NAME="claude-squad_${VERSION}_${PLATFORM}_${ARCHITECTURE}${ARCHIVE_EXT}"
BINARY_URL="${RELEASE_URL}/${ARCHIVE_NAME}"
TMP_DIR=$(mktemp -d)
download_release "$VERSION" "$BINARY_URL" "$ARCHIVE_NAME" "$TMP_DIR"
extract_and_install "$TMP_DIR" "$ARCHIVE_NAME" "$BIN_DIR" "$EXTENSION"
}
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
if ! "$@"; then err "command failed: $*"; fi
}
err() {
echo "$1" >&2
exit 1
}
main "$@" || exit 1