-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
211 lines (174 loc) · 5.37 KB
/
install.sh
File metadata and controls
211 lines (174 loc) · 5.37 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
#!/bin/bash
# Anvil Installation Script
# This script downloads and installs the latest version of Anvil
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
REPO="0xjuanma/anvil"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="anvil"
# Functions
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Detect architecture
detect_arch() {
local arch=$(uname -m)
case $arch in
x86_64)
echo "amd64"
;;
arm64|aarch64)
echo "arm64"
;;
*)
print_error "Unsupported architecture: $arch"
exit 1
;;
esac
}
# Detect OS
detect_os() {
local os=$(uname -s)
case $os in
Darwin)
echo "darwin"
;;
Linux)
echo "linux"
;;
*)
print_error "Unsupported operating system: $os"
exit 1
;;
esac
}
# Get latest release version
get_latest_version() {
local response=$(curl -s "https://api.github.com/repos/$REPO/releases/latest")
# Check for HTTP errors
local http_code=$(curl -s -o /dev/null -w "%{http_code}" "https://api.github.com/repos/$REPO/releases/latest")
if [ "$http_code" != "200" ]; then
print_error "GitHub API returned HTTP $http_code for repository: $REPO"
print_info "Please verify the repository exists and is accessible"
return 1
fi
# Check if we got an error message from GitHub API
if echo "$response" | grep -q '"message"'; then
local error_msg=$(echo "$response" | grep '"message":' | cut -d'"' -f4)
print_error "GitHub API error: $error_msg"
print_info "Repository: $REPO"
return 1
fi
local tag_name=$(echo "$response" | grep '"tag_name":' | cut -d'"' -f4)
# Check if tag_name is empty
if [ -z "$tag_name" ]; then
print_error "Failed to parse version from GitHub API response"
print_info "Repository: $REPO"
print_info "API response (first 10 lines):"
echo "$response" | head -10
return 1
fi
echo "$tag_name"
}
# Download and install
install_anvil() {
local os=$(detect_os)
local arch=$(detect_arch)
local version
if ! version=$(get_latest_version); then
print_error "Failed to get latest version from GitHub"
print_info "You can manually download from: https://github.com/$REPO/releases"
exit 1
fi
if [ -z "$version" ]; then
print_error "Failed to get latest version"
exit 1
fi
print_status "Installing Anvil $version for $os-$arch"
# Use architecture-specific binaries
local binary_name="anvil-$os-$arch"
local download_url="https://github.com/$REPO/releases/download/$version/$binary_name"
print_status "Downloading from: $download_url"
# Create temporary directory
local tmp_dir=$(mktemp -d)
local tmp_file="$tmp_dir/$BINARY_NAME"
# Download binary
if ! curl -L "$download_url" -o "$tmp_file"; then
print_error "Failed to download Anvil"
rm -rf "$tmp_dir"
exit 1
fi
# Make executable
chmod +x "$tmp_file"
# Test the binary
if ! "$tmp_file" --help > /dev/null 2>&1; then
print_error "Downloaded binary is not working correctly"
rm -rf "$tmp_dir"
exit 1
fi
# Install binary
print_status "Installing to $INSTALL_DIR/$BINARY_NAME"
# Create install directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
print_status "Creating directory $INSTALL_DIR"
if ! sudo mkdir -p "$INSTALL_DIR"; then
print_error "Failed to create directory $INSTALL_DIR"
rm -rf "$tmp_dir"
exit 1
fi
fi
if [ -w "$INSTALL_DIR" ]; then
mv "$tmp_file" "$INSTALL_DIR/$BINARY_NAME"
else
print_status "Need sudo permissions to install to $INSTALL_DIR"
sudo mv "$tmp_file" "$INSTALL_DIR/$BINARY_NAME"
fi
# Cleanup
rm -rf "$tmp_dir"
print_success "Anvil $version installed successfully!"
print_status "Run 'anvil' to verify installation"
print_status "Run 'anvil init' to get started"
}
# Main
main() {
echo ""
echo "🔨 Anvil Installation Script"
echo "================================"
echo ""
# Check dependencies
if ! command -v curl > /dev/null 2>&1; then
print_error "curl is required but not installed"
exit 1
fi
# Check if already installed
if command -v anvil > /dev/null 2>&1; then
local current_version=$(anvil --version 2>/dev/null | head -n1 || echo "unknown")
print_status "Anvil is already installed: $current_version"
print_status "Updating to latest version..."
fi
install_anvil
echo ""
echo "🎉 Installation Complete!"
echo ""
echo "Next steps:"
echo " 1. Run 'anvil init' to initialize your environment"
echo " 2. Run 'anvil doctor' to verify everything is working"
echo " 3. Run 'anvil install --list' to see available tool groups. Create your own groups in settings.yaml."
echo ""
}
main "$@"