#!/bin/bash
# Telocall Link — double-click in Finder to connect (macOS .command file)
# https://link.telocall.com/connect-mac

cd "$(dirname "$0")" || true
clea
echo ""
echo "============================================"
echo "  Telocall Link — Connect"
echo "============================================"
echo ""
echo "Downloading the latest connect script..."
if ! curl -fsSL -o /tmp/telocall-mac-connect.sh https://link.telocall.com/connect-mac.sh; then
  echo ""
  echo "ERROR: Could not download from link.telocall.com"
  echo "Check internet, then double-click this file again."
  echo ""
  read -r -p "Press Enter to close..."
  exit 1
fi
chmod +x /tmp/telocall-mac-connect.sh
echo ""
bash /tmp/telocall-mac-connect.sh
status=$?
echo ""
if [ "$status" -eq 0 ]; then
  echo "You can close this window."
else
  echo "Something went wrong (exit $status)."
  echo "You can double-click this file again, or send us:"
  echo "  ~/Library/Application Support/TelocallLink/connect.log"
fi
echo ""
read -r -p "Press Enter to close..."
exit "$status"
