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

script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
wine_loader="${YABRIDGE_WINELOADER:-$script_dir/wine-staging-9.21.sh}"
bitwig="${BITWIG_STUDIO:-/usr/bin/bitwig-studio}"

if [[ ! -x "$wine_loader" ]]; then
  printf 'Wine loader is not executable: %s\n' "$wine_loader" >&2
  exit 127
fi

if [[ ! -x "$bitwig" ]]; then
  printf 'Bitwig Studio launcher is not executable: %s\n' "$bitwig" >&2
  exit 127
fi

export WINELOADER="$wine_loader"
unset WINEPREFIX

exec "$bitwig" "$@"
