diff options
| author | Your Name <you@example.com> | 2026-02-08 20:23:31 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-02-08 20:23:31 +0800 |
| commit | c0e80820010cc5b0fdea1eb69bafef7f575e3201 (patch) | |
| tree | 94b8be5284bec668e1911bbe65e1b215ccd7657a /client.sh | |
Diffstat (limited to 'client.sh')
| -rwxr-xr-x | client.sh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/client.sh b/client.sh new file mode 100755 index 0000000..2118a73 --- /dev/null +++ b/client.sh | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Install tailscale and register with a headscale server | ||
| 3 | # Copy to a VM and run: sudo ./client.sh <server_ip> <auth_key> | ||
| 4 | # Example: sudo ./client.sh 37.27.166.243 hskey-auth-xxxx | ||
| 5 | # macOS CLI: echo 'alias tailscale="/Applications/Tailscale.app/Contents/MacOS/Tailscale"' >> ~/.zshrc | ||
| 6 | set -e | ||
| 7 | |||
| 8 | die() { echo "Error: $1" >&2; exit 1; } | ||
| 9 | info() { echo " $1"; } | ||
| 10 | |||
| 11 | [[ $EUID -eq 0 ]] || die "Must run as root" | ||
| 12 | |||
| 13 | SERVER_IP="${1:?Usage: $0 <server_ip> <auth_key>}" | ||
| 14 | AUTH_KEY="${2:?Usage: $0 <server_ip> <auth_key>}" | ||
| 15 | LOGIN_SERVER="http://${SERVER_IP}:8080" | ||
| 16 | |||
| 17 | echo "=== Installing Tailscale Client ===" | ||
| 18 | echo "Server: $LOGIN_SERVER" | ||
| 19 | echo "" | ||
| 20 | |||
| 21 | # 1. Install tailscale | ||
| 22 | if command -v tailscale &>/dev/null; then | ||
| 23 | info "Tailscale already installed: $(tailscale version | head -1)" | ||
| 24 | else | ||
| 25 | info "Installing tailscale..." | ||
| 26 | dnf install -y tailscale | ||
| 27 | fi | ||
| 28 | |||
| 29 | # 2. Start tailscaled | ||
| 30 | info "Starting tailscaled..." | ||
| 31 | systemctl enable --now tailscaled | ||
| 32 | |||
| 33 | # 3. Register with headscale | ||
| 34 | info "Registering with headscale at $LOGIN_SERVER..." | ||
| 35 | tailscale up --login-server "$LOGIN_SERVER" --authkey "$AUTH_KEY" | ||
| 36 | |||
| 37 | # 4. Show status | ||
| 38 | echo "" | ||
| 39 | echo "=== Connected ===" | ||
| 40 | tailscale status | ||
| 41 | echo "" | ||
| 42 | echo "To disconnect: tailscale down" | ||
| 43 | echo "To switch server: tailscale down && tailscale up --login-server http://<new_ip>:8080 --authkey <key> --force-reauth" | ||
| 44 | echo "To remove: tailscale down && systemctl disable --now tailscaled && dnf remove -y tailscale" | ||
