# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI="5"

DESCRIPTION="3ware SATA+PATA RAID controller Command Line Interface tool"
HOMEPAGE="http://www.lsi.com/"


# At this time we can't get this as a standalone archive, instead we need to fetch
# it together with the 3DM2 code, and get both ARCHs
ThreeDM2_VERSION="9.5.5.1"


SRC_URI="http://www.lsi.com/downloads/Public/SATA/SATA%20Common%20Files/3DM2_CLI-linux_${PV}_${ThreeDM2_VERSION}.zip"

LICENSE="LSI"
SLOT="0"


# This package can never enter stable, it can't be mirrored and upstream
# can remove the distfiles from their mirror anytime.
#
# At this time the upstream only provides x86 and amd64 binaries
KEYWORDS="~amd64 ~x86"
IUSE=""

RESTRICT="mirror fetch"
QA_PREBUILT="/opt/tw_cli/tw_cli"

S=${WORKDIR}

pkg_nofetch() {
	einfo "Upstream has implement a mandatory clickthrough EULA for distfile download"
	einfo "Please visit $SRC_URI"
	einfo "And place $A in ${DISTDIR}"
	
	# Note: 3ware gave permission to redstiribute, but the state of redstribution now 
	# that LSI has aquired them should once again be considered unknown until further
	# confirmation has been provided.
	# Ref: http://bugs.gentoo.org/show_bug.cgi?id=60690#c106
}

src_unpack() {
	unpack ${A}
	cd "${S}"
	unpack ./tdmCliLnx.tgz
}

src_install() {
	exeinto /opt/tw_cli
	case ${ARCH} in
		amd64) CLI_BIN=tw_cli.x86_64;;
		x86) CLI_BIN=tw_cli.x86;;
		*) die "unsupported ARCH";;
	esac
	newexe ${CLI_BIN} tw_cli

	dosym /usr/sbin/tw_cli /opt/tw_cli/tw_cli

	newman ${PN}.8.nroff ${PN}.8
}

pkg_postinst() {
	elog 
	elog "This binary supports should support ALL cards, including, but not"
	elog "limited to the following series:"
	elog ""
	elog "PATA: 6xxx, 72xx, 74xx, 78xx, 7000, 7500, 7506"
	elog "SATA: 8006, 8500, 8506, 9500S, 9550SX, 9590SE,"
	elog "      9550SXU, 9650SE, 9650SE-{24M8,4LPME},"
	elog "      9690SA, 9750"
	elog ""
	elog "Release notes for this version are available at:"
	elog "${SRC_URI_BASE}/${PV}_Release_Notes_Web.pdf"
	elog
}