#!/bin/bash
# Workplace VPN setup for macOS
LOGIN_SERVER="https://vpn.forge-stack.work"

set -e
echo "Workplace VPN Setup"
echo "==================="

if ! command -v brew >/dev/null 2>&1; then
  echo "Homebrew not found. Installing..."
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

echo ""
echo "[1/3] Installing Tailscale via Homebrew..."
brew install --cask tailscale-app 2>&1 | tail -5 || true

echo ""
echo "[2/3] Setting Workplace control server..."
defaults write io.tailscale.ipn.macos ControlURL "$LOGIN_SERVER" 2>/dev/null || true
defaults write io.tailscale.ipn.macsys ControlURL "$LOGIN_SERVER" 2>/dev/null || true

echo ""
echo "[3/3] Launching Tailscale..."
open -a Tailscale 2>/dev/null || true

echo ""
echo "==================="
echo " Setup complete!"
echo "==================="
echo ""
echo "Click Tailscale in menu bar → Sign in → use your Google work account."
echo "After admin approval, open: https://apps.forge-stack.work"
