#!/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 $1

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID
  cp -PR $PKG_DIR/config/settings.xml $ADDON_BUILD/$PKG_ADDON_ID/settings-default.xml

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config
  cp $BUILD/vdr-[0-9]*/channels.conf* $ADDON_BUILD/$PKG_ADDON_ID/config
  cp $BUILD/vdr-[0-9]*/diseqc.conf $ADDON_BUILD/$PKG_ADDON_ID/config
  cp $BUILD/vdr-[0-9]*/keymacros.conf $ADDON_BUILD/$PKG_ADDON_ID/config
  cp $BUILD/vdr-[0-9]*/scr.conf $ADDON_BUILD/$PKG_ADDON_ID/config
  cp $BUILD/vdr-[0-9]*/sources.conf $ADDON_BUILD/$PKG_ADDON_ID/config
  cp $BUILD/vdr-[0-9]*/svdrphosts.conf $ADDON_BUILD/$PKG_ADDON_ID/config
  echo '0.0.0.0/0' >> $ADDON_BUILD/$PKG_ADDON_ID/config/svdrphosts.conf
  mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/live
  cp -PR $BUILD/vdr-live-*/live/* $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/live
  cp $PKG_DIR/config.plugins/remote.conf $ADDON_BUILD/$PKG_ADDON_ID/config
  mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/epgsearch
  cp $PKG_DIR/config.plugins/commands.conf $ADDON_BUILD/$PKG_ADDON_ID/config

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins
  cp $BUILD/rotorng-[0-9]*/examples/rotorng.conf $ADDON_BUILD/$PKG_ADDON_ID/config/plugins

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/epgsources/epgdata2xmltv
  cp $BUILD/vdr-plugin-xmltv2vdr*/dist/epgdata2xmltv/epgdata2xmltv.dist $ADDON_BUILD/$PKG_ADDON_ID/config/epgsources/epgdata2xmltv/

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-plugin-xvdr-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-plugin-vnsiserver-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-dynamite-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-iptv-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-wirbelscan-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-wirbelscancontrol-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-plugin-dvbapi-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-sc-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-sc-*/systems/*/libsc*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-plugin-streamdev-*/server/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-plugin-streamdev-*/client/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-live-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/rotorng-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-control-*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-epgsearch*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-plugin-xmltv2vdr*/libvdr*.so.* $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-xineliboutput-[0-9]*/libvdr*.so.1.7.27 $ADDON_BUILD/$PKG_ADDON_ID/plugin
  cp -PR $BUILD/vdr-text2skin-[0-9]*/libvdr*.so.1.7.27 $ADDON_BUILD/$PKG_ADDON_ID/plugin

#  ENABLED_PLUGINS="cardclient constcw sc-conax sc-cryptoworks sc-irdeto sc-nagra sc-seca sc-viaccess sc-videoguard2"
#  for plugin in $ENABLED_PLUGINS; do
#    cp -PR $BUILD/vdr-sc-*/systems/$plugin/libsc*.so* $ADDON_BUILD/$PKG_ADDON_ID/plugin
#  done

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/xvdr
  cp -PR $BUILD/vdr-plugin-xvdr-*/xvdr/allowed_hosts.conf $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/xvdr

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/vnsiserver
  cp -PR $BUILD/vdr-plugin-vnsiserver-*/vnsiserver/allowed_hosts.conf $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/vnsiserver

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/bin
  cp -P $BUILD/vdr-[0-9]*/vdr $ADDON_BUILD/$PKG_ADDON_ID/bin/vdr.bin
  cp -P $BUILD/vdr-plugin-xmltv2vdr*/dist/epgdata2xmltv/epgdata2xmltv $ADDON_BUILD/$PKG_ADDON_ID/bin

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/attr-[0-9]*/libattr/.libs/*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/libcap-[0-9]*/libcap/*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/cxxtools-[0-9]*/.build-target/src/.libs/*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/tntnet-[0-9]*/.build-target/framework/common/.libs/*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/libzip-[0-9]*/lib/.libs/libzip*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/libxslt-[0-9]*/libxslt/.libs/libxslt*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib
  cp -P $BUILD/libxslt-[0-9]*/libexslt/.libs/libexslt*.so* $ADDON_BUILD/$PKG_ADDON_ID/lib

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/lib/imlib2/loaders/
mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/lib/imlib2/filters/
  cp $SYSROOT_PREFIX/usr/lib/libImlib2.so.1 $ADDON_BUILD/$PKG_ADDON_ID/lib/
  cp $SYSROOT_PREFIX/usr/lib/imlib2/loaders/*.so $ADDON_BUILD/$PKG_ADDON_ID/lib/imlib2/loaders/
  cp $SYSROOT_PREFIX/usr/lib/imlib2/filters/*.so $ADDON_BUILD/$PKG_ADDON_ID/lib/imlib2/filters/

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/streamdev-server
  cp -PR $BUILD/vdr-plugin-streamdev-*/streamdev-server/streamdevhosts.conf $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/streamdev-server

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/text2skin/anthra_1280_OS/
  cp -PR $BUILD/vdr-skinanthra_1280_OS-*/* $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/text2skin/anthra_1280_OS/
  rm -fr $ADDON_BUILD/$PKG_ADDON_ID/config/plugins/text2skin/anthra_1280_OS/themes

mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config/themes
  cp -P $BUILD/vdr-skinanthra_1280_OS-*/themes/* $ADDON_BUILD/$PKG_ADDON_ID/config/themes/
