#!/bin/zsh
set -e
SERVER='https://lcl.sitekings.net'
ARCH='amd64'
APP_DIR="$(cd "$(dirname "$0")" && pwd)"
BIN="$APP_DIR/sk-sos-mac-amd64"
CONFIG="$APP_DIR/../../../SK-Remote-Support.config"
PIN=""
if [ -f "$CONFIG" ]; then
  CFG_PIN="$(/usr/bin/sed -n 's/^PIN=//p' "$CONFIG" | /usr/bin/head -n 1)"
  CFG_SERVER="$(/usr/bin/sed -n 's/^SERVER=//p' "$CONFIG" | /usr/bin/head -n 1)"
  if [ -n "$CFG_PIN" ]; then PIN="$CFG_PIN"; fi
  if [ -n "$CFG_SERVER" ]; then SERVER="$CFG_SERVER"; fi
fi
/usr/bin/osascript   -e 'display notification "Starting SK Remote Services..." with title "SK Remote Services"'   >/dev/null 2>&1 || true
if [ -n "$PIN" ]; then
  exec "$BIN" "--pin" "$PIN" "--server" "$SERVER"
else
  exec "$BIN" "--server" "$SERVER"
fi
