#!/bin/sh

cd "$(dirname "$(readlink -f "${0}")")" || exit 1

ask_continue() {
    printf "$1 ([y]es or [N]o): "; read -r REPLY
    case $(echo "$REPLY" | tr '[:upper:]' '[:lower:]') in
        y|yes) ;;
        *)     echo "Installation canceled." && exit 1;;
    esac
}

PRODUCT=Charlatan3

! ./check_compatibility.sh && ask_continue "Do you want to continue with installation anyway?"

more license.txt
ask_continue "Do you accept the license terms?"

clap_dir=$(echo "$CLAP_PATH" | sed 's/:.*//')
clap_dir=${clap_dir:-$HOME/.clap}
vst3_dir="$HOME/.vst3"
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
DATA_DIR="$DATA_DIR/charlatan"

clear
echo "CLAP plug-in will be installed to $clap_dir"
echo "VST3 plug-in will be installed to $vst3_dir"
echo "Factory presets will be installed to $DATA_DIR"
echo "WARNING: Existing Factory presets will be overwritten!"
echo "         To prevent data loss, backup your presets directory before proceeding."
ask_continue "Do you want to continue with installation?"

mkdir -p "$clap_dir"
cp $PRODUCT.so "$clap_dir/$PRODUCT.clap"
mkdir -p "$vst3_dir/$PRODUCT.vst3/Contents/x86_64-linux"
cp $PRODUCT.so "$vst3_dir/$PRODUCT.vst3/Contents/x86_64-linux/"
mkdir -p "$DATA_DIR"
cp -rf presets "$DATA_DIR/"
