#!/bin/bash
set -e

echo "Streamline WireGuard setup helper"
echo "This installs the official WireGuard tools. Streamline never stores your tunnel private key."
echo

if [ -d "/Applications/WireGuard.app" ] || command -v wg >/dev/null 2>&1; then
  echo "WireGuard is already installed."
  echo "Import your authorized .conf file into WireGuard, connect it, then use Check in Streamline Settings."
  read -r -p "Press Return to close."
  exit 0
fi

if command -v brew >/dev/null 2>&1; then
  read -r -p "Install the official wireguard-tools package with Homebrew? [y/N] " answer
  case "$answer" in
    y|Y|yes|YES)
      brew install wireguard-tools
      echo
      echo "WireGuard tools installed. Import an authorized .conf file using the official WireGuard app or wg-quick."
      ;;
    *)
      echo "Installation cancelled."
      ;;
  esac
else
  echo "Homebrew was not found. Opening the official WireGuard installation page."
  open "https://www.wireguard.com/install/"
fi

echo
read -r -p "Press Return to close."
