# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils multilib

SUFFIX="zip"
X86_AT="twonkymedia-i386-glibc-2.2.5-${PV}.${SUFFIX}"
AMD64_AT="twonkymedia-i386-glibc-2.2.5-${PV}.${SUFFIX}"
ARMV5_AT="twonkymedia-kirkwood-${PV}.${SUFFIX}"
# not tested on armv6
ARMV6_AT="twonkymedia-armel-glibc-2.2.5-${PV}.${SUFFIX}"
ARMV7_AT="twonkymedia-armel-glibc-2.2.5-${PV}.${SUFFIX}"

DESCRIPTION="Stream your Media to the devices on your Netowrk"
HOMEPAGE="http://www.twonky.com/"
URL_BASE="http://www.twonkyforum.com/downloads/${PV}"
SRC_URI="arm? ( ${URL_BASE}/${ARMV5_AT}
		${URL_BASE}/${ARMV6_AT}
		${URL_BASE}/${ARMV7_AT} )
	x86? ( ${URL_BASE}/${X86_AT} )
	amd64? ( ${URL_BASE}/${X86_AT} )"

SLOT="0"
LICENSE="as-is"
KEYWORDS="~amd64 ~arm ~x86"
RESTRICT="strip"
IUSE=""

DEPEND="app-arch/unzip"
RDEPEND="sys-libs/glibc
	sys-devel/gcc"

QA_EXECSTACK="opt/twonkymedia/cgi-bin/convert
	opt/twonkymedia/cgi-bin/cgi-jpegscale
	opt/twonkymedia/twonkymediaserver
	opt/twonkymedia/twonkymedia
	opt/twonkymedia/plugins/mediafusion-integration-plugin
	opt/twonkymedia/plugins/itunes-import"

S="${WORKDIR}"

src_unpack() {
	einfo "Unpacking for arch ${CHOST/-*/}"

	if [[ ${CHOST/-*/} = "armv5tel" ]]; then
		unpack ${ARMV5_AT}
	elif [[ ${CHOST/-*/} = "armv6j" ]]; then
		unpack ${ARMV6_AT}
	elif [[ ${CHOST/-*/} = "armv7a" ]]; then
		unpack ${ARMV7_AT}
	elif [[ ${ARCH} = "x86" ]]; then
		unpack ${X86_AT}
	elif [[ ${ARCH} = "amd64" ]]; then
		unpack ${X86_AT}
	fi
}

src_compile() { :; }

src_install() {
	local dirs="cgi-bin plugins resources"

	dodir /opt/${PN}

	cp -pPR $dirs "${D}/opt/${PN}/" || die "failed to copy"

	insinto /opt/${PN}
	doins initial_keystore.dat radio.m3u config.html twonkymedia-server-default.ini

	exeinto /opt/${PN}
	doexe twonkymedia twonkymediaserver

	dodoc Linux-HowTo.txt RevisionHistory || die

	newinitd "${FILESDIR}"/twonkymedia.initd twonkymedia
}

#pkg_postinst() {
#}
