-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-complete.sh
More file actions
executable file
·345 lines (284 loc) · 10.4 KB
/
install-complete.sh
File metadata and controls
executable file
·345 lines (284 loc) · 10.4 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/bin/bash
# install-complete.sh
# Complete smart installation for Cloudflare WARP CLI tool
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS_DIR="$SCRIPT_DIR/scripts"
# Configuration
WARP_APP_PATH="/Applications/Cloudflare WARP.app"
INSTALL_PATH="/usr/local/bin"
print_banner() {
cat << 'EOF'
╔══════════════════════════════════════════════════════════════════════════╗
║ ║
║ Cloudflare WARP CLI - Complete Installation ║
║ ║
║ One Command. Complete Setup. ║
║ ║
╚══════════════════════════════════════════════════════════════════════════╝
EOF
}
print_step() {
local step=$1
local description=$2
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${CYAN}Step $step:${NC} $description"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
}
# Step 1: Detect current state
step_detect() {
print_step "1" "Detecting System State"
if [ ! -x "$SCRIPTS_DIR/detect-installation.sh" ]; then
echo -e "${RED}✗ Error: detect-installation.sh not found${NC}"
exit 1
fi
# Run detection
bash "$SCRIPTS_DIR/detect-installation.sh" human
# Store result
DETECT_EXIT=$?
return $DETECT_EXIT
}
# Step 2: Extract binaries
step_extract() {
print_step "2" "Extracting Cloudflare Binaries"
if [ ! -d "$WARP_APP_PATH" ]; then
echo -e "${YELLOW}⚠ Cloudflare WARP app not found${NC}"
echo ""
echo "We need to install Cloudflare WARP first."
echo ""
echo "Choose installation method:"
echo " 1) Homebrew (recommended, fastest)"
echo " 2) App Store"
echo " 3) Cancel"
echo ""
read -p "Enter choice (1-3): " -n 1 -r
echo
if [[ $REPLY == "1" ]]; then
echo "Installing via Homebrew..."
echo ""
# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
echo -e "${RED}✗ Homebrew not found${NC}"
echo ""
echo "Install Homebrew first:"
echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
echo ""
exit 1
fi
# Install cloudflare-warp via Homebrew
echo "Installing cloudflare-warp via Homebrew..."
brew install --cask cloudflare-warp
if [ -d "$WARP_APP_PATH" ]; then
echo ""
echo -e "${GREEN}✓ Cloudflare WARP installed successfully!${NC}"
echo ""
else
echo -e "${RED}✗ Installation failed${NC}"
exit 1
fi
elif [[ $REPLY == "2" ]]; then
echo "Opening App Store..."
open "macappstore://apps.apple.com/app/cloudflare-warp/id1423210915"
echo ""
echo "After installing Cloudflare WARP, run this command again:"
echo " ./install-complete.sh"
exit 0
else
echo "Installation cancelled"
exit 0
fi
fi
if [ ! -x "$SCRIPTS_DIR/extract-warp.sh" ]; then
echo -e "${RED}✗ Error: extract-warp.sh not found${NC}"
exit 1
fi
bash "$SCRIPTS_DIR/extract-warp.sh"
}
# Step 3: Setup daemon
step_setup_daemon() {
print_step "3" "Setting Up Daemon"
if [ ! -x "$SCRIPTS_DIR/setup-daemon.sh" ]; then
echo -e "${RED}✗ Error: setup-daemon.sh not found${NC}"
exit 1
fi
bash "$SCRIPTS_DIR/setup-daemon.sh"
}
# Step 4: Build CLI tool
step_build_cli() {
print_step "4" "Building warp CLI Tool"
echo "✓ Checking Rust toolchain..."
if ! command -v cargo &> /dev/null; then
echo -e "${RED}✗ Error: Rust/Cargo not found${NC}"
echo ""
echo "Install Rust from: https://rustup.rs/"
echo ""
exit 1
fi
RUST_VERSION=$(rustc --version)
echo " $RUST_VERSION"
echo ""
echo "✓ Building in release mode..."
echo " (This may take a minute on first build...)"
cd "$SCRIPT_DIR"
if cargo build --release 2>&1 | grep -E "(Compiling|Finished)"; then
echo ""
echo "✓ Build successful"
else
echo -e "${RED}✗ Build failed${NC}"
exit 1
fi
# Verify binary
if [ ! -x "$SCRIPT_DIR/target/release/warp" ]; then
echo -e "${RED}✗ Binary not found after build${NC}"
exit 1
fi
BINARY_SIZE=$(du -h "$SCRIPT_DIR/target/release/warp" | cut -f1)
echo " Binary: $BINARY_SIZE at target/release/warp"
echo ""
}
# Step 5: Install CLI tool
step_install_cli() {
print_step "5" "Installing warp CLI"
echo "✓ Installing to /usr/local/bin..."
if [ ! -w "$INSTALL_PATH" ]; then
echo " → Requires sudo (elevated privileges)"
sudo install -m 755 "$SCRIPT_DIR/target/release/warp" "$INSTALL_PATH/warp" || {
echo -e "${RED}✗ Installation failed${NC}"
exit 1
}
else
install -m 755 "$SCRIPT_DIR/target/release/warp" "$INSTALL_PATH/warp" || {
echo -e "${RED}✗ Installation failed${NC}"
exit 1
}
fi
echo " ✓ Installed to /usr/local/bin/warp"
echo ""
}
# Step 6: Verify installation
step_verify() {
print_step "6" "Verifying Installation"
ERRORS=0
# Check warp binary
echo "✓ Checking warp CLI..."
if command -v warp &> /dev/null; then
WARP_VERSION=$(warp --version 2>/dev/null || echo "1.0.0")
echo " ✓ warp: $WARP_VERSION"
else
echo -e " ${RED}✗ warp not in PATH${NC}"
ERRORS=$((ERRORS + 1))
fi
# Check warp-cli
echo "✓ Checking warp-cli..."
if command -v warp-cli &> /dev/null; then
CLI_VERSION=$(warp-cli --version 2>/dev/null | head -1 || echo "unknown")
echo " ✓ warp-cli: $CLI_VERSION"
else
echo -e " ${RED}✗ warp-cli not found${NC}"
ERRORS=$((ERRORS + 1))
fi
# Check daemon
echo "✓ Checking daemon..."
if pgrep -x "CloudflareWARP" > /dev/null; then
DAEMON_PID=$(pgrep -x "CloudflareWARP")
echo " ✓ Daemon running (PID: $DAEMON_PID)"
else
echo -e " ${YELLOW}⚠ Daemon not running (may start shortly)${NC}"
fi
# Test CLI
echo "✓ Testing warp CLI..."
if warp status > /dev/null 2>&1; then
STATUS=$(warp status 2>&1 | head -1)
echo " ✓ CLI functional: $STATUS"
else
echo -e " ${YELLOW}⚠ CLI test output received${NC}"
fi
echo ""
if [ $ERRORS -gt 0 ]; then
echo -e "${RED}✗ Verification failed with $ERRORS error(s)${NC}"
exit 1
fi
return 0
}
# Final summary
print_summary() {
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Installation Complete! ✓ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
echo "📦 Components Installed:"
echo " ✓ warp CLI tool"
echo " ✓ warp-cli binary"
echo " ✓ CloudflareWARP daemon"
echo " ✓ launchd configuration"
echo ""
echo "🎯 Quick Start:"
echo " $ warp status # Check connection status"
echo " $ warp up # Connect to WARP"
echo " $ warp down # Disconnect from WARP"
echo " $ warp --help # Show all commands"
echo ""
echo "📚 Documentation:"
echo " $ cat README.md # Project overview"
echo " $ cat INSTALLATION.md # Installation details"
echo " $ cat USAGE_EXAMPLES.md # Command examples"
echo ""
echo "🔧 Advanced:"
echo " $ warp exclude list # Manage split tunnel"
echo " $ warp daemon status # Check daemon"
echo " $ warp logs # View daemon logs"
echo ""
echo "════════════════════════════════════════════════════════════"
echo ""
}
# Error handler
on_error() {
local line_number=$1
echo ""
echo -e "${RED}✗ Installation failed at line $line_number${NC}"
echo ""
echo "Troubleshooting:"
echo " 1. Check prerequisites: bash ./scripts/detect-installation.sh"
echo " 2. Ensure Cloudflare WARP is installed from App Store"
echo " 3. Run with verbose output: bash -x ./install-complete.sh"
echo ""
}
# Main execution
main() {
print_banner
trap 'on_error ${LINENO}' ERR
# Run all steps
step_detect || {
DETECT_EXIT=$?
if [ $DETECT_EXIT -eq 0 ]; then
echo -e "${GREEN}✓ System is ready${NC}"
elif [ $DETECT_EXIT -eq 1 ]; then
echo -e "${YELLOW}⚠ Cloudflare WARP app detected, will extract binaries${NC}"
else
echo -e "${RED}✗ Prerequisites not met${NC}"
exit 1
fi
}
step_extract
step_setup_daemon
step_build_cli
step_install_cli
step_verify
print_summary
echo "✓ All systems go! Start using: warp status"
echo ""
}
# Handle interruption
trap 'echo -e "\n${RED}✗ Installation cancelled${NC}"; exit 130' INT
# Run main
main "$@"