-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
467 lines (427 loc) Β· 17.2 KB
/
Copy pathMakefile
File metadata and controls
467 lines (427 loc) Β· 17.2 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# TrinityProxy Makefile
# Easy build and deployment for SOCKS5 proxy network
.PHONY: help build clean install deps test run-controller run-agent setup-dev check-deps format lint setup-system vps-setup setup-api-controller quickstart debug cleanup install-service start-service stop-service
# Default target
all: deps build
# Help target - shows available commands
help:
@echo "TrinityProxy Build System"
@echo "========================="
@echo ""
@echo "π SIMPLE COMMANDS (for users):"
@echo " make run-controller - Start as API controller (auto-installs nginx/SSL if needed)"
@echo " make run-agent - Complete agent setup (installs service, starts in background)"
@echo " make run - Interactive role selection"
@echo ""
@echo "π Available targets:"
@echo ""
@echo "Quick Setup:"
@echo " make quickstart - Standard setup (after system dependencies)"
@echo " make vps-setup - Complete VPS setup for CONTROLLER"
@echo " make agent-setup - Complete VPS setup for AGENT"
@echo " make setup-system - Install system dependencies (Go, Dante, etc.)"
@echo ""
@echo "Build & Dependencies:"
@echo " make all - Install dependencies and build everything"
@echo " make build - Build all binaries"
@echo " make deps - Install Go dependencies"
@echo " make install - Install system dependencies (requires sudo)"
@echo " make clean - Clean build artifacts"
@echo ""
@echo "Development:"
@echo " make setup-dev - Complete development setup"
@echo " make test - Run tests"
@echo " make format - Format Go code"
@echo " make lint - Run linter"
@echo " make check-deps - Check system dependencies"
@echo ""
@echo "VPS Deployment:"
@echo " make setup-api-controller - Setup controller with SSL/NGINX"
@echo " make install-service - Install controller as systemd service"
@echo " make install-agent-service - Install agent as systemd service"
@echo " make start-service - Start systemd controller service"
@echo " make stop-service - Stop systemd controller service"
@echo " make start-agent-service - Start systemd agent service"
@echo " make stop-agent-service - Stop systemd agent service"
@echo " make deploy-vps - Deploy to VPS (set VPS_HOST variable)"
@echo " make install-dante - Install Dante SOCKS5 server only"
@echo " make cleanup - Remove old TrinityProxy installation"
# Variables
BINARY_NAME=trinityproxy
BUILD_DIR=build
GO_FILES=$(shell find . -name "*.go" -type f)
INSTALLER_BINARY=$(BUILD_DIR)/installer
API_BINARY=$(BUILD_DIR)/api
# Go build flags
LDFLAGS=-ldflags "-X main.Version=$(shell export PATH="/usr/local/go/bin:$$PATH"; git describe --tags --always --dirty 2>/dev/null || echo 'dev')"
# Build all binaries
build: $(BUILD_DIR)/$(BINARY_NAME) $(INSTALLER_BINARY) $(API_BINARY)
@echo "[+] Build complete!"
@echo "[*] Main binary: $(BUILD_DIR)/$(BINARY_NAME)"
@echo "[*] Installer: $(INSTALLER_BINARY)"
@echo "[*] API Server: $(API_BINARY)"
# Build main binary
$(BUILD_DIR)/$(BINARY_NAME): $(GO_FILES) | $(BUILD_DIR)
@echo "[*] Building main binary..."
@export PATH="/usr/local/go/bin:$$PATH"; go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
# Build installer binary
$(INSTALLER_BINARY): cmd/installer/installer.go | $(BUILD_DIR)
@echo "[*] Building installer..."
@export PATH="/usr/local/go/bin:$$PATH"; go build $(LDFLAGS) -o $(INSTALLER_BINARY) ./cmd/installer
# Build API server binary
$(API_BINARY): cmd/api/enhanced_main.go | $(BUILD_DIR)
@echo "[*] Building API server..."
@export PATH="/usr/local/go/bin:$$PATH"; go build $(LDFLAGS) -o $(API_BINARY) ./cmd/api
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Install Go dependencies
deps:
@echo "[*] Installing Go dependencies..."
@export PATH="/usr/local/go/bin:$$PATH"; go mod download
@export PATH="/usr/local/go/bin:$$PATH"; go mod tidy
@echo "[+] Dependencies installed!"
# Install system dependencies (Ubuntu/Debian)
install-dante:
@echo "[*] Installing Dante SOCKS5 server..."
@if command -v apt-get >/dev/null 2>&1; then \
sudo apt-get update && sudo apt-get install -y dante-server; \
elif command -v yum >/dev/null 2>&1; then \
sudo yum install -y dante-server; \
elif command -v dnf >/dev/null 2>&1; then \
sudo dnf install -y dante-server; \
elif command -v pacman >/dev/null 2>&1; then \
sudo pacman -S --noconfirm dante; \
else \
echo "[-] Unsupported package manager. Please install dante-server manually."; \
exit 1; \
fi
@echo "[+] Dante SOCKS5 server installed!"
# Complete system installation
install: install-dante
@echo "[*] Installing SQLite..."
@if command -v apt-get >/dev/null 2>&1; then \
sudo apt-get install -y sqlite3; \
elif command -v yum >/dev/null 2>&1; then \
sudo yum install -y sqlite; \
elif command -v dnf >/dev/null 2>&1; then \
sudo dnf install -y sqlite; \
elif command -v pacman >/dev/null 2>&1; then \
sudo pacman -S --noconfirm sqlite; \
fi
@echo "[+] System dependencies installed!"
# Check if required dependencies are available
check-deps:
@echo "[*] Checking dependencies..."
@export PATH="/usr/local/go/bin:$$PATH"; \
if command -v go >/dev/null 2>&1; then \
echo "[+] Go found: $$(go version)"; \
else \
echo "[-] Go is not installed!"; \
exit 1; \
fi
@command -v git >/dev/null 2>&1 || (echo "[-] Git is not installed!" && exit 1)
@command -v sqlite3 >/dev/null 2>&1 || echo "[!] SQLite3 not found - run 'make install'"
@command -v sockd >/dev/null 2>&1 || echo "[!] Dante server not found - run 'make install-dante'"
@echo "[+] Dependency check complete!"
# Development setup
setup-dev: deps build check-deps
@echo "[+] Development environment ready!"
@echo "[*] Run 'make run' to start TrinityProxy"
# Run tests
test:
@echo "[*] Running tests..."
@export PATH="/usr/local/go/bin:$$PATH"; go test -v ./...
# Format Go code
format:
@echo "[*] Formatting Go code..."
@export PATH="/usr/local/go/bin:$$PATH"; go fmt ./...
@echo "[+] Code formatted!"
# Run linter (requires golangci-lint)
lint:
@echo "[*] Running linter..."
@export PATH="/usr/local/go/bin:$$PATH"; \
if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "[!] golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Clean build artifacts
clean:
@echo "[*] Cleaning build artifacts..."
rm -rf $(BUILD_DIR)
@export PATH="/usr/local/go/bin:$$PATH"; go clean
@echo "[+] Clean complete!"
# Runtime targets
run: build
@echo "[*] Starting TrinityProxy with interactive setup..."
@export PATH="/usr/local/go/bin:$$PATH"; ./$(BUILD_DIR)/$(BINARY_NAME)
# Smart controller setup - handles all controller requirements automatically
run-controller: build
@echo "[*] Starting TrinityProxy in Controller mode..."
@export PATH="/usr/local/go/bin:$$PATH"; TRINITY_ROLE=controller ./$(BUILD_DIR)/$(BINARY_NAME)
# Smart agent setup - handles all agent requirements automatically
run-agent:
@echo "[*] Setting up TrinityProxy Agent (complete setup)..."
@echo "[*] Checking agent requirements..."
@# Ensure system dependencies are installed
@if ! command -v sockd >/dev/null 2>&1; then \
echo "[*] Installing required system dependencies..."; \
make setup-system; \
fi
@# Build if needed
@if [ ! -f "$(BUILD_DIR)/$(BINARY_NAME)" ]; then \
echo "[*] Building binaries..."; \
make build; \
fi
@# Install as systemd service if not already installed
@if [ ! -f /etc/systemd/system/trinityproxy-agent.service ]; then \
echo "[*] Installing agent as systemd service..."; \
make install-agent-service; \
fi
@# Start the service
@echo "[*] Starting TrinityProxy Agent service..."
@sudo systemctl start trinityproxy-agent
@sleep 3
@echo ""
@if sudo systemctl is-active trinityproxy-agent >/dev/null 2>&1; then \
echo "π SUCCESS! TrinityProxy Agent is running!"; \
echo ""; \
echo "β
Agent Status: sudo systemctl status trinityproxy-agent"; \
echo "β
View Logs: sudo journalctl -u trinityproxy-agent -f"; \
echo "β
SOCKS5 proxy is active and reporting to controller"; \
echo ""; \
echo "π― Agent running in background via systemd service!"; \
else \
echo "β Agent service failed to start. Check logs:"; \
sudo journalctl -u trinityproxy-agent --no-pager -n 20; \
fi
# Development helpers
dev-controller: build
@echo "[*] Starting development controller (with auto-restart)..."
@if command -v entr >/dev/null 2>&1; then \
find . -name "*.go" | entr -r make run-controller; \
else \
echo "[!] Install 'entr' for auto-restart: apt-get install entr"; \
make run-controller; \
fi
dev-agent: build
@echo "[*] Starting development agent (with auto-restart)..."
@if command -v entr >/dev/null 2>&1; then \
find . -name "*.go" | entr -r make run-agent; \
else \
echo "[!] Install 'entr' for auto-restart: apt-get install entr"; \
make run-agent; \
fi
# Deployment helpers
deploy-vps:
@if [ -z "$(VPS_HOST)" ]; then \
echo "[-] VPS_HOST not set. Usage: make deploy-vps VPS_HOST=user@your-vps.com"; \
exit 1; \
fi
@echo "[*] Deploying to VPS: $(VPS_HOST)"
rsync -avz --progress . $(VPS_HOST):~/TrinityProxy/
ssh $(VPS_HOST) "cd ~/TrinityProxy && make setup-dev && sudo make install"
@echo "[+] Deployment complete!"
# Quick start for new clones
quickstart:
@echo "TrinityProxy Quick Start"
@echo "======================="
@echo "[1/5] Setting up system dependencies..."
@make setup-system
@echo "[2/5] Checking dependencies..."
@make check-deps
@echo "[3/5] Installing Go dependencies..."
@make deps
@echo "[4/5] Building binaries..."
@make build
@echo "[5/5] Ready to run!"
@echo ""
@echo "π SIMPLE USAGE:"
@echo " make run-controller - Start as API controller (auto-installs everything)"
@echo " make run-agent - Complete agent setup (installs service, runs in background)"
@echo " make run - Interactive selection"
@echo ""
# Complete VPS setup (runs setup script)
setup-system:
@if [ -f "scripts/setup.sh" ]; then \
echo "[*] Running system setup script..."; \
chmod +x scripts/setup.sh; \
sudo bash scripts/setup.sh; \
echo "[+] System setup complete!"; \
else \
echo "[!] Setup script not found. Installing basic dependencies..."; \
make install; \
fi
# VPS-specific quickstart (includes system setup)
vps-setup: setup-system quickstart setup-api-controller install-service
@echo ""
@echo "[+] VPS Setup Complete!"
@echo "======================"
@echo "Checking port 3100 and starting TrinityProxy Controller..."
@echo ""
@# Kill anything blocking port 3100
@if command -v lsof >/dev/null 2>&1; then \
BLOCKING_PID=$$(lsof -ti:3100 2>/dev/null); \
if [ ! -z "$$BLOCKING_PID" ]; then \
echo "[*] Killing process blocking port 3100 (PID: $$BLOCKING_PID)"; \
sudo kill -9 $$BLOCKING_PID 2>/dev/null || true; \
sleep 2; \
fi \
fi
@# Start the service
@echo "[*] Starting TrinityProxy Controller service..."
@sudo systemctl start trinityproxy-controller
@sleep 3
@echo ""
@if sudo systemctl is-active trinityproxy-controller >/dev/null 2>&1; then \
echo "π SUCCESS! TrinityProxy Controller is running!"; \
echo ""; \
echo "β
API Available at: https://api.sauronstore.com"; \
echo "β
Service Status: sudo systemctl status trinityproxy-controller"; \
echo "β
View Logs: sudo journalctl -u trinityproxy-controller -f"; \
echo ""; \
echo "π― Your VPS is ready! Controller is running in background."; \
else \
echo "β Service failed to start. Check logs:"; \
sudo journalctl -u trinityproxy-controller --no-pager -n 20; \
fi
@echo ""
# Agent VPS setup (system setup + agent service)
agent-setup: setup-system quickstart install-agent-service
@echo ""
@echo "[+] Agent VPS Setup Complete!"
@echo "============================="
@echo "Starting TrinityProxy Agent service..."
@echo ""
@# Start the agent service
@echo "[*] Starting TrinityProxy Agent service..."
@sudo systemctl start trinityproxy-agent
@sleep 3
@echo ""
@if sudo systemctl is-active trinityproxy-agent >/dev/null 2>&1; then \
echo "π SUCCESS! TrinityProxy Agent is running!"; \
echo ""; \
echo "β
Agent Status: sudo systemctl status trinityproxy-agent"; \
echo "β
View Logs: sudo journalctl -u trinityproxy-agent -f"; \
echo "β
SOCKS5 proxy is active and reporting to controller"; \
echo ""; \
echo "π― Your Agent VPS is ready! SOCKS5 proxy running in background."; \
else \
echo "β Agent service failed to start. Check logs:"; \
sudo journalctl -u trinityproxy-agent --no-pager -n 20; \
fi
@echo ""
# API Controller setup with SSL (uses setup_api.sh)
setup-api-controller:
@if [ -f "scripts/setup_api.sh" ]; then \
echo "[*] Setting up API controller with SSL..."; \
chmod +x scripts/setup_api.sh; \
sudo bash scripts/setup_api.sh; \
echo "[+] API controller setup complete!"; \
else \
echo "[!] API setup script not found. Using basic controller setup..."; \
make run-controller; \
fi
# Install controller as systemd service (runs in background)
install-service: build
@if [ -f "scripts/install-service.sh" ]; then \
echo "[*] Installing TrinityProxy Controller as systemd service..."; \
chmod +x scripts/install-service.sh; \
sudo bash scripts/install-service.sh; \
echo "[+] TrinityProxy Controller service installed!"; \
else \
echo "[!] Service installation script not found."; \
exit 1; \
fi
# Install agent as systemd service (runs in background)
install-agent-service: build
@if [ -f "scripts/install-agent-service.sh" ]; then \
echo "[*] Installing TrinityProxy Agent as systemd service..."; \
chmod +x scripts/install-agent-service.sh; \
sudo bash scripts/install-agent-service.sh; \
echo "[+] TrinityProxy Agent service installed!"; \
else \
echo "[!] Agent service installation script not found."; \
exit 1; \
fi
# Start/restart the systemd service
start-service:
@if [ -f /etc/systemd/system/trinityproxy-controller.service ]; then \
echo "[*] Starting TrinityProxy Controller service..."; \
sudo systemctl start trinityproxy-controller; \
sudo systemctl status trinityproxy-controller; \
else \
echo "[!] Service not installed. Run 'make install-service' first."; \
exit 1; \
fi
# Stop the systemd service
stop-service:
@if [ -f /etc/systemd/system/trinityproxy-controller.service ]; then \
echo "[*] Stopping TrinityProxy Controller service..."; \
sudo systemctl stop trinityproxy-controller; \
echo "[+] Service stopped."; \
else \
echo "[!] Service not installed."; \
fi
# Start/restart the agent systemd service
start-agent-service:
@if [ -f /etc/systemd/system/trinityproxy-agent.service ]; then \
echo "[*] Starting TrinityProxy Agent service..."; \
sudo systemctl start trinityproxy-agent; \
sudo systemctl status trinityproxy-agent; \
else \
echo "[!] Agent service not installed. Run 'make install-agent-service' first."; \
exit 1; \
fi
# Stop the agent systemd service
stop-agent-service:
@if [ -f /etc/systemd/system/trinityproxy-agent.service ]; then \
echo "[*] Stopping TrinityProxy Agent service..."; \
sudo systemctl stop trinityproxy-agent; \
echo "[+] Agent service stopped."; \
else \
echo "[!] Agent service not installed."; \
fi
# Version info
version:
@echo "TrinityProxy Build System"
@echo "Git Version: $(shell git describe --tags --always --dirty 2>/dev/null || echo 'dev')"
@export PATH="/usr/local/go/bin:$$PATH"; echo "Go Version: $$(go version 2>/dev/null || echo 'Go not found')"
@echo "Build Date: $(shell date)"
# Show project status
status:
@echo "TrinityProxy Project Status"
@echo "=========================="
@echo "Repository: $(shell git remote get-url origin 2>/dev/null || echo 'No remote')"
@echo "Branch: $(shell git branch --show-current 2>/dev/null || echo 'No git')"
@echo "Last Commit: $(shell git log -1 --pretty=format:'%h - %s (%cr)' 2>/dev/null || echo 'No commits')"
@export PATH="/usr/local/go/bin:$$PATH"; echo "Go Modules: $$(go list -m all 2>/dev/null | wc -l || echo 'N/A') dependencies"
@echo "Build Status: $(shell [ -f $(BUILD_DIR)/$(BINARY_NAME) ] && echo 'Built' || echo 'Not built')"
# Debug PATH and environment
debug:
@echo "TrinityProxy Debug Information"
@echo "============================="
@echo "Current PATH: $$PATH"
@echo "Go in PATH: $$(command -v go 2>/dev/null || echo 'Not found')"
@echo "Go in /usr/local/go/bin: $$(ls -la /usr/local/go/bin/go 2>/dev/null || echo 'Not found')"
@export PATH="/usr/local/go/bin:$$PATH"; echo "Go with updated PATH: $$(command -v go 2>/dev/null || echo 'Not found')"
@export PATH="/usr/local/go/bin:$$PATH"; echo "Go version: $$(go version 2>/dev/null || echo 'Not accessible')"
@echo "Sockd in PATH: $$(command -v sockd 2>/dev/null || echo 'Not found')"
@echo "[*] Current directory: $$(pwd)"
@echo "User: $$(whoami)"
# Remove old TrinityProxy installation
cleanup:
@if [ -f "scripts/cleanup.sh" ]; then \
echo "[*] Running TrinityProxy cleanup script..."; \
chmod +x scripts/cleanup.sh; \
sudo bash scripts/cleanup.sh; \
else \
echo "[-] Cleanup script not found at scripts/cleanup.sh"; \
echo "[*] Manual cleanup instructions:"; \
echo " sudo systemctl stop trinityproxy"; \
echo " sudo systemctl disable trinityproxy"; \
echo " sudo rm -f /etc/systemd/system/trinityproxy.service"; \
echo " sudo rm -f /etc/danted.conf /etc/trinityproxy-*"; \
echo " sudo rm -rf /root/TrinityProxy ~/TrinityProxy"; \
fi