#!/bin/sh

# x-vdr (Installations-Skript fuer einen VDR mit Debian als Basis)
# von Marc Wernecke - www.zulu-entertainment.de
# 30.04.2007
#
# vdr-muggle

# defaults
source ./../../x-vdr.conf
source ./../../setup.conf
source ./../../functions
WEB="http://kent.dl.sourceforge.net/sourceforge/vdr-muggle/vdr-muggle-0.1.12.tgz"
#WEB="http://downloads.htpc-tech.de/muggle/vdr-muggle-0.1.11.tgz"
VERSION="muggle-0.1.12"
LINK="muggle"

VAR=`basename $WEB`
DIR=`pwd`

# plugin entfernen
function clean_plugin() {
  cd $SOURCEDIR/VDR/PLUGINS/src
  rm -rf $LINK*
  rm -f $VDRLIBDIR/libvdr-$LINK*
  rm -f $VDRBINDIR/image_convert.sh
  log "cleaning $LINK"
}

# plugin installieren
function install_plugin() {
  download_plugin
  extract_plugin
  cd $SOURCEDIR/VDR/PLUGINS/src
  rm -f $LINK
  ln -vfs $VERSION $LINK
  patch_plugin

  ## plugin specials - start ##
#  apt_install "sqlite3 libsqlite3-dev"
  # oder Patch entfernen und...
  apt_install "libmysqlclient15-dev mysql-server mysql-client"

  apt_install "libmad0-dev libtag1-dev libvorbis-dev"
  apt_install "libwrap0-dev"

  # scripts
  if [ -f $DIR/muggle-image-convert ]; then
    cp -f $DIR/muggle-image-convert $VDRBINDIR
  else
    cp -f $SOURCEDIR/VDR/PLUGINS/src/$LINK/scripts/muggle-image-convert $VDRBINDIR
  fi
  chmod 0755 $VDRBINDIR/muggle-image-convert
  ## plugin specials - ende ##
}

# plugin commands
if [ $# \> 0 ]; then
  cmd=$1
  cmd_plugin
else
  install_plugin
  log "install-plugin fuer $VERSION ist fertig"
fi

exit 0
