#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options

PKG_DIR=`find $PACKAGES -type d -name $1`

mkdir -p $INSTALL/etc/bluetooth
#  cp $PKG_BUILD/src/main.conf $INSTALL/etc/bluetooth
  cp $PKG_DIR/config/main.conf $INSTALL/etc/bluetooth
  cp $PKG_BUILD/tools/rfcomm.conf $INSTALL/etc/bluetooth
  cp $PKG_BUILD/input/input.conf $INSTALL/etc/bluetooth

  if [ "$ALSA_SUPPORT" = yes ]; then
    cp $PKG_BUILD/audio/audio.conf $INSTALL/etc/bluetooth
  fi

mkdir -p $INSTALL/etc/dbus-1/system.d
  cp $PKG_BUILD/src/bluetooth.conf $INSTALL/etc/dbus-1/system.d

mkdir -p $INSTALL/lib/udev
# not needed:  cp $PKG_BUILD/scripts/bluetooth_serial $INSTALL/lib/udev
# not needed:  chmod +x $INSTALL/lib/udev/bluetooth_serial
  cp $PKG_BUILD/tools/hid2hci $INSTALL/lib/udev

mkdir -p $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/scripts/97-bluetooth.rules $INSTALL/lib/udev/rules.d
# todo:        cp $PKG_BUILD/scripts/97-bluetooth-hid2hci.rules $INSTALL/lib/udev/rules.d
# not needed:  cp $PKG_BUILD/scripts/97-bluetooth-serial.rules $INSTALL/lib/udev/rules.d

mkdir -p $INSTALL/usr/lib
  cp -P $PKG_BUILD/lib/.libs/libbluetooth.so* $INSTALL/usr/lib

if [ "$ALSA_SUPPORT" = yes ]; then
  mkdir -p $INSTALL/usr/lib/alsa
    cp $PKG_BUILD/audio/.libs/*.so $INSTALL/usr/lib/alsa
fi

mkdir -p $INSTALL/usr/lib/bluetooth/plugins

mkdir -p $INSTALL/usr/sbin
  cp $PKG_BUILD/src/bluetoothd $INSTALL/usr/sbin

mkdir -p $INSTALL/usr/share/alsa
  cp $PKG_BUILD/audio/bluetooth.conf $INSTALL/usr/share/alsa

if [ "$DEVTOOLS" = "yes" ]; then
  mkdir -p $INSTALL/usr/bin
    cp $PKG_BUILD/tools/ciptool $INSTALL/usr/bin
    cp $PKG_BUILD/tools/dfutool $INSTALL/usr/bin
    cp $PKG_BUILD/tools/hcitool $INSTALL/usr/bin
    cp $PKG_BUILD/tools/l2ping $INSTALL/usr/bin
    cp $PKG_BUILD/tools/rfcomm $INSTALL/usr/bin
    cp $PKG_BUILD/tools/sdptool $INSTALL/usr/bin

mkdir -p $INSTALL/usr/sbin
  cp $PKG_BUILD/tools/bccmd $INSTALL/usr/sbin # TODO
  cp $PKG_BUILD/tools/hciattach $INSTALL/usr/sbin
  cp $PKG_BUILD/tools/hciconfig $INSTALL/usr/sbin
fi

