#!/usr/bin/env bash

set -o errexit
set -o nounset

if (( $# == 0 )); then
  echo "Usage: $0 TAILNET" >&2
  exit 1
fi

target_tailnet="$1"
current_tailnet="$(tailscale status --json | jq -r .CurrentTailnet.Name)"

if [[ "$current_tailnet" != "$target_tailnet" ]]; then
  print_info "-> tailscale switch '$target_tailnet'"
  tailscale switch "$target_tailnet"
  echo ""
fi
