#!/bin/bash

set -e
clear

PKG_NAME="MixChecker-1.0.0-macOS-unsigned-internal.pkg"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PKG_PATH="$SCRIPT_DIR/$PKG_NAME"

echo "Mix Checker macOS beta installer"
echo "================================"
echo ""
echo "This script will temporarily disable Gatekeeper, install Mix Checker,"
echo "then re-enable Gatekeeper automatically."
echo ""
echo "Use this only for private beta testing if the package is unsigned."
echo "For public release, use a signed and notarized Mix Checker package."
echo ""

if [ ! -f "$PKG_PATH" ]; then
  echo "Installer package not found:"
  echo "$PKG_PATH"
  echo ""
  echo "Put this script in the same folder as:"
  echo "$PKG_NAME"
  echo ""
  read -p "Press Enter to close this window."
  exit 1
fi

read -p "Type INSTALL to continue: " confirm

if [ "$confirm" != "INSTALL" ]; then
  echo ""
  echo "Cancelled. Nothing was installed."
  exit 1
fi

echo ""
echo "Disabling Gatekeeper temporarily..."
sudo spctl --master-disable
spctl --status

echo ""
echo "Installing Mix Checker..."
sudo installer -pkg "$PKG_PATH" -target /

echo ""
echo "Re-enabling Gatekeeper..."
sudo spctl --master-enable
spctl --status

echo ""
echo "Mix Checker installation finished."
echo "Open your DAW and rescan plugins if Mix Checker does not appear automatically."
echo ""
read -p "Press Enter to close this window."
