-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-from-github.sh
More file actions
executable file
·323 lines (262 loc) · 9.45 KB
/
install-from-github.sh
File metadata and controls
executable file
·323 lines (262 loc) · 9.45 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
#!/bin/bash
# Install Cloudflare WARP CLI directly from GitHub
# Usage: curl -fsSL https://raw.githubusercontent.com/zero8dotdev/warp-cli/main/install-from-github.sh | bash
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'
print_banner() {
cat << 'EOF'
╔════════════════════════════════════════════════════════════╗
║ Cloudflare WARP CLI - GitHub Installer ║
║ Install in 2-3 minutes ║
╚════════════════════════════════════════════════════════════╝
EOF
}
print_step() {
local step=$1
local description=$2
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${CYAN}Step $step:${NC} $description"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
}
# Ask for sudo password upfront
request_sudo() {
if [ "$EUID" -ne 0 ]; then
echo "This installation requires elevated privileges (sudo)."
sudo -v || {
echo -e "${RED}✗ Sudo access denied${NC}"
exit 1
}
fi
}
# Check prerequisites
check_prerequisites() {
print_step "1" "Checking Prerequisites"
# Check for Cloudflare WARP app
if [ ! -d "/Applications/Cloudflare WARP.app" ]; 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 ""
if [ -t 0 ]; then
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..."
brew install --cask cloudflare-warp
if [ -d "/Applications/Cloudflare WARP.app" ]; 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 " curl -fsSL https://raw.githubusercontent.com/zero8dotdev/warp-cli/main/install-from-github.sh | bash"
exit 0
else
echo "Installation cancelled"
exit 0
fi
else
# Non-interactive mode: try Homebrew first, then App Store link
if command -v brew &> /dev/null; then
echo "Installing via Homebrew..."
brew install --cask cloudflare-warp 2>/dev/null || true
fi
if [ ! -d "/Applications/Cloudflare WARP.app" ]; then
echo -e "${RED}✗ Cloudflare WARP not found${NC}"
echo ""
echo "Please install Cloudflare WARP from one of these options:"
echo " 1. Homebrew: brew install --cask cloudflare-warp"
echo " 2. App Store: https://apps.apple.com/app/cloudflare-warp/id1423210915"
echo ""
echo "Then run this command again:"
echo " curl -fsSL https://raw.githubusercontent.com/zero8dotdev/warp-cli/main/install-from-github.sh | bash"
exit 1
fi
fi
fi
echo "✓ Cloudflare WARP app found"
# Check for Rust/Cargo
if ! command -v cargo &> /dev/null; then
echo -e "${YELLOW}⚠ Rust/Cargo not found${NC}"
echo ""
echo "Installing Rust (required for building)..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
source $HOME/.cargo/env
echo "✓ Rust installed"
else
RUST_VERSION=$(rustc --version)
echo "✓ $RUST_VERSION"
fi
# Check for git
if ! command -v git &> /dev/null; then
echo -e "${RED}✗ git not found${NC}"
echo "Please install git: brew install git"
exit 1
fi
echo "✓ git found"
echo ""
}
# Clone and prepare
clone_repo() {
print_step "2" "Downloading from GitHub"
TEMP_DIR=$(mktemp -d)
echo "✓ Using temporary directory: $TEMP_DIR"
cd "$TEMP_DIR"
echo "✓ Cloning repository..."
git clone https://github.com/zero8dotdev/warp-cli.git 2>&1 | grep -E "(Cloning|Resolving)" || true
cd warp-cli
echo "✓ Repository ready"
echo ""
}
# Build
build() {
print_step "3" "Building from Source"
echo "✓ Checking Cargo..."
RUST_VERSION=$(rustc --version)
echo " $RUST_VERSION"
echo ""
echo "✓ Building in release mode..."
echo " (This may take 1-2 minutes on first build...)"
cargo build --release 2>&1 | tail -5
if [ ! -x "target/release/warp" ]; then
echo -e "${RED}✗ Build failed${NC}"
exit 1
fi
BINARY_SIZE=$(du -h target/release/warp | cut -f1)
echo "✓ Build successful ($BINARY_SIZE binary)"
echo ""
}
# Extract binaries
extract_binaries() {
print_step "4" "Setting Up Daemon"
echo "✓ Extracting warp-cli from WARP app..."
bash scripts/extract-warp.sh
echo "✓ Configuring daemon..."
bash scripts/setup-daemon.sh
echo ""
}
# Install
install_binary() {
print_step "5" "Installing warp CLI"
INSTALL_PATH="/usr/local/bin"
echo "✓ Installing to $INSTALL_PATH..."
if [ ! -w "$INSTALL_PATH" ]; then
sudo install -m 755 target/release/warp "$INSTALL_PATH/warp"
else
install -m 755 target/release/warp "$INSTALL_PATH/warp"
fi
echo "✓ Installed to /usr/local/bin/warp"
echo ""
}
# Verify
verify_installation() {
print_step "6" "Verifying Installation"
if ! command -v warp &> /dev/null; then
echo -e "${RED}✗ warp command not found in PATH${NC}"
exit 1
fi
echo "✓ warp command found"
if warp --version > /dev/null 2>&1; then
WARP_VERSION=$(warp --version)
echo "✓ Version: $WARP_VERSION"
fi
if warp status > /dev/null 2>&1; then
echo "✓ CLI is functional"
fi
echo ""
}
# Cleanup
cleanup() {
print_step "7" "Cleaning Up"
echo "✓ Removing temporary files..."
cd /
rm -rf "$TEMP_DIR"
echo "✓ Cleanup complete"
echo ""
}
# Summary
print_summary() {
cat << 'EOF'
╔════════════════════════════════════════════════════════════╗
║ Installation Complete! ✓ ║
╚════════════════════════════════════════════════════════════╝
📦 Installed:
✓ warp CLI tool
✓ warp-cli binary
✓ CloudflareWARP daemon
✓ launchd configuration
🎯 Quick Start:
$ warp status # Check connection status
$ warp up # Connect to WARP
$ warp down # Disconnect from WARP
$ warp --help # Show all commands
📚 Documentation:
https://github.com/zero8dotdev/warp-cli
════════════════════════════════════════════════════════════
EOF
echo "✓ All systems go! Start using: warp status"
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. Ensure Cloudflare WARP is installed from App Store"
echo " 2. Check your internet connection"
echo " 3. Try again: curl -fsSL https://raw.githubusercontent.com/zero8dotdev/warp-cli/main/install-from-github.sh | bash"
echo ""
cleanup
}
# Main
main() {
print_banner
trap 'on_error ${LINENO}' ERR
# Request sudo upfront so password is cached
request_sudo
check_prerequisites
clone_repo
build
extract_binaries
install_binary
verify_installation
cleanup
print_summary
}
# Handle interruption
trap 'echo -e "\n${RED}✗ Installation cancelled${NC}\n"; exit 130' INT
# Run
main "$@"