-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·214 lines (183 loc) · 5.93 KB
/
setup.sh
File metadata and controls
executable file
·214 lines (183 loc) · 5.93 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
#!/bin/bash
# Setup script for Tailscale Exit Node Benchmark
# Installs dependencies on Linux (Ubuntu/Debian/Fedora/Arch/Alpine)
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
log_info() { echo -e "${CYAN}[INFO]${NC} $*"; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*"; }
echo -e "${BOLD}${CYAN}"
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ Tailscale Exit Node Benchmark - Setup ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Detect OS
detect_os() {
if [[ -f /etc/os-release ]]; then
. /etc/os-release
echo "$ID"
elif [[ -f /etc/debian_version ]]; then
echo "debian"
elif [[ -f /etc/redhat-release ]]; then
echo "rhel"
else
echo "unknown"
fi
}
OS=$(detect_os)
log_info "Detected OS: $OS"
# Install system dependencies
install_system_deps() {
log_info "Installing system dependencies..."
case "$OS" in
ubuntu|debian|pop)
sudo apt-get update
sudo apt-get install -y curl jq bc iputils-ping
;;
fedora)
sudo dnf install -y curl jq bc iputils
;;
centos|rhel|rocky|almalinux)
sudo yum install -y curl jq bc iputils
;;
arch|manjaro)
sudo pacman -Sy --noconfirm curl jq bc iputils
;;
alpine)
sudo apk add curl jq bc iputils
;;
*)
log_warn "Unknown OS. Please manually install: curl, jq, bc, ping"
;;
esac
log_success "System dependencies installed"
}
# Install Tailscale
install_tailscale() {
if command -v tailscale &>/dev/null; then
log_success "Tailscale already installed: $(tailscale version | head -1)"
return 0
fi
log_info "Installing Tailscale..."
case "$OS" in
ubuntu|debian|pop)
# Official Tailscale install script
curl -fsSL https://tailscale.com/install.sh | sh
;;
fedora)
sudo dnf config-manager --add-repo https://pkgs.tailscale.com/stable/fedora/tailscale.repo
sudo dnf install -y tailscale
;;
centos|rhel|rocky|almalinux)
sudo yum-config-manager --add-repo https://pkgs.tailscale.com/stable/rhel/8/tailscale.repo
sudo yum install -y tailscale
;;
arch|manjaro)
sudo pacman -Sy --noconfirm tailscale
;;
alpine)
sudo apk add tailscale
;;
*)
log_warn "Unknown OS. Installing via official script..."
curl -fsSL https://tailscale.com/install.sh | sh
;;
esac
log_success "Tailscale installed"
}
# Enable and start Tailscale service
start_tailscale() {
log_info "Enabling Tailscale service..."
if command -v systemctl &>/dev/null; then
sudo systemctl enable --now tailscaled
log_success "Tailscale service started"
elif command -v rc-service &>/dev/null; then
sudo rc-service tailscale start
sudo rc-update add tailscale
log_success "Tailscale service started (OpenRC)"
else
log_warn "Could not detect init system. Please start tailscaled manually."
fi
}
# Check Tailscale status
check_tailscale() {
log_info "Checking Tailscale status..."
if ! tailscale status &>/dev/null; then
log_warn "Tailscale is not logged in."
echo ""
echo -e "${YELLOW}To authenticate, run:${NC}"
echo -e " ${CYAN}sudo tailscale up${NC}"
echo ""
echo -e "${YELLOW}Or to use an auth key:${NC}"
echo -e " ${CYAN}sudo tailscale up --authkey=tskey-auth-xxxxx${NC}"
echo ""
return 1
fi
log_success "Tailscale is connected"
tailscale status
}
# Verify all dependencies
verify_deps() {
log_info "Verifying dependencies..."
local missing=()
for cmd in curl jq bc ping tailscale; do
if ! command -v "$cmd" &>/dev/null; then
missing+=("$cmd")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
log_error "Missing: ${missing[*]}"
return 1
fi
log_success "All dependencies available"
echo ""
echo -e " curl: $(curl --version | head -1)"
echo -e " jq: $(jq --version)"
echo -e " bc: $(bc --version | head -1)"
echo -e " ping: $(ping -V 2>&1 | head -1)"
echo -e " tailscale: $(tailscale version | head -1)"
}
# Main
main() {
local skip_tailscale=false
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-tailscale)
skip_tailscale=true
shift
;;
-h|--help)
echo "Usage: $0 [--skip-tailscale]"
echo ""
echo "Options:"
echo " --skip-tailscale Skip Tailscale installation (install only curl, jq, bc, ping)"
exit 0
;;
*)
shift
;;
esac
done
install_system_deps
if [[ "$skip_tailscale" == "false" ]]; then
install_tailscale
start_tailscale
check_tailscale || true
fi
echo ""
verify_deps
echo ""
echo -e "${GREEN}${BOLD}Setup complete!${NC}"
echo ""
echo -e "Next steps:"
echo -e " 1. Ensure Tailscale is authenticated: ${CYAN}sudo tailscale up${NC}"
echo -e " 2. Run quick test: ${CYAN}./quick-test.sh${NC}"
echo -e " 3. Run full benchmark: ${CYAN}./benchmark.sh${NC}"
}
main "$@"