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

EAPI=3

DESCRIPTION="SabLink System Release files package"
HOMEPAGE="http://sablink.disconnected-by-peer.at/"
SRC_URI=""

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 arm ~x86"

IUSE=""
DEPEND=""
# Listing default packages for the current release
RDEPEND="app-admin/eselect-python
	dev-lang/python:2.7
	sys-devel/base-gcc:4.7
	sys-devel/gcc-config
	app-admin/update-motd
	virtual/cron
	app-admin/equo
"

SABLINK_VER="${PV}"
SABLINK_HEADER="SabLink Linux"
SABLINK_RELEASE="sablink-release"

src_unpack() {
	if use x86; then
		echo "${SABLINK_HEADER} x86 ${SABLINK_VER}" > "${SABLINK_RELEASE}"
	elif use arm; then
		echo "${SABLINK_HEADER} ${CHOST/-*/} ${SABLINK_VER}" > "${SABLINK_RELEASE}"
	else
		echo "${SABLINK_HEADER} amd64 ${SABLINK_VER}" > "${SABLINK_RELEASE}"
	fi
}

src_install() {
	# install relesae file
	insinto /etc
	doins "${SABLINK_RELEASE}"
	dosym /etc/"${SABLINK_RELEASE}" /etc/system-release

	# install equo update cron
	exeinto /etc/cron.daily
	doexe "${FILESDIR}/equo-update.cron"

	# Bug 3459 - reduce the risk of fork bombs
	insinto /etc/security/limits.d
	newins "${FILESDIR}/00-sabayon-anti-fork-bomb.conf" 00-sablink-anti-fork-bomb.conf

	# install sablink greeting
	exeinto /etc/update-motd.d
	newexe "${FILESDIR}/greeting.sh" 20-greeting

	# install the check for updates script
	newbin "${FILESDIR}/equo-update-check" equo-update-check

	# install repository files
	insinto /etc/entropy
	newins "${FILESDIR}/repositories.conf.0" repositories.conf
	insinto /etc/entropy/repositories.conf.d
	doins "${FILESDIR}/entropy_sablink.nas-central.org"
}

pkg_postinst() {
	# Setup Python 2.7
	eselect python update --ignore 3.0 --ignore 3.1 --ignore 3.2 --ignore 3.3 --ignore 3.4
}