-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquick-start.sh
More file actions
113 lines (98 loc) · 2.71 KB
/
Copy pathquick-start.sh
File metadata and controls
113 lines (98 loc) · 2.71 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
#!/bin/bash
set -e
echo "====================================="
echo "Defenra Agent Quick Start"
echo "====================================="
echo ""
# Check if Go is installed
if ! command -v go &> /dev/null; then
echo "❌ Error: Go is not installed"
echo "Please install Go 1.21 or higher"
echo "Visit: https://golang.org/dl/"
exit 1
fi
GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
echo "✓ Go version: $GO_VERSION"
# Check if .env exists
if [ ! -f ".env" ]; then
echo ""
echo "Creating .env file..."
echo ""
read -p "Agent ID: " AGENT_ID
read -sp "Agent Key: " AGENT_KEY
echo ""
read -p "Core URL (default: http://localhost:3000): " CORE_URL
CORE_URL=${CORE_URL:-http://localhost:3000}
cat > .env << EOF
AGENT_ID=$AGENT_ID
AGENT_KEY=$AGENT_KEY
CORE_URL=$CORE_URL
POLLING_INTERVAL=60
LOG_LEVEL=info
CACHE_SIZE=10000
EOF
echo "✓ .env file created"
else
echo "✓ .env file exists"
fi
# Download dependencies
echo ""
echo "Downloading dependencies..."
go mod download
echo "✓ Dependencies downloaded"
# Download GeoIP database if not exists
if [ ! -f "GeoLite2-City.mmdb" ]; then
echo ""
echo "Downloading GeoIP database..."
wget -q --show-progress -O GeoLite2-City.mmdb \
https://github.com/Defenra/DefenraCore/raw/refs/heads/main/data/GeoLite2-City.mmdb
echo "✓ GeoIP database downloaded"
else
echo "✓ GeoIP database exists"
fi
# Build
echo ""
echo "Building Defenra Agent..."
go build -o defenra-agent .
echo "✓ Build complete"
# Export environment variables
echo ""
echo "Loading environment variables..."
export $(cat .env | xargs)
echo "✓ Environment loaded"
# Show info
echo ""
echo "====================================="
echo "Ready to start!"
echo "====================================="
echo ""
echo "Configuration:"
echo " - Agent ID: $AGENT_ID"
echo " - Core URL: $CORE_URL"
echo " - Polling Interval: 60 seconds"
echo ""
echo "Starting Defenra Agent..."
echo ""
echo "Note: You may need sudo to bind to ports 53, 80, 443"
echo ""
# Check if running as root or with CAP_NET_BIND_SERVICE
if [ "$EUID" -ne 0 ]; then
echo "⚠️ Warning: Not running as root"
echo "Privileged ports (53, 80, 443) may not be accessible"
echo ""
echo "Options:"
echo " 1. Run with sudo: sudo -E ./defenra-agent"
echo " 2. Give capabilities: sudo setcap 'cap_net_bind_service=+ep' ./defenra-agent"
echo " 3. Use alternative ports (requires firewall rules)"
echo ""
read -p "Continue anyway? (y/N): " CONTINUE
if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then
echo "Exiting..."
exit 0
fi
fi
echo ""
echo "Starting agent..."
echo "Press Ctrl+C to stop"
echo ""
./defenra-agent