#!/bin/bash
# Owlnighter installer — https://owlnighter.notcool.in
# Fetches the app with curl (no quarantine flag, no Gatekeeper drama),
# puts it in /Applications, and opens it.
set -euo pipefail

URL="https://owlnighter.notcool.in/downloads/Owlnighter-latest.zip"
DEST="/Applications"
[ -w "$DEST" ] || DEST="$HOME/Applications"
mkdir -p "$DEST"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT

echo "⬇  fetching Owlnighter…"
curl -fsSL "$URL" -o "$TMP/owl.zip"
ditto -x -k "$TMP/owl.zip" "$TMP"

killall Owlnighter 2>/dev/null || true
rm -rf "$DEST/Owlnighter.app"
ditto "$TMP/Owlnighter.app" "$DEST/Owlnighter.app"
xattr -dr com.apple.quarantine "$DEST/Owlnighter.app" 2>/dev/null || true

open "$DEST/Owlnighter.app"
echo "🦉 Owlnighter installed in $DEST — look up, he's in your menu bar."
