#!/bin/sh
# /usr/bin/bn-launcher of the Linux packages. The launcher runs from the player's own folder, because there it can
# replace itself when the backend has a newer version; the copy that came with the package only seeds that folder.
packaged=/usr/lib/bn-launcher/bn-launcher
data="${BNL_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bn-launcher}"
program="$data/bin/bn-launcher"

if [ ! -x "$program" ]; then
    mkdir -p "$data/bin" && cp "$packaged" "$program.part" && chmod 755 "$program.part" && mv "$program.part" "$program" \
        || exec "$packaged" "$@"
fi
exec "$program" "$@"
