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

EAPI="1"

NOVELL_BUILDID32="pnMbR9EB7wo~"
NOVELL_FILE32="patchfiles/edir8863.tar.gz"
NOVELL_BUILDID64="pnMbR9EB7wo~"
NOVELL_FILE64="patchfiles/edir8863.tar.gz"
RESTRICT="mirror strip"
USE_RPMOFFSET_ONLY="1"

inherit novell eutils rpm multilib versionator

MY_PV=$(replace_version_separator 4 '-')

DESCRIPTION="Novell Transport Security Layer"
HOMEPAGE="http://www.novell.com"
SRC_URI="x86? ( http://${NOVELL_ACCOUNT_USERNAME}:${NOVELL_ACCOUNT_PASSWORD}@cdn.novell.com/prot/${NOVELL_BUILDID32}/${NOVELL_FILE32} )
        multilib? ( http://${NOVELL_ACCOUNT_USERNAME}:${NOVELL_ACCOUNT_PASSWORD}@cdn.novell.com/prot/${NOVELL_BUILDID32}/${NOVELL_FILE32} )
        amd64? ( http://${NOVELL_ACCOUNT_USERNAME}:${NOVELL_ACCOUNT_PASSWORD}@cdn.novell.com/prot/${NOVELL_BUILDID64}/${NOVELL_FILE64} )"

LICENSE="Novell-eDir-88"
SLOT="8.8"
KEYWORDS="~x86 ~amd64"
IUSE="multilib"

DEPEND=""

RDEPEND="virtual/libc
	net-nds/netiq-env
	>=app-crypt/netiq-nici-2.7.3_p001"

src_unpack() {
	cd "${WORKDIR}"
	unpack  ${A}
	if use x86
	then
	    narch=i386
	    nlib=lib
	    ndir=Linux
	elif use amd64
	then
	    narch=x86_64
	    nlib=lib64
	    ndir=Linux64
	fi
	mkdir -p "${WORKDIR}"/${PN}-${MY_PV}
	cd ${PN}-${MY_PV}
	if has_multilib_profile
	then
	    march=i386
	    mlib=lib
	    mdir=Linux
	    rpm_unpack ../work/edir8863/${mdir}/novell-ntls.${march}.rpm
	fi
	rpm_unpack ../work/edir8863/${ndir}/novell-ntls.${narch}.rpm
}

src_compile() { :; }

src_install() {
	into /opt/novell
	dolib "${WORKDIR}"/${PN}-${MY_PV}/opt/novell/${nlib}/*
	dosym /opt/novell/$(get_libdir)/libntls.so /usr/$(get_libdir)/libntls.so
	if has_multilib_profile
	then
	    ABI="x86" dlib="$(get_libdir)"
	    ABI="x86" dolib "${WORKDIR}"/${PN}-${MY_PV}/opt/novell/${mlib}/*.so*
	    dosym /opt/novell/${dlib}/libntls.so /usr/${dlib}/libntls.so
	fi
}

pkg_nofetch() {
	einfo "This files require you to register at ${HOMEPAGE} (free account)"
	einfo "Please download following file(s):"
	if use x86
	then
	    einfo " - ${NOVELL_FILE32}"
	    einfo "from http://download.novell.com/Download?buildid=${NOVELL_BUILDID32}"
	elif use amd64
	then
	    einfo " - ${NOVELL_FILE64}"
	    einfo "from http://download.novell.com/Download?buildid=${NOVELL_BUILDID64}"
	    if use multilib
	    then
		einfo " - ${NOVELL_FILE32}"
		einfo "from http://download.novell.com/Download?buildid=${NOVELL_BUILDID32}"
	    fi
	fi
	einfo "and place them in ${DISTDIR}"
	einfo ""
	einfo "To get rid of downloading files from ${HOMEPAGE}"
	einfo "you can create a file /etc/portage/novell.acc"
	einfo "containing the novell account infos with following commands"
	einfo "# echo \"NOVELL_ACCOUNT_USERNAME=\\\"balduin\\\"\" >> /etc/portage/novell.acc"
	einfo "# echo \"NOVELL_ACCOUNT_PASSWORD=\\\"derfisch\\\"\" >> /etc/portage/novell.acc"
}