-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·251 lines (208 loc) · 6.5 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·251 lines (208 loc) · 6.5 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
#!/bin/bash
set -e
# Arc CLI Installation Script
# This script detects your OS and architecture and installs the appropriate version
VERSION="${VERSION:-latest}"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
GITHUB_REPO="arc-framework/arc-cli"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Emojis
CHECK_MARK="✅"
CROSS_MARK="❌"
ROCKET="🚀"
PACKAGE="📦"
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}" >&2
}
print_success() {
echo -e "${GREEN}${CHECK_MARK} $1${NC}" >&2
}
print_error() {
echo -e "${RED}${CROSS_MARK} $1${NC}" >&2
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}" >&2
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Darwin*)
echo "darwin"
;;
Linux*)
echo "linux"
;;
MINGW*|MSYS*|CYGWIN*)
echo "windows"
;;
*)
print_error "Unsupported operating system: $(uname -s)"
exit 1
;;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64)
echo "amd64"
;;
arm64|aarch64)
echo "arm64"
;;
*)
print_error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
}
# Get latest release tag
get_latest_release() {
if [ "$VERSION" = "latest" ]; then
# Try to get the latest non-feature release
local latest=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# If no latest release, get the most recent release (including pre-releases)
if [ -z "$latest" ] || [ "$latest" = "null" ]; then
latest=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases" | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/')
fi
echo "$latest"
else
echo "$VERSION"
fi
}
# Try to find and download the correct asset
# This function tries multiple naming patterns until one succeeds
download_asset() {
local os=$1
local arch=$2
local version=$3
local tmp_dir=$4
# Determine file extension
local extension="tar.gz"
if [ "$os" = "windows" ]; then
extension="zip"
fi
# Try common naming patterns for GoReleaser
local patterns=(
"arc-cli_${os}_${arch}.${extension}"
"arc-cli_${os}_${arch}_v8.0.${extension}"
"arc-cli_${os}_${arch}_v1.${extension}"
"arc_${os}_${arch}.${extension}"
)
for filename in "${patterns[@]}"; do
local download_url="https://github.com/${GITHUB_REPO}/releases/download/${version}/${filename}"
print_info "Trying: $filename"
# Try to download
if curl -fsSL "$download_url" -o "${tmp_dir}/${filename}" 2>/dev/null; then
print_success "Downloaded: $filename"
echo "$filename" # This is the ONLY echo that goes to stdout
return 0
fi
done
return 1
}
# Download and install
install_arc() {
local os=$1
local arch=$2
local version=$3
print_info "Installing Arc CLI..."
print_info "OS: $os"
print_info "Architecture: $arch"
print_info "Version: $version"
# Create temp directory
local tmp_dir=$(mktemp -d)
# Try to download the asset
local filename=$(download_asset "$os" "$arch" "$version" "$tmp_dir")
local download_status=$?
if [ $download_status -ne 0 ] || [ -z "$filename" ]; then
print_error "Failed to download Arc CLI"
print_info "Please check available releases at:"
print_info "https://github.com/${GITHUB_REPO}/releases/tag/${version}"
rm -rf "$tmp_dir"
exit 1
fi
cd "$tmp_dir"
# Determine file extension for extraction
local extension="${filename##*.}"
if [[ "$filename" == *.tar.gz ]]; then
extension="tar.gz"
fi
# Extract
print_info "Extracting..."
if [ "$extension" = "tar.gz" ]; then
tar -xzf "$filename"
else
unzip -q "$filename"
fi
# Find the binary
local binary_path=$(find . -name "arc" -o -name "arc.exe" | head -n 1)
if [ -z "$binary_path" ]; then
print_error "Binary not found in archive"
rm -rf "$tmp_dir"
exit 1
fi
# Install
print_info "Installing to $INSTALL_DIR..."
# Check if we need sudo
if [ ! -w "$INSTALL_DIR" ]; then
print_warning "Need sudo to install to $INSTALL_DIR"
sudo mkdir -p "$INSTALL_DIR"
sudo cp "$binary_path" "$INSTALL_DIR/arc"
sudo chmod +x "$INSTALL_DIR/arc"
else
mkdir -p "$INSTALL_DIR"
cp "$binary_path" "$INSTALL_DIR/arc"
chmod +x "$INSTALL_DIR/arc"
fi
# Cleanup
cd - > /dev/null
rm -rf "$tmp_dir"
print_success "Arc CLI installed successfully!"
# Verify installation
if command -v arc &> /dev/null; then
print_success "Verification: arc is now available in your PATH"
echo -e "\n${ROCKET} ${GREEN}Get started by running:${NC}" >&2
echo -e " ${BLUE}arc help${NC}\n" >&2
arc version 2>/dev/null || true
else
print_warning "arc is installed but not in your PATH"
print_info "Add $INSTALL_DIR to your PATH:"
echo -e "\n export PATH=\"\$PATH:$INSTALL_DIR\"\n" >&2
print_info "Add this to your ~/.bashrc, ~/.zshrc, or ~/.profile to make it permanent"
fi
}
# Main
main() {
echo -e "\n${BLUE}${PACKAGE} Arc CLI Installer${NC}\n" >&2
local os=$(detect_os)
local arch=$(detect_arch)
# On macOS, prefer Homebrew if available
if [ "$os" = "darwin" ] && command -v brew &> /dev/null; then
print_info "Homebrew detected — using brew for installation"
brew tap arc-framework/tap 2>/dev/null || true
brew install arc-framework/tap/arc
print_success "Arc CLI installed via Homebrew!"
echo -e "\n${ROCKET} ${GREEN}Get started by running:${NC}" >&2
echo -e " ${BLUE}arc help${NC}\n" >&2
exit 0
fi
# Check for curl (required for non-brew installs)
if ! command -v curl &> /dev/null; then
print_error "curl is required but not installed"
exit 1
fi
local version=$(get_latest_release)
if [ -z "$version" ] || [ "$version" = "null" ]; then
print_error "Could not determine version to install"
print_info "Try specifying a version: VERSION=v0.1.0 curl -sSL ... | bash"
exit 1
fi
install_arc "$os" "$arch" "$version"
}
main "$@"