Skip to content

Instantly share code, notes, and snippets.

@rankun203
Last active April 3, 2025 10:45
Show Gist options
  • Save rankun203/20b12b5d01151b08ba5962ae6598f0e1 to your computer and use it in GitHub Desktop.
Save rankun203/20b12b5d01151b08ba5962ae6598f0e1 to your computer and use it in GitHub Desktop.
Launch Tailscale (with sudo)
#!/bin/bash
# filepath: setup_tailscale.sh
# Function to check if a process is running
check_process() {
pgrep -x "$1" >/dev/null
return $?
}
# Function to install Tailscale
install_tailscale() {
echo "Installing Tailscale..."
# Add Tailscale's GPG key
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/jammy.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
# Add the tailscale repository
curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/jammy.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list
# Install Tailscale
sudo apt-get update && sudo apt-get install -y tailscale
}
# Check if tailscale is installed
if ! command -v tailscale &> /dev/null; then
install_tailscale
fi
# Check if tailscaled is running
if ! check_process "tailscaled"; then
echo "Starting tailscaled..."
sudo tailscaled &
# Wait a moment for tailscaled to start
sleep 2
fi
# Check if we're already authenticated
if ! tailscale status >/dev/null 2>&1; then
echo "Connecting to Tailscale..."
echo "Please authenticate using the link that will be displayed..."
sudo tailscale up --advertise-exit-node --hostname rob
else
echo "Tailscale is already connected"
tailscale status
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment