#!/bin/bash
# Installs MegaKit 0.1.3 into Applications and opens it. From https://megakit-dist-7df4e5d2.pages.dev/
set -euo pipefail
zip_url="https://megakit-dist-7df4e5d2.pages.dev/updates/MegaKit-0.1.3-5.zip"
apps=/Applications
[[ -w $apps ]] || { apps=$HOME/Applications; mkdir -p "$apps"; }
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
echo "Downloading MegaKit 0.1.3…"
curl -fsSL "$zip_url" -o "$tmp/MegaKit.zip"
ditto -x -k "$tmp/MegaKit.zip" "$tmp"
osascript -e 'tell application id "local.megaclick" to quit' >/dev/null 2>&1 || true
sleep 1
rm -rf "$apps/MegaKit.app"
ditto "$tmp/MegaKit.app" "$apps/MegaKit.app"
xattr -dr com.apple.quarantine "$apps/MegaKit.app" 2>/dev/null || true
open "$apps/MegaKit.app"
echo "✓ MegaKit 0.1.3 is in $apps and running. Look for the M in the menu bar."
