summaryrefslogtreecommitdiff
path: root/client.sh
blob: 2118a73e2243beff80fa2c25b1fba125a582ab02 (plain)
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
#!/bin/bash
# Install tailscale and register with a headscale server
# Copy to a VM and run: sudo ./client.sh <server_ip> <auth_key>
# Example: sudo ./client.sh 37.27.166.243 hskey-auth-xxxx
# macOS CLI: echo 'alias tailscale="/Applications/Tailscale.app/Contents/MacOS/Tailscale"' >> ~/.zshrc
set -e

die()  { echo "Error: $1" >&2; exit 1; }
info() { echo "  $1"; }

[[ $EUID -eq 0 ]] || die "Must run as root"

SERVER_IP="${1:?Usage: $0 <server_ip> <auth_key>}"
AUTH_KEY="${2:?Usage: $0 <server_ip> <auth_key>}"
LOGIN_SERVER="http://${SERVER_IP}:8080"

echo "=== Installing Tailscale Client ==="
echo "Server: $LOGIN_SERVER"
echo ""

# 1. Install tailscale
if command -v tailscale &>/dev/null; then
    info "Tailscale already installed: $(tailscale version | head -1)"
else
    info "Installing tailscale..."
    dnf install -y tailscale
fi

# 2. Start tailscaled
info "Starting tailscaled..."
systemctl enable --now tailscaled

# 3. Register with headscale
info "Registering with headscale at $LOGIN_SERVER..."
tailscale up --login-server "$LOGIN_SERVER" --authkey "$AUTH_KEY"

# 4. Show status
echo ""
echo "=== Connected ==="
tailscale status
echo ""
echo "To disconnect:  tailscale down"
echo "To switch server: tailscale down && tailscale up --login-server http://<new_ip>:8080 --authkey <key> --force-reauth"
echo "To remove:      tailscale down && systemctl disable --now tailscaled && dnf remove -y tailscale"