#!/bin/bash
# RhythmEcho Linux installer
# Run from the folder containing linux/RhythmEcho.vst3

DIR="$(cd "$(dirname "$0")" && pwd)"
SRC="$DIR/linux/RhythmEcho.vst3"
NDA_FILE="$DIR/linux/NDA.md"

if [ ! -d "$SRC" ]; then
    echo "Error: Cannot find linux/RhythmEcho.vst3 next to this installer."
    exit 1
fi

if [ ! -f "$NDA_FILE" ]; then
    echo "Error: Cannot find NDA.md next to this installer."
    exit 1
fi

# Display NDA and require acceptance
echo "=========================================="
echo "  RhythmEcho Beta Test Agreement"
echo "=========================================="
echo ""
cat "$NDA_FILE"
echo ""
echo "=========================================="
echo ""
read -p "Do you accept these terms? (y/n): " ACCEPT
if [ "$ACCEPT" != "y" ] && [ "$ACCEPT" != "Y" ]; then
    echo "Installation cancelled."
    exit 0
fi
echo ""

# Try user-local first, fall back to system-wide
if [ -w "$HOME/.vst3" ] || mkdir -p "$HOME/.vst3" 2>/dev/null; then
    DEST="$HOME/.vst3"
    cp -R "$SRC" "$DEST/"
    echo "Installed to $DEST/RhythmEcho.vst3"
else
    DEST="/usr/lib/vst3"
    sudo mkdir -p "$DEST"
    sudo cp -R "$SRC" "$DEST/"
    echo "Installed to $DEST/RhythmEcho.vst3"
fi

echo "Restart your DAW to see RhythmEcho."
