#!/bin/sh

pluginpkg="dssi-example-plugins"
hostpkg="dssi-host-jack"

pluginhost=/usr/bin/jack-dssi-host
plugin=$(basename $0)

error() {
    echo "$*" 1>&2
}

if [ ! -x "${pluginhost}" ]; then
    error "Please install the '${hostpkg}' package to run DSSI-plugins as standalone"
    exit 1
fi

archmatch=false
archdirs=""
for f in /usr/lib/*/dssi/${plugin}.so; do
    test -e "${f}" || continue
    d="${f%/*}"
    archdirs="${archdirs} ${d}"
    if grep -aq ":${d}:" "${pluginhost}"; then
	archmatch=true
    fi
done

if [ "${archmatch}" = "false" ]; then
    error ""
    error "It seems as if ${pluginhost} has the wrong architecture to load plugins from ${archdirs}"
    error "Make sure to install the '${pluginpkg}' package matching the architecture of the '${hostpkg}' package"
    error ""
    dpkg -l "${hostpkg}" "${pluginpkg}" 1>&2
    error ""
    error "Continuing anyhow."
fi

"${pluginhost}" "${plugin}.so"
