#!/bin/sh
# Route bluetoothctl discovery through one live interactive BlueZ client.
# All other bluetoothctl calls go to the real package binary unchanged.
REAL="${BANANARCHY_REAL_BLUETOOTHCTL:-/usr/bin/bluetoothctl}"
HELPER="${BANANARCHY_BT_SCAN_HELPER:-/usr/bin/bananarchy-bt-scan.sh}"
export BANANARCHY_REAL_BLUETOOTHCTL="$REAL"

case " $* " in
  *" scan on "*|*" scan bredr "*|*" scan le "*)
    "$HELPER" || true
    exit 0
    ;;
  *)
    exec "$REAL" "$@"
    ;;
esac
