-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·250 lines (217 loc) · 7.28 KB
/
install.sh
File metadata and controls
executable file
·250 lines (217 loc) · 7.28 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
#!/usr/bin/env bash
# Weft CLI Installation Script
# Usage: curl -fsSL https://raw.githubusercontent.com/weftlabs/weft-cli/main/install.sh | sh
# Or: wget -qO- https://raw.githubusercontent.com/weftlabs/weft-cli/main/install.sh | sh
# Local test: WEFT_LOCAL_INSTALL=1 bash install.sh
set -e
# Configuration
REPO="weftlabs/weft-cli"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
PYTHON_MIN_VERSION="3.11"
LOCAL_INSTALL="${WEFT_LOCAL_INSTALL:-0}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Helper functions
error() {
echo -e "${RED}Error: $1${NC}" >&2
exit 1
}
info() {
echo -e "${GREEN}$1${NC}"
}
warn() {
echo -e "${YELLOW}$1${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Detect OS and architecture
detect_platform() {
local os arch
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
*) error "Unsupported operating system: $(uname -s)" ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
echo "${os}_${arch}"
}
# Check Python version
check_python() {
if ! command_exists python3; then
error "Python 3 is required but not found. Please install Python ${PYTHON_MIN_VERSION} or higher."
fi
local python_version
python_version=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
if ! python3 -c "import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)"; then
error "Python ${PYTHON_MIN_VERSION}+ is required (found: ${python_version})"
fi
info "✓ Python ${python_version} detected"
}
# Check Docker
check_docker() {
if ! command_exists docker; then
warn "Warning: Docker not found. Weft requires Docker to run agents."
warn "Install Docker from: https://docs.docker.com/get-docker/"
else
info "✓ Docker detected"
fi
}
# Get latest release version
get_latest_version() {
if command_exists curl; then
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | \
grep '"tag_name":' | \
sed -E 's/.*"v?([^"]+)".*/\1/'
elif command_exists wget; then
wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | \
grep '"tag_name":' | \
sed -E 's/.*"v?([^"]+)".*/\1/'
else
error "curl or wget is required"
fi
}
# Install using pip
install_with_pip() {
local version="$1"
local install_cmd="python3"
local install_target
info "Installing Weft ${version} using pip..."
# Check if pip is available via python -m pip
if ! ${install_cmd} -m pip --version >/dev/null 2>&1; then
error "pip is not available. Please install pip first."
fi
# Determine install target
if [ "$LOCAL_INSTALL" = "1" ]; then
# Local development mode - install from current directory
if [ ! -f "pyproject.toml" ]; then
error "LOCAL_INSTALL=1 but pyproject.toml not found. Run from repository root."
fi
install_target="."
info "Installing from local directory (development mode)"
else
# Normal mode - install from GitHub
install_target="git+https://github.com/${REPO}.git@v${version}"
fi
# Install to user directory with explicit flags for PEP 668 compliance
# Try --user first, then --break-system-packages if needed (macOS Homebrew Python)
if ${install_cmd} -m pip install --user --no-warn-script-location "${install_target}" >/tmp/weft-install.log 2>&1; then
info "✓ Weft installed successfully"
elif grep -q "externally-managed-environment" /tmp/weft-install.log; then
# Homebrew Python requires --break-system-packages even with --user
warn "Detected externally-managed Python, using --break-system-packages..."
if ${install_cmd} -m pip install --user --break-system-packages --no-warn-script-location "${install_target}" >/tmp/weft-install.log 2>&1; then
info "✓ Weft installed successfully"
else
cat /tmp/weft-install.log
error "Failed to install Weft. See output above for details."
fi
else
cat /tmp/weft-install.log
error "Failed to install Weft. See output above for details."
fi
}
# Verify installation
verify_installation() {
# Check common locations for the weft binary
local paths=(
"$HOME/.local/bin"
"$HOME/Library/Python/*/bin"
"/usr/local/bin"
)
local weft_path=""
for path in "${paths[@]}"; do
# Expand glob patterns
for expanded_path in $path; do
if [ -f "$expanded_path/weft" ]; then
weft_path="$expanded_path"
break 2
fi
done
done
if [ -z "$weft_path" ]; then
warn "Warning: weft binary not found in expected locations"
warn "You may need to add Python's bin directory to your PATH"
return 1
fi
# Test the installation
if "$weft_path/weft" --version >/dev/null 2>&1; then
info "✓ Installation verified: $weft_path/weft"
# Check if directory is in PATH
if ! echo "$PATH" | grep -q "$weft_path"; then
warn ""
warn "Add to PATH by adding this to your shell profile (~/.bashrc or ~/.zshrc):"
echo " export PATH=\"$weft_path:\$PATH\""
warn ""
fi
return 0
else
warn "Warning: weft binary found but not working correctly"
return 1
fi
}
# Main installation
main() {
info "====================================="
info " Weft CLI Installation Script"
info "====================================="
echo ""
# Pre-flight checks
info "Checking prerequisites..."
check_python
check_docker
echo ""
# Get version
if [ "$LOCAL_INSTALL" = "1" ]; then
info "Local install mode enabled"
VERSION="dev"
else
info "Fetching latest version..."
VERSION=$(get_latest_version)
if [ -z "$VERSION" ]; then
VERSION="0.1.0"
warn "Could not fetch latest version, using v${VERSION}"
else
info "Latest version: v${VERSION}"
fi
fi
echo ""
# Install
install_with_pip "$VERSION"
echo ""
# Verify
info "Verifying installation..."
if verify_installation; then
info ""
info "====================================="
info " Installation Complete!"
info "====================================="
info ""
info "Next steps:"
info " 1. Set your Claude API key:"
info " export ANTHROPIC_API_KEY=sk-ant-api03-..."
info ""
info " 2. Initialize a project:"
info " cd your-project && weft init"
info ""
info " 3. Read the documentation:"
info " https://github.com/${REPO}/tree/main/docs"
info ""
else
warn ""
warn "Installation completed but verification failed."
warn "Please check your PATH configuration or install using:"
warn " pip3 install --user git+https://github.com/${REPO}.git"
warn ""
fi
}
# Run main installation
main "$@"