#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2011 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, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

add_user avahi x 495 495 "avahi-daemon" "/var/run/avahi-daemon" "/bin/sh"
add_group avahi 495

add_user avahiautoipd x 496 496 "avahi-autoipd" "/var/lib/avahi-autoipd" "/bin/sh"
add_group avahiautoipd 496

mkdir -p $INSTALL/etc/avahi
  cp $PKG_BUILD/avahi-autoipd/avahi-autoipd.action $INSTALL/etc/avahi
  cp $PKG_BUILD/avahi-daemon/avahi-daemon.conf $INSTALL/etc/avahi
  cp $PKG_BUILD/avahi-dnsconfd/avahi-dnsconfd.action $INSTALL/etc/avahi
  cp $PKG_BUILD/avahi-daemon/hosts $INSTALL/etc/avahi

mkdir -p $INSTALL/etc/avahi/services
  cp $PKG_BUILD/avahi-daemon/ssh.service $INSTALL/etc/avahi/services
  cp $PKG_DIR/config/http.service $INSTALL/etc/avahi/services
#  cp $PKG_DIR/config/samba.service $INSTALL/etc/avahi/services

  if [ $SFTP_SERVER = "yes" ]; then
    cp $PKG_BUILD/avahi-daemon/sftp-ssh.service $INSTALL/etc/avahi/services
  fi


mkdir -p $INSTALL/etc/dbus-1/system.d
  cp $PKG_BUILD/avahi-daemon/avahi-dbus.conf $INSTALL/etc/dbus-1/system.d

mkdir -p $INSTALL/usr/bin
  cp $PKG_BUILD/avahi-utils/.libs/avahi-browse $INSTALL/usr/bin
    ln -sf avahi-browse $INSTALL/usr/bin/avahi-browse-domains
  cp $PKG_BUILD/avahi-utils/.libs/avahi-publish $INSTALL/usr/bin
    ln -sf avahi-publish $INSTALL/usr/bin/avahi-publish-address
    ln -sf avahi-publish $INSTALL/usr/bin/avahi-publish-service
  cp $PKG_BUILD/avahi-utils/.libs/avahi-resolve $INSTALL/usr/bin
    ln -sf avahi-resolve $INSTALL/usr/bin/avahi-resolve-address
    ln -sf avahi-resolve $INSTALL/usr/bin/avahi-resolve-host-name
  cp $PKG_BUILD/avahi-utils/.libs/avahi-set-host-name $INSTALL/usr/bin

mkdir -p $INSTALL/usr/sbin
  cp $PKG_BUILD/avahi-autoipd/avahi-autoipd $INSTALL/usr/sbin
  cp $PKG_BUILD/avahi-daemon/.libs/avahi-daemon $INSTALL/usr/sbin
  cp $PKG_BUILD/avahi-dnsconfd/.libs/avahi-dnsconfd $INSTALL/usr/sbin

mkdir -p $INSTALL/usr/lib
  cp -P $PKG_BUILD/avahi-common/.libs/*.so*[.0-9] $INSTALL/usr/lib/
  cp -P $PKG_BUILD/avahi-core/.libs/*.so*[.0-9] $INSTALL/usr/lib/
  cp -P $PKG_BUILD/avahi-client/.libs/*.so*[.0-9] $INSTALL/usr/lib/
  cp -P $PKG_BUILD/avahi-compat-libdns_sd/.libs/*.so*[.0-9] $INSTALL/usr/lib/

mkdir -p $INSTALL/usr/share/avahi
  cp $PKG_BUILD/service-type-database/service-types $INSTALL/usr/share/avahi
  cp $PKG_BUILD/avahi-daemon/avahi-service.dtd $INSTALL/usr/share/avahi

mkdir -p $INSTALL/usr/share/dbus-1/interfaces
  cp $PKG_BUILD/avahi-daemon/org.freedesktop.Avahi.*.xml $INSTALL/usr/share/dbus-1/interfaces

