#!/usr/bin/env bash
set -euo pipefail

# The launcher is intentionally separate from the Nuitka standalone tree.
# Keeping Qt/PySide shared libraries outside the executable lets recipients
# replace them, as required by the LGPL option selected by TalkyText.
launcher="$(readlink -f "${BASH_SOURCE[0]}")"
launcher_dir="$(dirname "${launcher}")"

for executable in \
    "${launcher_dir}/talkytext.dist/talkytext" \
    "${launcher_dir}/runtime/client/talkytext.dist/talkytext" \
    "${HOME}/.local/share/talkytext/runtime/client/talkytext.dist/talkytext"; do
    if [[ -x "${executable}" ]]; then
        export TALKYTEXT_LAUNCHER_PATH="${launcher}"
        exec "${executable}" "$@"
    fi
done

echo "TalkyText runtime not found next to ${launcher}." >&2
echo "Reinstall TalkyText from the complete Linux archive." >&2
exit 127
